My First Eclipse Experience.
This is a quick tutorial on how to get started with the Eclipse Integrated
Development Environment (IDE. There are many Java IDEs, each with strengths and
weaknesses. One of the strengths of Eclipse is that it is free! Another is that
is has a market share of more than 50%, meaning that industrial users are finding it to be a
good tool.
We will also use JCreator--free for the Learning Edition--which is very fast
to launch, but which lacks some of the best features of the Professional
Edition. (The Professional Edition is free for a 30-day trial.) I will use it in class sometimes. Another major player is
NetBeans from
Sun. There are technical and performance differences that make Eclipse
preferable, I believe.
Eclipse can be thought of as a Java IDE, on top of which is built IBM's WebSphere, a large collection of tools
for building Web-based applications. By learning Eclipse you will be
learning something of industrial strength that will also make learning WebSphere
much faster if and when you get to that. IBM was a founding company of the
Eclipse Foundation, which manages Eclipse. IBM is rather rapidly giving more
parts of WebSphere to Eclipse; the entire package, with all updates, is now
nearly 700MB. We will be using only a very small fraction of this functionality.
I will give occasional demonstrations, of the "this-will-not-be-on-the-exam"
type, of other things that can be done with Eclipse.
Of course Eclipse is much more than just a Java IDE. Tons of plugins are
available, making it a highly flexible and powerful tool.
The Eclipse effort is open-source. I believe the organization has one paid
employee, an executive director. All other work is done by volunteers; some key
people are on loan from their employers to work full-time on the project.
This presentation is entirely tied to my two sections of CSc 221, Software
Design Lab, at City College of New York in Fall, 2005. Even more particularly,
it is the technical part of what I did in the first lecture of the semester.
Steps in getting Eclipse from the course CD to your hard drive
At home . . .
- Create a folder named eclipse
on your C drive. (In the 7/118 lab you can’t do this. Create a folder named
eclipse in the temp folder
and carry on. On your own computer, you can, of course, create a folder
named eclipse on the C root.
- Insert the course CD into your CD drive. Copy the file
eclipse-SDK-3.0.1-win32.zip
into your eclipse folder.
- Unzip the file
eclipse-SDK-3.0.1-win32.zip into the same folder. That will create
another folder named eclipse
containing the unzipped files and folders.
- You can launch Eclipse from this folder by double clicking on the file
name eclipse.exe, or you can
drag that file to your desktop or your quick launch bar, either of which will
create a shortcut for you. This process will
not put Eclipse into the Windows Registry. If you want--I neither favor
nor advise against this--you can create a folder under
Program Files named
Eclipse and copy the Eclipse
folder there. If you are using Linux, you will need to escape the space,
writing #mkdir New\ Folder.
(Thanks to David Gurvich for a correction on this.)
In the lab . . .
. . . you click on the Eclipse icon on the desktop. The only place that
is writable by you is
C:\temp,
so you will have to create a workspace (see below) there. On your own
machine the workspace can be wherever you like. Make the appropriate changes
in the instructions below, depending on whether you are in the lab or on
your own machine.
Back to the tutorial . . .
- Open Eclipse: double click on the
eclipse.exe
file name, the Eclipse icon on the desktop, or
whatever. When you are asked to select a workspace, browse to
C:\temp. (When you are
finished with this lab, you will be able to copy your workspace onto CD or
floppy, ready to pick up at another session where you left off today.) After
selecting a workspace, wait for Eclipse to launch.
(Actually, I'd suggest you first create a folder in
C:\temp
( or wherever you want on your own machine) named 221HW1 or whatever, and
specify that when you start Eclipse. Before long you are going to have lots
of saved workspaces; put them somewhere you can find them, and give them
names that mean something to you.)
- If this is the first time Eclipse has been opened with this workspace (it
is), you will get a welcome screen. Roll over the icons in the middle and
make a note that there are lots of help facilities available, but we don’t
want that now. See Figures 1 and 2.

Figure 1.

Figure 2.
- After clicking on the arrow-like thing in the top right or the X in the
top left, you will see a
blank Eclipse workbench. See Figure 3.

Figure 3.
- Create a project: File/New/Project,
or click on the New icon
just below the File button
and select Project. Name it
Lab1, or anything else you
please. Leave all checkboxes as they are. Click
Finish. (You may be asked
if you want to switch to a Java perspective. Say yes.)
- In the Package Explorer area on the left, your new project will appear.
Click on the + to expand the
view. You will see that some libraries have been made available
automatically. NOTE: we want jre1.5.0_04.
If that is not what you see, plunge ahead bravely. That is what is installed
in the lab, and that is what is on the course CD.
- Right click on the Lab1
project symbol and choose New/Package.
Name it helloJava, or
anything else you please. If you start with an uppercase letter you will be
told that the convention is for package names to begin with a lowercase
letter. This is only a convention, but why not do it the standard way?
Virtually everybody does.
- Right click on the package and select
New/Class. Name it
MyFirstEclipse, or whatever you please. Unclick
Inherited
Abstract
Methods, and click
public
static
void
main. The only
modifier you want is public. Click
Finish. When you are ready to
click Finish, the dialog should look like Figure 4.

Figure 4.
- (If you are like me, you will have trouble remembering, at the beginning,
which comes first: Project or Package? There are four things you need; try memorizing the phrase "Workspace ProPack Class." Crazy?
Worked for me.)
- The editor window will show a basic Java program with a main
method. Your workbench will look like Figure 5. Experiment with dragging the
boundaries between panes on this window to make the panes larger or smaller.
The comments that begin with /**
are Javadoc comments. We will talk about these later. For now, you can
either ignore them or erase them. What you see will not exactly match what
is shown in Figure 5.

Figure 5.
- Modify
public static void main(String[] args) {
}
to:
public static void main(String[] args) {
System.out.println("Hello,
Eclipse World!");
}
(If the string "Hello . . .."
extends over two lines in your browser, be aware that in the program, as
I ran it, that didn't happen. Strings in Java cannot be broken across lines.)
- Click Window/Show View/Console.
A console window will open at the bottom, with other views available on
tabs. (If a Console tab is already there, just click on it.)
- If no funny red marks show in the left margin, your program is
syntactically correct: Eclipse has been compiling it as you type. Make that
official by doing a Save (Control+S
is faster). If a red circle with an X in it appears, click on the Problems
tab at the bottom to see what the problem(s) is/are. In fact, make some deliberate
errors so you can see this. Then fix it and save again. Click on the Console
tab.
- Click Run/Run as/Java Application,
and your output will appear in the Console window.
- Make some small change and press Control + F11, which means "Run the last thing I ran."
Or click on the icon near the top left that looks like this:
.
- If you try to run without saving, a dialog box will appear asking you
what to save. You can just click OK. Or, dismiss the dialog,
Save, and say to run again.
- Take out the statement to print Hello
Eclipse etc.
- Insert a declaration at the class level and within
main and add statements as
follows. (We’ll worry later about that
static, and don’t worry about the indentation differences. ) Fix
any syntactic errors, Save, and run. The sum of the first ten integers is 55.
(I’ll bet you knew that.)
public class MyFirstEclipse {
static int sum;
public static void main(String[] args) {
for (int i = 1; i <= 10; i++)
sum += i;
System.out.print("The sum of the first 10 integers is: " + sum);
}
}
(See comment above about the
System.out.println statement. Strings cannot be broken across
lines.)
- Now let’s move to HW1. From the course CD, copy the file
HW1StarterV3.java to
C:\temp. (Or wherever, on your
machine.)
- Back in Eclipse, right click on your package and select
Import.
- Select File System and browse to
C:\temp. Click OK.
- You will see your HW1StarterV3.java
file. Check that box and click Finish.
- Click on the + to the
left of your project name. Your HW1 class is there. Double click on its
symbol to open it in the editor window.
- You will get a nasty message saying that the package isn’t what Eclipse
expected. Right click on the red error indicator at the top and select Quick
Fix. (Eclipse knows what to do; it just wants you to admit how smart it is.
Well, not really; you might not want the automatic correction.)
Click on Add package declaration . . .
An import with the package name is inserted.
NOTE: In some cases, for unknown reasons, Quick
Fix doesn't pop up. Assuming you named your package hw1,
insert the following lines, before any of the
import statements:
package hw1;
- Save the file to formalize the compilation (which has already been done).
Don’t look for a Compile button!
There isn’t one.
- Do Run/Run as/Java Application.
The GUI created by the program will appear.
- To exercise the GUI, you need to resize the Eclipse window so that you
can see the GUI and the Eclipse Console. Play with it. Does it complain if
you hit Enter with no first name? (It better!)
That's it for this lesson. This is how far we got on the first day.
Specifically, we did not discuss the Java concepts at all, and did not examine
the HW1 program.
Whenever you are ready to leave the lab, close
Eclipse and send yourself and your partner email with your Java file attached.
Or copy to a USB memory thing, or burn a CD. But email is simplest.
To continue, go to
Instructions and
code snippets for the second lab.
Back to Dan McCracken's Home Page