01 Getting Started With Eclipse (Sep 2023 Update)
01 Getting Started With Eclipse (Sep 2023 Update)
Getting Started with Eclipse: What is an IDE? Eclipse Installation and Basic Use
Before Starting installation of Eclipse, ensure you have installed and verified the configuration of Java as per the
first part of Hybrid 01
You can find instructions on how to install Java within the Hybrid 01 materials on Brightspace.
Images used in this handout are the property of the respective owners, e.g. Eclipse.org.
Installation of Eclipse
Visit the Eclipse.org website to download the latest version of Eclipse (https://www.eclipse.org/ )
Tip: Use the Download button in the upper right corner, then use the “Download Packages” link to see more
download options (https://www.eclipse.org/downloads/ )
While Eclipse has an optional installer available we will not use it, instead we will select a specific version of Eclipse
and download a Zip file instead. Use the download-packages link.
Page 1 of 18
On the download packages page (https://www.eclipse.org/downloads/packages/ ) get this download:
“Eclipse IDE for Java Developers”
At the time this handout was created the downloaded file is named: eclipse-java-2021-03-R-win32-x86_64.zip
1) Unzip the zip file you downloaded (Graphics Icon may differ)
2) There should be a folder extracted named “eclipse”, it is a large file it may take a few moments to extract.
Page 2 of 18
At this point Installation is complete.
We did not need to use an installation program to install Eclipse. This also means we do not need to uninstall Eclipse
either when we are done with it, and there are no hidden changes to the operating system configuration (typically
done by an installer program).
Starting Eclipse
Start Eclipse using the shortcut, pinned link, or double-click on the eclipse.exe directly. The splash screen is the first
thing you will see. (Splash screen appearance may vary depending on version of Eclipse installed).
Page 3 of 18
Selecting a Workspace
Eclipse will ask you for the workspace directory, browse to the directory you created in your homework folder and
Eclipse will configure it as a workspace by adding the needed files. Click Launch.
(I do not recommend using the “Use this as the default and do not ask again” as I like the option to choose which
workspace I will use (I have more than one), on program start-up and clicking Launch is not time consuming.)
Note that in the image below, the default workspace location was changed to
“C:\CST8116 Homework\CST8116 Eclipse Workspace” if this location does not yet exist, Eclipse will create it.
Page 4 of 18
Welcome Page
The Welcome Page is displayed by default.
A built-in reference is the help system. Use the Help Menu and select the Help Contents sub-menu to open the help
page. In this screen shot the relevant help sections top categories were expanded, these are the Workbench User
Guide, and the Java development user guide.
Page 5 of 18
There is too much to learn in one sitting by reading all of the help system, use it as a reference to learn more as
needed about Eclipse.
The Tips and Tricks can tell you how to use a dark theme for Eclipse. Your professor may use the default color theme
with the font size adjusted for lectures.
Page 7 of 18
Alternatively, you can close the Welcome page using the X icon within the welcome page’s tab.
Page 8 of 18
Specifying Amazon Corretto JDK 17 as the default for the workspace
Use the Window Menu, Preferences sub-menu
A dialog window will open, select Java and expand it using the little arrow to the left of “Java”
Select the “Installed JREs”
Remove the check mark from the eclipse plugins jre, and select instead AmazonCorretto\jdk17.0.3_6
(If you are using a newer version of Amazon Corretto 17 than 17.0.3_6 use that.)
The screen shot below shows this change:
Page 9 of 18
Setting the Compiler Compliance Level for Java 17
To ensure that Eclipse gives us syntax error messages appropriate for Java 17 we need to set the compiler
compliance level. Versions of Java before 9 are listed with their version number, e.g. Java 8 is listed as 1.8, while Java
9 onwards is listed as we would expect (Java 9, 10 and so on).
Use the Window > Preferences menu to re-open the preferences dialog from the previous step, click on the
Compiler option under Java, then use the Drop-down box to verify Java 17, or to select Java 17.
Page 10 of 18
Creating Your First Java Project
Using the File Menu, use the New sub-menu and select Java Project.
Page 11 of 18
Eclipse will return to the Java Perspective, I used the little > character next to the project name (Week 1 Hybrid
Demo Hello World) to expand the folder list.
o This is not the same as the physical files on the hard drive; Eclipse is showing you what you need to see
within the Package Explorer.
There is a folder named src, short for “Source” which is really a short way of saying for “Source Code”
o Java source code files will be placed into this folder.
Select the src folder within your project, in the package explorer, then
Using the File menu, select New sub-menu, then select the Class sub-menu.
I entered the class name “HelloWorld” (do not use spaces in a class name) within the Name text box, placed a
check-mark next to “public static void main(String[] args)” and clicked the Finish Button. Everything else was left with
defaults.
o On an aside, using the comments templates may be a neat way to place your required comment block at the
top of each class-source-code file you create, but this is something you will need to explore later.
o * There are a number of options on this window, and much you will not understand. For now just know that
as you learn more Java including in future courses more of the options you are seeing will make sense.
(Week 1 Lecture Notes explain what method main is used for).
Page 12 of 18
Note the warning about using the default package is discouraged. For now, ignore this, we will learn more about
packages later.
A package is a way to organize classes, similar to how you organize files within folders on a hard drive.
o Because each of our programs in Introduction to Computer Programming will not have many source code
files we can use the default package, in other words organizing a few code files in a folder is manageable.
o Larger projects consisting of 100’s of source code files need a package structure to organize the files.
Page 13 of 18
Finally, we have our first Java program opened within the Eclipse editor.
The package explorer shows the file HelloWorld.java on the left. (1)
The editor view shows us the contents of the file, and uses the file name as the tab name (2)
The outline view shows class HelloWorld, with method main. In larger programs, the outline view helps you to
navigate code files, as well as sections within code files. (3)
Edit the source code by removing the programmer comment and adding System.out.println("Hello World"); within
method main as illustrated below.
A programmer comment starts with two forward-slash characters, and by default has green text in Eclipse.
e.g. // TODO Auto-generated method stub
Here is the code before; I removed the default coloring here to make it easier to read.
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Change it to this (shown below), including the comment block at the top of the file, tip once you start typing /*
eclipse will align and add * characters as needed for you.
Click on the space beside “1” above public class HelloWorld and add a “Header comment” as well as a comment
above the method main header public static void main(String[] args) (as illustrated below)
/*
* Student Name: Stanley Pieda
* Lab Professor: Professor Stanley Pieda
* Due Date: no due date
* Modified: June 23, 2022.
* Description: Hybrid 01 Demo file
*/
Page 14 of 18
/* Description: this class outputs a greeting from within method main. */
public class HelloWorld {
System.out.println("Hello World");
}
}
As you type in System.out.println("Hello World"); type slowly and pause after entering the first dot character, Eclipse
will offer code-help to assist. (Complete the line by typing System.out.println("Hello World");
Cautionary Note:
Eclipse’s productivity enhancement features, code helpers, a check box to create method main and more help you
write code, but also interfere with your learning. Without looking at anything, can you write the main method
correctly in the space below and get it perfectly correct including capitalization?
You may want to practice coding by hand, as well as using Eclipse. The theory tests in the course may require you
to write code by hand and remember syntax.
In addition, sometimes Eclipse does not really understand what you are trying to do, and the automated features
can make things worse.
Page 15 of 18
o World is reported as “Syntax error on token “World”, { expected” i.e. the class name must be one word
followed by only an opening brace{
There are suggested fixes like renaming the code file, or rename the type to HelloWorld. Often none of the
suggested fixes is correct. (See below, I experimented).
The secret here is that the problem the complier reports could be treated as “Hello, message from the compiler,
there was something I didn’t understand at this point in the source code please fix” it then suggests a possible
problem but you need to look at your code and do some thinking to fix the mistake.
Make lots of mistakes as you work, then fix them, you will make fewer mistakes, and get faster at fixing them.
This comes with practice. It is better to learn how to fix mistakes in programming, than attempt to write perfect
code the first time especially as a learner. (Can you learn to ride a bicycle from a book, without practicing on a
bicycle at all, and expect to ride perfectly your first time?)
Out of curiosity, I experimented with the quick-fix of “Rename type to “HelloWorld” and sadly, Eclipse only changed
“Hello” to “HelloWorld” leaving the original “Word” in place, so it didn’t fix things it made them a little worse:
Correct the syntax mistake by removing the space, and ensuring that the only class name after the word class is
“HelloWorld”.
On an aside, using the Project menu, you can see that Build Automatically is selected. If you deselect this check box,
you would then be required to run the compiler using the Project menu manually. (Not recommended).
(Build in this context for us in an introduction course means to compile, but Eclipse is doing a few more things
behind the scenes)
Page 16 of 18
Running a Java Program in Eclipse
Use the Run menu’s Run sub-menu to attempt to run the program
Or use the run icon in the toolbar (float the mouse over buttons to see tool tips)
If there are no syntax mistakes your program should run, and you will see the output in the console view (a tab at
the bottom of the screen)
o Eclipse may ask you if you want to save sources (source code files) before you run them, I usually click OK to
save, or alternatively you may want to set the check box “Always save resources before launching” to on.
Because this program has no user input, or much processing, it shuts down after outputting Hello World.
There is a small grey box-icon in the Console tool-bar that lights up Red when a program is running; this button shuts
down a buggy program that stops responding. If you float the mouse over it the tool-tip is “Terminate”.
The double XX button removes the terminated program launches from the console to remove clutter. And the tool-
tip is “Remove All Terminated Launches”
Tip: Use the Terminate and Remove All Terminated Launches buttons. If you have Java programs that bug out and
stop responding they still use CPU and RAM, so repeatedly running the same buggy program again and again is
similar to running MS Word or your web browser multiple times and leaving them open. Theoretically, too many
running programs can use up your CPU time, your RAM, and slow down your computer. So Terminate and Remove
Terminated Launches as needed.
Page 17 of 18
Summary: What is an IDE?
We have installed and used fundamental features of the IDE Eclipse.
We have used the Editor in Eclipse, instead of windows Notepad.
We have automatically used the compiler, instead of javac on a command prompt window.
We have viewed output in a console view inside Eclipse, instead of using java in a command prompt window.
In other words, our basic development tools of Editor, Compiler, and Running a program are all within Eclipse.
Page 18 of 18