Skip to main content
Banner graphic with text description of the course website

“Intro to Eclipse” Exercises

LAB #01 Exercise #4: Creating a Basic App




Go back to Eclipse.

  • Right-click the project name in the explorer and select New -> Class
Pasted Graphic 1
  • In the resulting dialog box, type Lab01 as the Class name.
  • NOTE the initial CAPITAL letter. This is important and you should be careful to capitalize the initial letter of any new class you create.
  • Check the box that asks Eclipse to add a main method for you. The dialog is shown below:

Pasted Graphic

Next you will see this:

Pasted Graphic 2


Let's have a look in the body of the main method.
You will see a line like this:
// TODO Auto-generated method stub

You can go ahead and delete the entire line. The body of the method will be empty. There should be only blankness between the innermost opening and closing curly braces (the "{" and the "}")

Now cut and paste the following lines into the body of the main method.

System.out.println("*******************");
System.
out.print("Hello");
System.
out.print(" ");
System.
out.print("World");
System.
out.println();
System.
out.println("*******************");

The contents of the editor window should look like what is shown below.
By now you should understand that the body of the main method is the portion in between the inner "{" and "}" (curly braces)

Pasted Graphic 3



Now selection Run -> Run (or click on the green circle with the arrow Pasted Graphic 4

STRONGLY SUGGESTED: learn the keyboard shortcuts (they depends on the OS, on windows it is ctrl-shift-F11)

You will see a couple of things happening. First, a fourth tabbed pane will appear called "Console".
Then, in that console, the output of the app will appear. It should look like this:

Pasted Graphic 7


Congratulations!!! You just wrote and invoked your first Java application.


Now practise changing the stuff between the quotation marks and re-running the app, to print other messages to the console.

Notice that there is both println and print statements - can you identify what each statement does?