Getting Started Using Eclipse


Laurie Williams, Dright Ho, Ben Smith and Sarah Heckman. [Contact Authors]
CSC 326 - Software Engineering
Department of Computer Science
North Carolina State University

Back to Software Engineering Tutorials


0.0 Outline
1.0 Background of Eclipse
2.0 Installing Eclipse
3.0 Extending Eclipse
4.0 Editors and Views
5.0 Perspectives
6.0 Creating a Java Project
7.0 Creating a Java Package
8.0 Creating a Java Interface
9.0 Creating a Java Class
10.0 History
11.0 Running the Program
12.0 Exercise
13.0 Resources

1.0 Background of Eclipse

Eclipse is an Integrated Development Environment (IDE) that is open source and maintained by many software development leaders like IBM and Borland. The idea behind the Eclipse platform is to provide a common environment that companies can modify and customize by creating plug-ins. Plug-ins are created to do some specific tasks that a work group might need while developing a software product. The plug-ins and modification of the Eclipse platform can later be distributed royalty free.

This tutorial introduces you to the user interface of Eclipse and some common activities that can be done in the Eclipse environment. Large images are displayed as thumbnails, but are linked to a page of full size images. For this tutorial we are using Eclipse 3.3.x.

Top | Contents

2.0 Installing Eclipse

To follow the instructions for manually setting up Eclipse and the rest of the development environment on your machine, follow the below instructions below. You may want to check out the web installer which puts the required version of Eclipse and all the plugins you will need on your machine automatically.

Download Eclipse from here. You need the Java Runtime Environment (JRE) to use Eclipse; this fall we are using Java Version 1.4.2, which can be downloaded here. Be sure to select the JRE and not the SDK, because you do not need the Java source files to use Eclipse.

After you download Eclipse, you will want to unzip the folder to right under your C drive (or main hard drive). However, you can install Eclipse into whichever directory you want. Eclipse is run by launching the eclipse.exe executable which is at the top level of the Eclipse directory.

Top | Contents
3.0 Extending Eclipse

The base functionality of Eclipse can be extended through the use of plug-ins. These plug-ins can add functionality to Eclipse like modeling, UML, XML, metrics, reliability reports, and other information. The Eclipse web site has a list of links to many popular plug-in repositories. Check out the Installing Plugins tutorial for more information.

Top | Contents

4.0 Editors and Views

Eclipse has two main components for displaying information about a project. These are editors and views.

4.1 Editors
Editors are a way for a user to change information in a project. An editor may contain text or objects that can be changed and manipulated, but usually editors contain the code being developed during a project (such as .java files). A different editor may be opened depending on the file type selected. The editor or application that is opened when a file is selected can be modified in Window > Preferences > Workbench > File Associations.

4.2 Views
Views show a representation of a single task in the Eclipse environment. For example the Navigator view shows the hierarchal file structure of every project open in the Eclipse workbench, and allows a file to be opened. Any number of views can be opened in the workbench at one time. To open a view that is not displayed in the workbench select Window > Show View..> Other.. for a complete list of views.

4.3 Moving Editors and Views
Editors and views can be moved around on the workbench to create a custom layout. To move an editor or a view, select the tab with the name of the file or view being moved. If you can add the file or view to a stack of files or views a is displayed. If you can move the file or view beside an editor or view a black arrow is shown with the new location of the file or view outlined in the workspace. A view may not be stacked in an editor location and an editor may not be stacked in a view location.

Top | Contents

5.0 Perspectives

Perspectives show all functionality associated with a large task, for example the Java Perspective is associated with creating a Java application. Each perspective has a default layout with views and editors appropriate for that task. If the views and editors are moved within a perspective, Eclipse will remember the new layout.

5.1 Opening a Perspective
A perspective is opened by selecting the Window > Open Perspective..> Other.. for a complete list of perspectives, or the icon can be selected in the tab located in the upper right of the screen. In Eclipse there are 8 perspectives, but other perspectives may be listed when plug-ins are added. A description of the 8 perspectives are listed below:

5.1.1 CVS Repository Exploring : provides tools for the user to connect to and explore a CVS repository.
5.1.2 Debug : provides tools for the user to create breakpoints in code, and step through the code to view values of variables at a given point in time in order to debug mistakes in the code base.
5.1.3 Java : provides tools for the user to easily create and explore a Java project
5.1.4 Java Browsing : provides tools for the user to quickly move between Java projects, packages, types, and members of all Java projects open in the workbench.
5.1.5 Java Type Hierarchy : provides tools for the user to quickly view the Java type hierarchy of files in a Java project
5.1.6 Plug-in Development : provides tools for a user to create an Eclipse plug-in
5.1.7 Resource : provides general editing tools for the user to create a basic project. This is the default perspective.
5.1.8 Team Synchronizing : provides tools for teams to synchronize their code base through a CVS repository or other means.

5.2 Views in a Perspective
Each perspective has a default layout of views that are most commonly used for the task that the perspective supports; however, each perspective has other views that may provide helpful functionality to the perspective.

5.3 Switching Between Perspectives
All perspectives that have been opened, remain easily accessible through the perspective tab at the upper right of the workbench. A user can change perspective by clicking on the icon associated with the perspective they wish to change too.

5.4 Closing Perspectives
To close a perspective, right click on the icon associated with the perspective that you wish to close and select Close from the context menu.

Top | Contents

6.0 Creating a Java Project

6.1 There are three ways to create a Java project:

