Completing and Running the Example Program

Here we will learn a few of the coding features of Eclipse.

Add a main method to your program by typing on a new line "public static void main(String[] args)". Press enter to go to the next line, then type "{". You will notice that Eclipse automatically adds a second closing bracket on the next line. Press enter again and notice that Eclipse automatically indents the cursor ready to type another statement.

Next Type "System." and wait for a few seconds. Eclipse will automatically create a list of possible elements to insert into your code. Next type "o" and Eclipse narrows the list of elements down to "out". Select this by pressing enter. Then complete the line by typing ".println("Hello world!")" (leave out the semicolon for demonstration purposes).

You will notice at this point that Eclipse has underlined the line with a red line, similar to the way word does when there is a spelling error. Eclipse has picked up a Syntax error and underlined it to show us. If we now save the file Eclipse will show an entry in the "Tasks" box at the bottom of the screen. Double clicking this will highlight the error.

Fix our error by adding the semicolon to continue.

To run out new program we use the "Run" icon at the top of the screen, however because Eclipse is designed to allow the design many different types of Java application, we have to tell it which one we are using. Click the down arrow on the right side of the first little running person "Run" icon, choose "Run As" and choose "Java Application".

Eclipse will ask us if we want to save our files before running the application. Click the OK button to do so and allow Eclipse to continue. Eclipse will compile and run your program showing the output in the "Console" box at the bottom of the screen.

Eclipse has hidden our "Tasks" view, but we can switch back to that by clicking the new "Tasks" tab right at the bottom of the screen.

Next Section: Importing and exporting