Creating Java Projects Using Eclipse

By Robert Turner,2014-04-24 12:16
9 views 0
Creating Java Projects Using Eclipse

    Creating Java Projects Using Eclipse

    Start Eclipse

    Start the Eclipse program by going to Start?Programs?Other Apps?Eclipse

    The following dialog box will be displayed. Type in the workspace path as below and press OK:

You will then see the welcome screen within Eclipse.



Create a new project

To create a new project in Eclipse, select File?New?Project…


When the New Project dialog box appears, just press Next.


    When the New Java Project dialog box appears, type in the name of the project you want to create in the project name section and press Finish. If you get a dialog box saying that this type of project is associated with the Java Perspective and whether to switch to that perspective, choose Yes and check the box to remember your choice.


    You should now see the screen as displayed below. As you can see, in the Package Explorer panel on the left, a folder has appeared with the name of the project. Inside that project folder is a link to the Java Runtime Environment that will be used to execute the code in your project. Unlike ordinary programs that can only be executed by the operating system on which they were developed, Java programs are special in that they can be executed on any machine (and indeed any operating system) as long as that machine has a Java Virtual Machine. This means that Java programs are Write Once, Run Anywhere which has many advantages over traditional codes. For instance, a game written in Java can be played on a PC, Mac, Unix system or even PDAs and smartphones with no change to the code – Java is highly portable!


You are now in the position to be able to write your Java program. All Java programs contain one or more Java class files which contain the code (more on

this in week 2!). To add a new class to your project, select File?New?Class.


When the New Java Class dialog box appears, type the name of the class into the Name area.

!!! Make sure that none of the three checkboxes at the bottom of the dialog box are checked !!!

Now press Finish.


    In the centre panel, type in the HelloWorld code as listed in the lecture. Notice the syntax highlighting that Eclipse adds automatically. Comments are in green, special Javadoc comments are in light blue, reserved Java keywords are in purple and strings are in blue. This highlighting is useful, not just because it makes it easier to read your code but can help when debugging. You will by now have seen that the words corejava and Console in your code are underlined in red. On the left hand border, you can see a white cross in a red box. Move your cursor over the box and a message appears telling you that these words cannot be resolved. This means that Java cannot understand this part of your syntax. Go on to the module webpage and download the file. Unzip this file into a folder call corejava. You should now have three Java class files in a folder called corejava. Copy this folder to your HelloWorld project folder. Now go back to Eclipse, right-click on HelloWorld in the left-hand panel (the project folder one, not the class file) and select Refresh.


You should now have a complete Java program with no errors. To execute your code select Run?Run As?Java Application. In the Run Type dialog box,

    scroll down the main type list until you see HelloWorld, select it and press OK. In the panel below your code, a new tab appears called Console. Click on it to interact with your program.


Report this document

For any questions or suggestions please email