CIS 120: Programming Languages and Techniques I
Spring 2020

CIS 120 Tools Setup

Step 1: Java Development Kit (JDK) 8

  1. 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.

  2. 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.
Note: Make sure you do this step before installing Eclipse.

Step 2: Install Eclipse

We recommend using the latest version of Eclipse (Eclipse IDE 2020-03), but earlier versions should work too. Make sure you have completed Step 1 before installing eclipse.

  1. Visit the Eclipse installer page.
  2. 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.
  3. Run the Eclipse Installer. Select "Eclipse IDE for Java Developers" and then "Install" to install Eclipse.
  4. Launch Eclipse.
  5. 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.

  1. Click File --> New --> JavaProject.
  2. Give the project a name
  3. Under "Use an execution environment JRE", make sure that JavaSE-1.8 or JavaSE-8 is selected (do not use a more recent JRE).
  4. Click "Next" (not "Finished").
  5. Under the "Sources" tab, if a "Create module-info.java" box is checked, uncheck it.
  6. Under the "Libraries" tab, click "Add Library", "JUnit", "Next", select "JUnit 5", and click "Finish".
  7. Import the homework files into the project.
    1. Right click on the project you just created.
    2. Choose Import --> General --> File System --> Next
    3. Browse to the folder (e.g. "hw06_temp") that you downloaded with the homework files, then select it
    4. 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
    5. Click "Finish"
    6. 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

  1. First, download the style checker plugin: checkstyle-plugin.zip.
  2. Open Eclipse. Under Help, click on "Install New Software..."
  3. Click "Add..." on the right side
  4. In the pop-up window, click on "Archive..." and navigate to the downloaded checkstyle-plugin.zip file. Click OK.
  5. Select the checkbox available next to "Checkstyle".
  6. Click "Next >", then "Next >" again.
  7. Accept the license agreements, and press "Finish".
  8. You might get a pop-up message saying you are installing unsigned software. Press "Install anyway".
  9. Restart Eclipse to apply the changes.

Configuring Eclipse to use CIS120's Style Guide

  1. Download our style guide configuration file here: cis120-checkstyle-config.xml.
  2. Open Eclipse, and go to preferences (For MacOS, go to Eclipse -> Preferences. For Windows and Linux go to Window -> Preferences).
  3. Click Checkstyle on the left sidebar. If you don't see Checkstyle, reinstall the checkstyle plugin using the instructions above.
  4. Under the "Global Checks Configurations" on the right side click on the "New..." button.
  5. Change the type from "Internal configuration" to "External Configuration file".
  6. Under location, press Browse, and select your downloaded cis120-checkstyle-config.xml file.
  7. Give the config a helpful name, like "CIS120 Style"
  8. Press "OK"
  9. Click on your configuration in the list, then click on "Set as Default" on the right side.
  10. Press "Apply and Close"
  11. If you are asked if you should rebuild projects, press "Yes".

Cannot initialize module TreeWalker error: If you get a 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

  1. Select or create a new Java project (see below).
  2. Right click on the project, click "Checkstyle", and click "Activate Checkstyle".
  3. Eclipse should now show you your style violations if they exist.

Known Bug In Windows: There is a bug in Windows that occurs if the path to your current project includes a space. If there is a space in the path name, the style checker will not work. Example of a path name with a space (between John and Smith): 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.