Working with Eclipse
This page will get you started with the Eclipse workflow.
Setting up a Workspace
Eclipse organizes all your projects under a workspace. When you first start eclipse, you're presented this dialog to choose the folder where you want the workspace to be. All your project files will be stored inside this folder, as a separate subfolder.
After that, you're presented with a welcome screen similar to this one:
Closing the welcome screen gives you a perspective layout like this:
For each homework, you will download a given zip file which will become a project in your workspace. The zip file contains all the stub code and unit tests. Save the zip file to your workspace folder and unzip it there.
In Eclipse, choose File > New > Java Project, you will get this dialog:
Set the dialog fields as shown, i.e.
- Project name: hw1 (or hw2, hw3, etc.)
- Contents: Create project from existing source. Navigate the path to the hw1 subfolder you just unzipped under the workspace folder.
Then click on Finish. You will now see the project you just created under the "Package Explorer" pane on the left. Click on the grey triangles to see what's under the project. You should see something like this in Eclipse:
After you're done with the homework, you will submit it as a zip file. You can do this by exporting the project by right clicking on the project and choose Export...
The export option is also available under the File menu. You will be presented with the export dialog window.
Choose General > Archive File and then click on Next. You will see this dialog.
The only thing you need to care about is in the middle, "To archive file." When you click on Finish, a zip file will be created where you specified it. This will be the zip file you gsubmit.
By the way, the homework packages are prepared exactly the same way. The grader will also import your project into his own workspace similar to how you imported files for the homework.
In this course, your code need to follow a code style formatting, roughly summarized below:
- Indentation is 2 spaces.
- Code and comment must fit within 80 columns of text.
- Curly brackets for code blocks start on the same line, but curly brackets for methods and classes start on a new line.
Fortunately, Eclipse can reformat code for you. Just import the cs112-code-style.xml profile attached at the bottom of this page. First open the Preference dialog window (on Mac OS X, that is Eclipse > Preferences; on Linux and Windows, that is Window > Preferences).
On the left pane, navigate to Java > Code Style > Formatter, then click on Import..., select the cs112-code-style.xml file you just downloaded, and click OK. You should see CS112 as the Active profile.
Then in the editor window, you can reformat your code by pressing the key combination ⌘-Shift-F (or Ctrl-Shift-F on Windows).
You can compare the "before" (left) and "after" (right) screenshots of the same code.
Running Unit Tests
When possible, each homework will come with a class dedicated for unit testing. These classes are named SomethingTest and placed in SomethingTest.java file. When you first import the homework, the code should compile, but all tests will fail. It is a good idea to check the unit test again once you think you completed the homework and only submit when you've made sure all the unit tests work.
To run a unit test, just click on SomethingTest.java file in the Package Explorer, then click on the Run button
, which is the fifth one from the left.
Here you can compare the screenshot before and after implementing the appropriate functions, making the unit tests pass.
This should be all you need to get started.