6.1.1 Select File > New > Project,

6.1.2 Select the arrow of the button in the upper left of the toolbar. Select Project, or

6.1.3 Right click on the Package Explorer view in the Java Perspective, and select Project.

6.1.4 Click on the icon on the toolbar.

6.2 Select Java project and click Next.

6.3 Give the project a name. If you would like to create src and bin folders for your java and class files respectively select the Create separate source and output folders radio button under the Project layout area of the New Java Project dialog. The default source folder is src/ and the default output folder is bin/. You can change these defaults by clicking on the Configure default... link. Click the Next button.

6.4 The next screen has four tabs: Source, Projects, Libraries, Order and Export. The source tab sets the source and output folders for Java files and class files. The project tab allows you to connect your new Java project to any other Java projects that are needed on the new Java project's build path. The libraries tab allows you to attach jar files of and Java libraries that you may need. The order and export tab determines the build order and how a project can be exported. Make any changes needed here, and then click the Finish button. If you are not in the Java perspective, Eclipse will ask if you would like to switch to the Java perspective. The project will show up in the Package Explorer view.


Step 6.2

Step 6.3

Step 6.4
Top | Contents

7.0 Creating a Java Package

7.0 There are four ways to create a Java Package. First, select the project you wish to create a package in.

7.1.1 Select File > New > Package,

7.1.2 Select the arrow of the button in the upper left of the toolbar. Select Package,

7.1.3 Right click on a project in the Package Explorer view in the Java Perspective, and select Package, or

7.1.4 Click on the icon in the toolbar.

7.2 Check to make sure that you are creating the package in the proper project and source folder. Give the package a name. Click Finish.


Step 7.2
Top | Contents

8.0 Creating a Java Interface

8.1 There are four ways to create a Java Interface. First, select the package you wish to create the interface in.

8.1.1 Select File > New > Interface

8.1.2 Select the arrow of the button in the upper left of the toolbar. Select Interface,

8.1.3 Right click on a package in the Package Explorer view in the Java Perspective, and select Interface, or

8.1.4 Click on the arrow of the icon in the toolbar. Select Interface.

8.2 Check to make sure that you are creating the interface in the proper package. Give the interface a name. Use the Add button to add interfaces that the new interface needs to extend. You may also select if you want generated comments added to the interface. All generated comments are configurable under Window > Preferences > Java > Code Style > Code Templates. Click Finish. The new Interface will be open in the editor.


Step 8.2
Top | Contents

9.0 Creating a Java Class

9.1 There are four ways to create a Java Class. First, select the package you wish to create the class in.

9.1.1 Select File > New > Class

9.1.2 Select the arrow of the button in the upper left of the toolbar. Select Class,

9.1.3 Right click on a package in the Package Explorer view in the Java Perspective, and select Class, or

9.1.4 Click on the arrow of the icon in the toolbar. Select Class.

9.2 Check to make sure that you are creating the Class in the proper package. Give the class a name.

9.2.1 Use the Browse button to search for a super class if your new class should inherit from another class.

9.2.2 Use the Add button to add interfaces the new class should extend.

9.2.3 Check the public static void main(String [] args) checkbox if the class you are creating starts the application.

9.2.4 Check the Inherit abstract methods checkbox if you would like to inherit abstract methods from a super class or interface.

9.3 Click Finish. The new class will be open in the editor.


Step 9.2
Top | Contents

10.0 History
Eclipse maintains a history of changes made to all files open in the workbench. If you need to revert a file to a previous version, or you just wish to find a line of code that you deleted, you can look up the local history of the file. This history is only persistent for the life of the Eclipse session. To look up the local history of a specific file, right click on the file and select Compare With > Local History.. or Replace With > Local Hi story.. depending on the operation you wish to do.
Top | Contents

11.0 Running the Program

There are several ways to run a program.

11.1 If the program has never been run before, you need to create run configuration for the program.

11.1.1 Select Run > Run..

11.1.2 Click the arrow on the icon in the tool bar and select Run..

11.1.3 Right click on the project you wish to run. Select Run > Java Application or Run > Run..

11.2 Select Java Application, then click the New button at the bottom left of the screen. This creates a new run configuration. Give the setting a name. If the project is not specified, you can Browse for it. To find the main class in the project, select the Search button.

11.3 If there are any command line arguments, enter them in the Program arguments text box under the Arguments tab.

11.4 You can add jar files to the classpath under the Classpath tab.

11.5 Click Run to run the program.

11.6 If you have already created a run configuration, you can select the configuration by name by selecting the arrow on the icon in the tool bar. Just pressing the green button will run the last configuration launched by Eclipse.


Step 11.2
Top | Contents

12.0 Exercise

Following computer science tradition, you will now write a simple HelloWorld application using Eclipse. We will call our application Greeter, and it will be able to say hello in several different languages. The diagram below describes the classes and their relationships in this example.

Language
Greeting
German guten Morgen
Spanish hola
French bonjour
Italian ciao

For this exercise create a Greeter program that can say hello in three different languages. You can just print the hello statements to System.out. Show the application to your TA for credit.

Top | Contents

13.0 Resources
Top | Contents

Back to Software Engineering Tutorials
Getting Started with Eclipse Tutorial ©2003-2006 North Carolina State University, Laurie Williams, Dright Ho, Ben Smith, Sarah Heckman
Email the authors with any questions or comments about this tutorial.
Last Updated: Monday, March 30, 2009 1:19 PM