2. Our first class Table of contents

2.1. The file "MyWorldLauncher.java"  

 

It is time to create our first class. It is nothing more than a new Java file.

Now apply it to the folder we have created and name it MyworldLauncher.java. To this empty file we have to add a file header. You can copy it from any other file of this project and paste it to MyWorldLauncher.java.

A typical Java file contains: 

·       file header

·       package definition

·       import statements

·       class header comments

·       class definition

·       attributes

·       methods

On the right side you see a link "Contents of MyworldLauncher.java". Use it to see the complete contents of the file. You can copy and paste the corresponding sections which are mentioned benaeath.

The file header consists of the file name and information like copyright, license and project reference. But you have to modify the contents.

The class header comments contain the class description, CVS information, your name and your email. 

(1) Modify the section beneath the import declarations. We have to outline the contents of the file. Maybe write something like this.

This class launches the MyWorld application.

 

(2) Next we must mention the authors name of this file.

@author Your name <your.name@domain.de>

 

The remaining lines are obligatory and you can maintain them. There are the line:

@version $Revision: 1.2 $ $Author$

 

It is used by CVS to keep track of source file changes. At the beginning this CVS commentaries should be empty. CVS will generate entries automatically. Also the first line of the file remains empty: $RCSfile: seite2.html,v $

  

(3) Now you can specify the package name. In our case it is simply the sub-directory we have created some steps before.

package org.resmedicinae.application.sample.myworld;

 

(4) It is always useful to import the following package in every new file you will create.

import java.lang.*;

 

Now we can start the implementation. For an Open Source project like Res Medicinae it is unalterable to make expressive commentaries.

 

(5) Add the following code.

 

 

public class MyWorldLauncher extends Object{

 

  /**

  *Launches the application

  *

  *for Javadoc:

  *@param args the command line arguments

  */

 

  public static void main(String[] args){

 

     System.out.println("\n\n My first Application\n\n");

 

  }

}

  

The MyWorldLauncher class inherits from the Object parent class – the top most class of the Java class hierarchy. It contains one static method main. Such a method is necessary to start the application by the system. System.out.println prints out information on the console.

 

<<PREVIOUS                                                                   NEXT>>

 Contents of MyworldLauncher.java
Copyright (c) 1999-2002. Dirk Behrendt All rights reserved. GNU FDL license. Last Update: 30.09.2002