Hints for Using Eclipse

Eclipse is a very sophisticated IDE (integrated development environment). This document is intended to help you with a few of the tasks you need to accomplish with Eclipse in this class. More information (well, way too much information) is available at eclipse.org.

Install Java 8

If Java is not already installed on your computer, find the right download for you at Java SE Downloads. You want the Java Platform (JDK). When you do the installation, try to avoid installing unwanted extras such as the Ask Toolbar or the McAfee Security Scanner.

Install Eclipse

If Eclipse is not already installed on your computer, find the right download for you at Eclipse IDE for Java EE Developers. This can be unzipped/untarred anywhere on your computer. The Eclipse executable will be in the eclipse subdirectory.

Your Workspace

In the classroom, Eclipse is configured to put your workspace on the V: drive.

The Welcome Screen

This is a screen with possibly useful buttons scattered around it. Just close it.

The First Java Program

To code your first Java program, select:

Click Yes for a Java perspective.

Getting out of Trouble

It is very easy for beginners to find themselves in some weird Eclipse mode (called "perspectives" in Eclipse-speak). Select:

to get back to familiar territory. If that doesn't work, try:

Creating Another Java Project

To create a project:

An Eclipse project contains the set of files for a particular application. If your project is named foo, the organization of your files will be:

Creating a Package in the src Directory

A package is a sub-directory in the src directory that contains a set of related Java classes. To create a package in the src directory:

Creating a Class in a Project

A class can be placed in src directory or any package directory under src. To create a class in the foo project:

Running a Class

Moving or Renaming a Package or Class

If you want to rename a package or a class, or move a class from one package to another, you should do it via refactoring.

To rename

To move a class

Formatting a Java Class

You can customize how a Java class should look in the Java Editor by modifying settings in Project -> Properties (for a specific project) or in Window -> Preferences (for all projects). Once set, those settings will become the default. To apply the format on a newly imported class, or after a change of the format:

For example, you can change the indentation by following Window -> Preferences -> Java -> Code Style -> Formatter -> Edit. In this window, change the Profile name to Java, Tab policy to Spaces only, Indentation size to 4, Tab size to 8, and click OK. Besides the format command, Ctrl-A Ctrl-I will also apply the indentation settings.

Creating Comments for Javadoc

Javadoc comments begin with /** and end with */. The javadoc program converts these comments into HTML documentation. The javadoc comment must appear just before the class or method to be documented. Typing /** and enter just before the class or method will generate some of the tags that you'll need.

A class comment might look something like:

 * The Foo class does exactly what its name suggests.
 * @author Alfred E. Neuman
 * @author Moxie Cowznofski
public class Foo { ... }

A method comment might look something like:

 * The dwim method does what I mean, nothing more, nothing less.
 * <p>
 * Use the p tag to start a new paragraph.
 * <br>
 * Use the br tag to start a new line.
 * @param whatToDo specifies what to do in reverse Polish notation.
 * @param howToDoIt specifies how to do it using Montague semantics.
 * @return true if successful, false otherwise.
public boolean dwim(String whatToDo, String howToDoIt) { ... }

Running Javadoc

Viewing Javadoc

There are two ways to view the Javadoc: using a web browser or using the Javadoc View window within Eclipse.

To use a web browser,

To use Javadoc View

Importing a Project

This is how to load a zip file that contains an Eclipse project.

Exporting a Project

This is how to create a zip file from an Eclipse project.

Refreshing a Project

If you open a project and think some files are missing, or you know some files were changed in the project directory, you can bring Eclipse up to date by right-clicking on project name, and select Refresh. For example, you might copy a data file into the project directory from a command window. Afterwards, you need to refresh the project.

How to Stop Eclipse from Nagging You

Eclipse often tries to be helpful by displaying popups with information about alternatives, parameters, and what not. If you find this distracting, this is how to turn some of it off.

If you want to see the information popups, you can do this manually using Ctrl-Space.

Another feature you might want to turn off is: