Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This guide will guide you through both of these options. We will first look at how to get each option set up properly. After that, we will look at the Eclipse development environment.

Contents

Table of Contents

Getting Everything Ready and Installed

...

The workspace is where you will be saving all your homework. If you haven't worked with Eclipse before, just click OK and thereby accept the default location. Eclipse then loads and greets you with a nice welcome screen. Feel free to switch off the "Always show Welcome at start up" option at the bottom and dismiss the screen by clicking the X at the top.
Image Modified
What you see next is the actual Eclipse development environment that you'll be spending most of your time in:

Image Modified

The window is divided into different areas. Most of them contain views, such as the Package Explorer to the left. The big empty area at the centre of the screen will house the Java source code editor, a text editor to write Java code with. You can drag views around, and close them as you wish. For example, you won't need the Task List during our lecture. Feel free to close it now. If you want to reopen a view you have closed, you can find a list of all available views through the menu by clicking Window -> Show View -> Other.

...

To solve your homework assignments, you will need to know how to create new Java projects, add classes to them, and how to execute them. Let's start by creating a new project. Right-click in the Package Explorer, and select New -> Java Project. This will open the following dialogue:

Image RemovedImage Added

Enter a project name that describes the project. For your homework assignments, for example, you may want the project name to contain the assignment the project is supposed to solve. Leave the rest untouched and click Next. The dialogue will change:Image Removed Finish. Your Eclipse workspace will now contain an entry for the new project. Eclipse has to be told that you want to use the ACM library with that project. To configure it that way, right-click on the project, click on Build Path and select Configure Build Path...:

Image Added

Remember the ACM library you downloaded? This is where we need it. Since you will be making use of that library, we need to configure the project such that it knows that the library exists. To that end, switch to the Libraries tab:

Image RemovedImage Added

A library in Java is distributed as a file with the `.jar` file extension. Click on the Add External JARs button and select the downloaded ACM library (if you don't remember where you saved it, simply download the library again). Once you have found the library, it should show up in the dialogue. If you expand its entry, it should look something like this:

Image Removed
Expand the entry of the acm.jar library, select the Source Attachment property of the library and click on Edit. Switch to External location and select the acm.zip which you downloaded.

Image Removed
Finally, click Finish and marvel at your new project showing up in the Package Explorer. Image Added
The ACM library is not ready to be used, but Eclipse won't display its documentation. We like documentation, so we tell Eclipse where to find it. Double-click the Source attachment entry, which will open the following dialog:

Image Added

Select External location and click the External File... button to select the acm.zip file you downloaded. Click OK to dismiss the dialog, click Apply and Close to dismiss the build path configuration and you're all set!

You are now ready to add your first class to ityour newly configured project. Right-click your new project in the Package Explorer and select New -> Class:

Image Modified
Give your class a proper name. The dialogue will tell you if your class name is valid or not. For the first few programming exercises, you want your class to extend a superclass, such as GraphicsProgram. To choose a superclass, click the corresponding Browse button. The result may look something like this:

Image Modified
Note that the dialogue still gives us a warning because we have left the package name empty. You can safely ignore that warning for the moment. There will come a time when you will actually use packages, but now is not that time. Instead, click Finish. Eclipse will create the class for you and open it in an editor for you to start writing code:

Image Modified
Let's say you have actually written a bit of code and want to see if it works. Save your class. Then, right-click it in the Package Explorer and select Run As -> Java Applet (or Java Application). If everything is fine, a window should pop up and your program should be executing. If instead Java cannot execute your program because of errors in your source code, Eclipse will tell you so:

...

The automatic tests we run on the source code you submit won't let you hand in badly formatted code. This is because we want to force you to write code that is properly readable. Fortunately, formatting your code properly is a matter of two clicks of a mouse button:

Image Modified

Importing Classes

There will be assignments where we ask you to import existing classes into your workspace. There are (at least) two ways to do so:

  1. Right-click the destination folder in your Eclipse project and choose Import....
  2. Use drag & drop.

We will now describe the latter. Start by downloading the respective class. Then, import it into your Java project by dragging and dropping it from your file explorer to your source folder, like this:

Image Added

Eclipse will ask you whether you want to copy the file into your project or just link to it. You want the former:

Image Added

The imported file may declare to be in a different package than the one you imported it to, resulting in a compiler error. To fix that, simply open up the file, point the mouse cursor at the wrong package declaration, and choose to move the file to that package.

Image Added