CSci 151: Foundations of computer science II
Home Syllabus Assignments Tests

Getting started with Eclipse

I suggest using Eclipse for your assignments in this course. Eclipse is a programming environment, which is free (open-source). It is probably the most commonly used programming environment used by professional Java programmers today.

Entering Eclipse

In the lab: Eclipse is already installed on the laboratory computers. From the Applications menu in the screen's upper left corner, select the Programming submenu, and select Eclipse.

On your own computer: I suggest downloading and installing a distribution of Eclipse called Easy Eclipse Desktop Java Distribution v1.2.2. You can download it from the download Web site.

Creating your project

Eclipse is based on the notion of projects. I suggest creating a project for each assignment. To create a project:

  1. Select New > Project… from the File menu.

  2. Open the Java folder, select Java Project, and click Next.

  3. Under Project name:, type a name for this project; I recommend 151-Assn1. Do not include spaces in your project name: Spaces sometimes confuse Eclipse! After entering the project name, click Finish.

  4. Eclipse may prompt you about changing to the Java perspective. Click Yes.

  5. If you still see the Welcome screen on the right side of Eclipse's window, go ahead and click the X next to Welcome.

  6. Notice the Package Explorer on the left side of Eclipse's window. You should see your new project listed under the Package Explorer

Creating your program

  1. To create a new class in your program, right-click the project and select New > Class from the pop-up menu.

  2. Type the name of your new class in the Name: field, and click Finish. (You may notice a message reading, The use of the default package is discouraged. You can ignore this message.)

  3. You will see the new class now listed beneath the project, and you will see its code opened up in the editor in the center of the window. If may later choose to close the code's tab in the window's center, you can reopen it by double-clicking the class name in the Package Explorer.

  4. For testing purposes, let's go ahead and create a Main method in your class:

    public class YourClassNameHere {
        public static void main(String[] args) {
            System.out.println("It works!");

Compiling your program

  1. Eclipse automatically compiles each class as you type it. Saving the class also forces it to compile the class immediately.

  2. Eclipse identifies each compile error in your program using a light bulb icon to the left of line containing an error. Hovering your mouse over this icon displays a message describing the line's problem.

  3. If you click the light bulb icon , Eclipse will display a pop-up menu offering some possible changes that might address the problem. Of course, what you want isn't always on this list - but it's often quite handy.

Executing your program

  1. In the Package Explorer, right-click the class containing the main method and select Run As > Java Application from the pop-up menu. If you don't see Java Application in the Run As submenu, it's because the class you right-clicked doesn't have a main method and so can't be executed.

  2. An easy way to start the program again is to click the Play button in the toolbar. You can also go through the pop-up menu as in the previous step, but you really only have to that once and then rely on the Play button to execute the last-executed program.