Java Tutorial - Java Script : Creating Hello World in Eclipse

Java Tutorial - Java Script :

Creating Hello World in Eclipse


As a brief introduction to the IDE, we will build the classic Hello World application. Eclipse starts with the Welcome screen, as seen in Figure 4.5. The Eclipse application refers to the application window as the workbench. A workbench may have one or more perspectives. A perspective defines the layout and views of the various windows within the workbench. Perspectives are organized to help with specific tasks. Our task is to create a HelloWorld Java program, so we start our task by selecting a perspective by choosing Window Open Perspective Java. After you do so, the arrangement of the Windows changes and some icons are added to the shortcut bar on the left side of the workbench. The icons on the border represent the currently available perspectives. Now, we want to create a project for our code. To do so, choose File New Project to bring up the dialog box, as shown in the Figure 4.7. Choose Java Java Project, and then click Next. The next screen prompts you for a project name; we will call our project HelloWorld, and click Next. Then, accept all of the defaults on the screen, and click Finish.

When the wizard finishes, you are returned to the workbench. The Package Explorer window now shows your project. Clicking on the node reveals the full path to the runtime package rt.jar. This is a good way to make sure that you are using the correct JDK. Highlight the project node and right-click it, then choose New package from the menu. When prompted for the name enter the following: com.wiley.freej2ee.ch4.eclipse Then, click Finish. A new package is added to the project. Right-click the new package, and choose New Class. Use HelloWorld as the class name and check the box next to public static void main... Leave everything else as it is, and click Finish.

Anew class is generated and displayed in the editor window.Position the cursor within the editor to start adding code to the main method. Start by typing System. As you pause, notice that the IDE displays a list of the methods available for the System class. Select “out” from the list of methods, and the editor will fill in the next part of the line. Add the next dot, and the system will again show a list of the methods. Select println(String), and enter “Hello World” as the argument. Do not add the semicolon at the end of the line, and save the source code by either choosing File Save or by clicking on the disk icon on the tool bar. Notice that now a red circle with a white x appears at the border of the editor window on the line below the one you just edited. This is showing you a compiler error and  indicating that you need to complete the expression; so, add the semicolon and resave the file.

After the program has been saved, the compiler errors are cleared. Now, you are ready to run the program. This is done through the Run menu. Choose Run Run As... Java application or click the running man icon on the toolbar.A console window will overlay the task and error window at the bottom of the screen and should now read “Hello World”.Congratulations! You have just written your first application using the Eclipse IDE.