Documentos de Académico
Documentos de Profesional
Documentos de Cultura
This tutorial is designed to help students get started with using the Eclipse IDE
By the end of this tutorial you will have been guided through all of the basic features of the Eclipse IDE
application that you will need to perform day-to-day programming tasks that may be required in introductory
java programming courses.
NOTE: This tutorial is intended for students with prior java programming experience.
A fully-customisable development environment which by default brings together the following features:
o
An intelligent code editor which allows multiple source code files to be opened.
A package explorer which allows the developer to navigate through the structure of the projects that
have been developed.
A class outline which allows the developer to quickly navigate to a specific class unit (method or
variable) when required.
The standard Java compiler and runtime environment for all versions of java currently in use (including
version 7.0, which is the latest release)
Other useful tools such as templates for generating javadoc (source code documentation) and skeleton code
for classes, interfaces and methods.
Students undertaking Java programming courses in RMIT CS&IT are expected to familiarise themselves with the
Eclipse IDE in order to make use of it when doing their course (assignment) work.
Page 1
NOTE: you can return to the welcome screen by selecting the Welcome option in the Help menu if you wish to
examine the other options in the welcome screen (including the configuration examples and tutorial links).
Once you have selected to move to the workbench you will be presented with the default workbench shown below it
will more than likely start up in a perspective for a different type of programming, so you should change the
perspective to the normal Java setting as shown below:
RMIT- School of Computer Science and Information Technology
Introduction to Eclipse Tutorial
Page 2
In the next section you will be guided through the process of setting up a basic project and writing a basic program
using the default workbench.
Page 3
You can also use the new project shortcut to access the project creating facility as shown in figure 2.2 below.
Page 4
Once you have selected the new project option by either one of the methods shown above you will need to select a
new project wizard (a helper facility which assists developers to quickly and easily configure the project to their
requirements).
You should select the option to create a new project by using either one of the methods described above
now.
For most java applications you will write as part of coursework you are required to do in RMIT CS&IT java
programming courses you will only need to create a normal java project as shown in figure 2.3 below.
Once you have selected the normal java project wizard and clicked on the next button you will be taken to the Java
Project wizard - for simple java applications you only need to give the project a name and then click on the Finish
button as shown in figure 2.4 below.
You should create a new project called exercises in your workspace as shown above when your instructor
directs you to do so.
NOTE: If you wish to configure a new project in more detail then there are additional options to create a folder
(package) structure, link existing source code folders to the project and several other features, which you can explore
at your own leisure.
Once you have created your new project it will be added to the package explorer area on the workbench as shown
below in figure 2.5 and you will be able to add new classes (and packages if needs be) to the project.
Page 5
Page 6
You can also use the "New Class" shortcut to start the class definition process as shown in figure 2.7 below.
Once you have selected the New Class option you will be taken to the new class wizard, which allows you to
customise the new class to meet your requirements, such as including method stubs (empty methods which you can
fill in) for constructors, inherited abstract methods and the main method, specifying a package the new class is to be
part of and specifying the superclass of the new class we are creating (if it is intended to be a subclass) and selecting
various class modifiers (visibility, abstract, final, etc) if required.
All we need to do here for now is specify the class name and include a method stub for the main method as shown in
figure 2.8 below and click on the Finish button.
You should create a new class called HelloWorld as shown above now (you can ignore the default package
warning).
RMIT- School of Computer Science and Information Technology
Introduction to Eclipse Tutorial
Page 7
Figure 2.9 Workbench updated with new project and class information
The package explorer (leftmost area) displays the classes that have been added to the current project.
The editor includes features such as syntax highlighting, automatic indentation and automatic syntax checking
which highlights errors as you type.
The class/method outline (rightmost area) allows you to navigate quickly and easily to the method/variable
that you need to change especially useful for classes that have more than a few methods.
The compiler error listing (bottom area) displays any compilation errors or warnings that were noted when you
saved your source code in tabular form.
Each of the regions in the workbench can also be resized to meet your preferences by clicking on and dragging one of
the corresponding borders to make the region in question either larger or smaller to suit your preferences.
Eclipse remembers the previous layout used for the workbench so that you do not have to adjust it again every time
you want to use Eclipse to write another program.
Page 8
The next step we will take is to implement the program and examine how the syntax checking and error reporting
features work.
Remove the TODO comment by highlighting it and hitting the delete key and add the following (incorrect) statements
to the main method in the editor window:
System.println("Hello World")
System.println("My number is : " + number);
You should add these statements to the main method now.
Save and note how the syntax checker has highlighted the errors in a manner similar to what is shown below in figure
2.10 below (both lines have basic syntax errors).
To see a description of the problems the syntax checker has detected simply run the mouse pointer over the
error flag as shown in figure 2.11 below.
Page 9
You should proceed to rectify the errors as discussed below while your instructor describes how
errors are reported and can be located in this next section.
To rectify the errors on this on the first line you need to change the statement as shown below (in the
underlined text):
System.out.println("Hello World");
Now lets look at the error listing feature - save the project by clicking on the save (floppy disk) shortcut as
shown in figure 2.12 below.
Page 10
If you click the mouse twice over an error in the error list the editor will highlight the corresponding problem in
your implementation as shown below in figure 2.13.
Rectify these two errors by making the following additions to the program as shown below (in the underlined
text) and save the program again:
RMIT- School of Computer Science and Information Technology
Introduction to Eclipse Tutorial
Page 11
This happens because eclipse generally checks for basic syntax errors in the first compilation pass and then
evaluates statements and expressions in a second compilation pass to see if they make sense.
However it is possible that eclipse will stop checking for errors until the ones it has already detected have
been rectified, so it may take more than one pass to rectify the errors that may be present in a class/method
you have just implemented.
You can rectify this error by changing the affected line as shown below (in the underlined text):
Page 12
All we have left to do now is to run our sample program you can do so by selecting Run -> Run As -> Java
Application as shown below in figure 2.14.
Alternatively you can use the run shortcut button as shown below in figure 2.15.
Page 13
You should run the program using either one of the methods described above when directed to do so
by your instructor.
Once you have used either of the above methods to run the program the java console view will appear in the
lower area of the workbench as shown below in figure 2.16.
This concludes the eclipse basics tutorial - you should try go get a little more practice by writing and running
sample programs from the week 1 learning materials as well as attempting the week 1 practice exercises on
blackboard.
Page 14