Step 1: Java Development Kit (JDK) 8
-
To run Eclipse, a Java Runtime Environment (JRE) must be installed. You verify that you have the JDK 8 installed by running the java -version command (from the Command prompt in Windows or the terminal on Mac):
$ java -version java version "1.8.0_172" Java(TM) SE Runtime Environment (build 1.8.0_172-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
You should see output similar to lines 2-4 above. Any higher version of Java will also work for this class.
-
If you do not have the JDK 8 or newer installed, you can download the newest version of Java from this site (after accepting the terms & conditions). Select the version for your OS from the table on the page.
Step 2: Install Eclipse
We recommend using the latest version of Eclipse (Eclipse IDE 2020-09), but earlier versions should work too. Make sure you have completed Step 1 before installing eclipse.
- Visit the Eclipse installer page.
- Click on the link for your platform on the right side of the screen (under “Download”) and unzip the downloaded file to get a file called “Eclipse Installer”.
- Note: The 64-bit Windows version of Eclipse may not be able to locate Java installations. If this happens, use the 32-bit Windows version instead.
- Run the Eclipse Installer. Select “Eclipse IDE for Java Developers” and then “Install” to install Eclipse.
- Launch Eclipse.
- The first time you run Eclipse, you need to choose a workspace (a folder that stores your projects).
Step 3: Making a Java Workspace
For the Java portion of the course, we recommend creating a new workspace. You will only need to do this once this semester. To create a workspace:
- Click File –> Switch Workspace –> Other …
- Click Browse… and navigate to the place where you want to store your Java workspace on disk.
- Create a new folder for your Java workspace and select it. Give it a meaningful name like “CIS120Workspace” so that you can find it easily.
To switch between workspaces, select File –> Switch Workspace.
Step 4: Creating a Java Project
Each homework assignment requires a separate Java Project.
- Click File –> New –> JavaProject.
- Give the project a name
- Under “Use an execution environment JRE”, make sure that JavaSE-1.8 or JavaSE-8 is selected (do not use a more recent JRE).
- Click “Next” (not “Finished”).
- Under the “Sources” tab, if a “Create module-info.java” box is checked, uncheck it.
- Under the “Libraries” tab, click “Add Library”, “JUnit”, “Next”, select “JUnit 5”, and click “Finish”.
- Import the homework files into the project.
- Right click on the project you just created.
- Choose Import –> General –> File System –> Next
- Browse to the folder (e.g. “hw06_temp”) that you downloaded with the homework files, then select it
- Check the box (so that it is selected) next to the folder name and make sure that the subfolders src and test (and, possibly other depending on the project) are selected. You should uncheck the Codio-specific files named .codio, .settings, Makefile, and README.md; they do not need to be imported into Eclipse
- Click “Finish”
- Select the new test folder in your project, choose Build Path –> Use as Source Folder. (If this is not an option, the test folder is probably a source folder and you don’t have to do anything).
JUnits Tests
Unit testing is a method of testing source code that verifies that individual units are working properly. A unit of code refers to the smallest testable part of an application, in Java this corresponds to a method. JUnit is a Java package that implements unit testing. Eclipse provides tools to automate the creation of JUnit tests. It also provides a good interface for running the tests. Together these two tools make systematically testing your program very easy.
The Style Checker
Installing the Style Checker Eclipse Plugin
- First, download the style checker plugin: checkstyle-plugin.zip.
- Open Eclipse. Under Help, click on “Install New Software…”
- Click “Add…” on the right side
- In the pop-up window, click on “Archive…” and navigate to the downloaded checkstyle-plugin.zip file. Click OK.
- Select the checkbox available next to “Checkstyle”.
- Click “Next >”, then “Next >” again.
- Accept the license agreements, and press “Finish”.
- You might get a pop-up message saying you are installing unsigned software. Press “Install anyway”.
- Restart Eclipse to apply the changes.
Configuring Eclipse to use CIS120’s Style Guide
- Download our style guide configuration file here: cis120-checkstyle-config.xml.
- Open Eclipse, and go to preferences (For MacOS, go to Eclipse -> Preferences. For Windows and Linux go to Window -> Preferences).
- Click Checkstyle on the left sidebar. If you don’t see Checkstyle, reinstall the checkstyle plugin using the instructions above.
- Under the “Global Checks Configurations” on the right side click on the “New…” button.
- Change the type from “Internal configuration” to “External Configuration file”.
- Under location, press Browse, and select your downloaded cis120-checkstyle-config.xml file.
- Give the config a helpful name, like “CIS120 Style”
- Press “OK”
- Click on your configuration in the list, then click on “Set as Default” on the right side.
- Press “Apply and Close”
- If you are asked if you should rebuild projects, press “Yes”.
Cannot initialize module TreeWalker - TreeWalker is not allowed as a parent of LineLength error
, try using this cis120-checkstyle-config.xml checkstyle configuration file instead. You can install it using the same instructions above.
Using the Style Checker
- Select or create a new Java project (see below).
- Right click on the project, click “Checkstyle”, and click “Activate Checkstyle”.
- Eclipse should now show you your style violations if they exist.
C:\\John Smith\eclipse-workspace\hw0
. If the style checker were being used in the project located in that path, then it will not work. To fix the issue, move the project or eclipse to a folder that does not have any spaces in the path name: C:\\eclipse-workspace\hw0
(Credit: CIS121)
Using the Eclipse debugger
For debugging Java code, the Eclipse debugger can turn out to be more helpful than just using print statements, especially when you start having really complex code. We suggest watching CIS 121’s YouTube tutorial on how to use the Eclipse debugger.