Home
Resources - Getting tools
Tutorials
Sample Code
Documents
Help

                 

 

 

Create the main file for the tutorial project

If the tutorial project is not listed in the Package explorer (left panel), go back to the previous subtopic to review how to import the project into the workspace. If the project is listed in explorer but is not open, right click on tutorial and choose Open Project. Now do the following -

  1. Either choose File | new | class from the menu, or right click on tutorial and choose new | class from the pop-up menu.
  2. The Source Folder field should be set to tutorial.
  3. Leave the Package field blank (the default package will be assumed).
  4. Leave Enclosing type unchecked.
  5. In the New Java Class window enter the name TutMain (this will be the name of the public class as well as the file name).
  6. The modifier should be set to public.
  7. At the bottom be sure to check public static void main(String[] args). This tells Eclipse to include the main method in the code. You can leave the other two check boxes as they are currently defined.
  8. Click Finish.

Eclipse will create the code for TutMain and open the file in the editor. You will notice that Eclipse also includes comments - you should edit the comments by deleting the two sets of double comment lines that begin with * To change the template for ... This is a note to the user that the template used for creating the default comments can be changed. If you are using your personal copy of Eclipse, you may want to change the indicated template at some point. (If so, leave the comments as they are to remind you.)

The code should look something like the following:

public class TutMain {
	public static void main(String[] args) {
   }
}

Note: if you forgot to check public static void main(String[] args) when defining the class, you can either type in the missing code or, in Package explorer, right click TutMain and choose delete. Then start over with item #1 above.

Place your cursor at the end of the public static void main ... { line and press RETURN. This opens up the main block. Type the following inside main():

public class TutMain {
	public static void main(String[] args) {
		System.out.println("Tutorial");	// <-- type this line, don't forget ";" at end
   }
}

You will notice that if you type slowly, Eclipse pops up a window from which you can choose an item to complete the line. Also, when you type the first parenthesis, Eclipse completes the closing parenthesis as well. You will find this type of "smart completion" occuring often as you enter code.

At this point you have completed the project. Now go to the next subtopic to run your program.