Eclipse IDE Tutorial
IBM’s Eclipse is a program that is used to write applications (other programs) in a variety of programming languages. It allows you to complete many distinct program development steps in one place (program window). A program which allows you to do this is known as an integrated development environment, or IDE.
In this course, Eclipse is used for writing programs in Java. There are several steps that must be completed to set up Eclipse and further steps to start up a new Java project (set of Java components which work together to make up an application). This tutorial explains each step with words and graphics from the Eclipse IDE.
This tutorial will help you to become familiar with the Eclipse IDE.
Index
Here is a brief description of each step in this tutorial. The link name is used as the link label throughout the tutorial.
- Start The start of the tutorial (top of this page).
- Launch Step 1: How to launch the Eclipse IDE.
- Create Step 2: How to create a new programming project.
- Edit Step 3: How to edit an existing project.
- Run Step 4: How to run your program. This also includes building or compiling your project.
Change folder options to display file extensions
You only need to do this once.
- Click on the button on your desktop.
- Select Settings-> Control Panel from the menu.
- A new window titled Control Panel should appear. Double click on the Folder Options icon.
- A new window titled Folder Options will appear, click on the View tab.
- Uncheck the box next to “Hide file extensions for known file types”.
- Click OK to exit and save the change.
- Click the close window button in the upper right hand corner of the Control Panel to close the window.
Window buttons
We’re ready to start Eclipse!
Step 1: How to launch the Eclipse IDE
This step will show you how to start the Eclipse program on the Windows 2000 operating system. This will be very familiar if you already know how to start other programs in a Windows environment.
Click on the button in the lower left corner of your desktop.
Find the Eclipse program in the Windows menu. -> Programs -> Eclipse -> eclipse.
Note that the “Eclipse” menu may not be visible. Examine the following image:
In this image, the Eclipse menu is visible. Click on the double down arrow () if the Eclipse menu is not visible. You will then see something resembling the following:
If you look enough, you should be able to find the “Eclipse” menu.When you launch Eclipse, you will be shown the following splash screen while it loads, which can take a few minutes:
After launching Eclipse for the first time, it will first ask you for a workspace location with an image like the following:
Change the workspace location to u:\private\cs302\projects and make it so that this is the default choice, as in the following image:
You will then be presented with a welcome workspace like the following:
You can optionally explore the various icons as you wish. The next time you run Eclipse, you will not be shown this welcome workspace, but all of the information it contains can be found elsewhere. When you are done, close the Welcome pane by clicking the X on the tab, then continue to the next step of the tutorial and use the Eclipse IDE to develop your Java programming project.
Step 2: How to create a new project
This step will show you how to create a Java application project in Eclipse.
Choose File -> New -> Project from the Eclipse menu bar, as in the following example:
The New Project wizard will appear, as in the following example:
Make sure “Java Project” is selected and click the Next button. The following window will be displayed:
Click Finish to create the project. You will be presented with the following dialog box:
Select “Remember my decision” (you will only be writing Java programs for this class) and click “Yes”. The following screen will be displayed, denoting an empty workspace:
Congratulations, you have created your first Java project! But, we’re only halfway there. Next comes putting some substance (code) into the project to make a working program!
Leave this project window open, since you will be continuing with the tutorial at this time. In general, once you have created a project and are done working on it for the time being, you may exit Eclipse by clicking the button in the upper right hand corner of the Eclipse title bar, or through the Eclipse menu File -> Exit.
Step 3: How to edit a project
This step will show you how to edit a source file in Eclipse.
Launch the Eclipse IDE if it is not currently running. Return to Step 1 of this tutorial if you need help completing this step.
We need to create a source file where we will write our program. Right-click on the “HelloWorld” project in the Package Explorer tabbed pane on the left side of the screen and navigate to New -> File, as in the following example:
Another window will be displayed. Click on the HelloWorld folder if it is not highlighted. Then click in the text box labeled “File name:” and type in HelloWorld.java, as in the following example:
Click Finish. This will create a new tabbed window where you can edit the HelloWorld.java source file. The single step creates the empty file and adds it to the project for you.Now that we’ve completed the setup we can write the program. Enter the following text into the HelloWorld.java window.
As you edit the file, you may notice red underlines appearing. This is Eclipse’s attempt to correct you, the same way a word processor attempts to correct spelling. If you follow the above, the red lines will eventually disappear, though it is normal for some to appear as you are writing programs. If there are still some left, compare the above image with the file you wrote until you find the difference. Issuing the “Build All” command may also clear up problems occasionally.
Also, note that even if the red lines disappear, this doesn’t mean that your program will work correctly! Just as your word processor only knows how to spell and the rudiments of grammar but not how to write an essay, Eclipse knows what a valid Java program looks like, but doesn’t understand whether or not the program you wrote does what you want it to. For a simple program like the above, it may very well work as soon as it is recognized as a valid Java program, but for more complicated programs, validity is only the tip of the iceberg.
It’s also worth mentioning that Eclipse will fill things in for you. For example, if you put a left parenthesis (, it will follow it up with a right parenthesis ). You can keep on typing and fill in the space between the parentheses. When you’re done, you can either manually type the end parenthesis ), which will type over the old one, or you can press the right arrow key to skip past the old one.
- Finally, personalize the file by adding the following header to the top of the file and fill in the fields appropriately. The Title is the name of the overall program (HelloWorld in this case) and Files is the list of source files you created (just HelloWorld.java in this case). This header should be included with all of the files you hand in. Instead of typing the header yourself you can select (click and drag over the text) the text below and choose “Copy” from the “Edit” menu, or hold Ctrl and press C on your keyboard. Then put the insertion point at the top of your HelloWorld.java file and choose “Paste” from the “Edit” menu, or hold Ctrl and press V on your keyboard.
///////////////////////////////////////////////////////////////////////////////
// ALL STUDENTS COMPLETE THESE SECTIONS
// Title: (program's title)
// Files: (list of source files)
// Semester: Fall 2005
//
// Author: (your name and email address)
// CS Login: (your login name)
// Lecturer's Name: (name of your lecturer)
// Lab Section: (your lab section number)
//
// PAIR PROGRAMMERS COMPLETE THIS SECTION
// Pair Partner: (name of your pair programming partner)
// CS Login: (partner's login name)
// Lecturer's Name: (name of your partner's lecturer)
// Lab Section: (your partner's lab section number)
//
// STUDENTS WHO GET HELP FROM ANYONE OTHER THAN THEIR PARTNER
// Credits: (list anyone who helped you write your program)
//////////////////////////// 80 columns wide //////////////////////////////////
- While you are editing the source code, it is a good idea to save your work frequently. The more often you save your work, the less work you will have to recreate in the event of a system crash or other interruption in your work.
You save the file by clicking on the disk icon. Files that have been modified since last save will have an asterisk before the file name, as in the above image.
You’re almost there! The next step will be to run the program.
Step 4: How to build and run your project
This step will show you how to compile and run your Java program in Eclipse. Be sure to read the whole document!
Before you begin, make sure the text in your editor window is exactly the same as the text in the previous step.
- Go to the left Package Explorer pane. The HelloWorld folder should be opened, but if it is not, click on the + symbol to the left of it. Then, click on the + next to “(default package)” to access the HelloWorld.java file. Right-click on the file and select Run -> Java Application, as in the following image:
Note: If you do not see a “Java Application” option, there is an error in your HelloWorld.java file. Don’t click on the “Run” option with the green arrow icon which is always available. Instead, go back to Step 3 and fix your HelloWorld.java file.
Once you run the HelloWorld program, you should notice output in the Console pane:
Note that you may have to click on the tab labeled “Console” to see this output.
A last important note is that for most of your projects, you’ll have more than one file that you edit. You can add more than one file to a given project the same way you added the first file to each project. However, each project will produce only one program. The different files will allow you to organize yourself in an object-oriented way.
Last modified June 27, 2006
Original version created by Sue Hazlett
Updated for Eclipse by Martin Hock
Updated for lab section use by Rebecca Hasti
Updated for Summer 2006 by Will Benton