JMU JMU - Department of Computer Science
Help Tools
Installing a Java Development Environment


1 Introduction

There are an enormous number of development environments for Java, some of which are freely available and some of which are commercial products. You may, in principal, use any development environment you want for CS149. In fact, because individual Professors have different preferences, different sections will be using different environments this semester.

I recommend that you use the environment described below. (This is not because it is necessarily the best environment but because it is fairly easy to install on all platforms, it is easy to use, provides all of the capabilities you will need, and does not provide too many capabilities.) In fact, I will assume that you are doing so and will be unable to provide assistance if you are not. However, the choice is up to you.

2 An Important Note

Many applications (including many development tools) use the space character as a delimiter. This means that, in general, it is a bad idea to use spaces in file names and/or directory names. So, while it is common practice to use directory/folder names like My Documents, you should avoid doing so when you can.

That said, some of the software you install may want to use names that include spaces and, unless you're confident, you should not change the defaults.

3 Downloading the Necessary Components

All of the components in the supported Java development environment are freely available. You should begin by downloading and saving all of the following to an appropriate directory/folder.

Java SE Development Kit v14
(You may use the OpenJDK if you prefer, which can be downloaded from jdk.java.net/14, but the Oracle version is easier for most people to install. Make sure you download the version for your operating system.)

jGRASP v2.x
(There is a version that is "bundled with the OpenJDK", however, if you install that version it will be more difficult for you to use Java from the command shell. So, I recommend the version that "requires Java". Make sure you download the version for your operating system.)

Checkstyle v8.35
(This is just a single file with an extension of .jar. Because of its extension, in most browsers you can download it by clicking on the link. However, in some browsers you may need to right-click or control-click on the link.)

CS149 Style Checks (This is just a single file with an extension of .xml. Because of its extension, to download it in most browsers you need to right-click/control-click on the link and select Save.)

Note that if you have not written programs in Java before then you probably do not have the JDK installed. You might think you do because you have the Java Runtime Environment (JRE) installed, but the two are not the same. The JRE only allows you to run programs written in Java, it does not allow you to write them.

4 Installation

You should install the components in the following order:
  1. Java SE Development (JDK) ( Instructions)
  2. jGRASP ( Instructions)
    Note: You can ignore any warnings you receive about the version of Java.
  3. Checkstyle (Instructions)
  4. A file comparison utility (see the course "Tools" page for options).

While you may use any file comparison utility you, you should be careful when choosing one. The lab computers use Meld so, if you are running Linux and want to be consistent, you should install it. Otherwise, you should probably install kdiff3 (which is available for all major platforms).

5 Configuring the Terminal Window (a.k.a., Command Shell)

To use Java from the command line the operating system must be able to find the directory/folder that contains the javac executable. To see if this is the case, open a terminal window (a.k.a., command shell window) and type javac -version and hit return. If everything is setup properly, you will get a message like javac 1.14.xxx. If not, you will need to add the directory/folder that contains the javac executable to the search path (which is different from the class path that Java itself uses, so don't be confused). The process for doing so is described on the Java download site (and elsewhere on the WWW).

6 Configuring jGRASP

6.1 Consistency with the Course Style Guide

In jGRASP, click on Settings, pull down to CSD Window Settings and across to Workspace. Then:
  1. If necessary, de-select the default box next to "Force Newlines" and check the checkbox.
  2. If necessary, de-select the default box next to "Auto Indent" and check the checkbox.
  3. If necessary, de-select the default box next to "Soft Tabs" and check the checkbox.
  4. If necessary, de-select the default box next to the "Tab Size" slider and change the value to 3.

6.2 Look and Feel

The default GUI for jGRASP is, in the opinion of many people, not visually pleasing. To change it, click on Settings, pull down to Look and Feel, and select one of the alternatives. (If you want a consisten look and feel across different operating systems, choose Nimbus. If not, you should probably choose the look and feel for your OS.)

7 Testing the Installation Using jGRASP

To test your installation using jGRASP:
  1. Run jGRASP.
  2. Click on File, pull down to New, and pull down to Java.
  3. Copy and paste the following fragment:
    /**
     * Test the installation of the CS149 development environment.
     *
     * @author  Prof. David Bernstein, James Madison University
     * @version 1.0
     */
    public class InstallationTest {
    
        /**
         * The entry point of the program.
         *
         * @param args  The command line arguments
         */
        public static void main(String[] args) {
            System.out.println("Java is installed correctly.");
        }
    }
    
    into the editing window.
  4. Click on File and pull down to Save As, then click on the "Home" icon, set the "Format" to Binary/Unix, name the file InstallationTest.java, and click on Save.
  5. Click on Build and pull down to Compile (or click on jgrasp-CompileFile.png).
  6. You should see several lines of text in the "Compile Messages" window, ending with "----jGRASP: operation complete." (Note: You may see a warning message about the bootstrap path. You can ignore this message. It's generated because you have v8 installed but are using v7.)
  7. Click on Build and pull down to Run (or click on jgrasp-Run.png).
  8. You should see the text Java is installed correctly. in the Run I/O window.
  9. Click on Tools, pull down to Checkstyle and over to Check File (or click on jgrasp-RunCheckstyleOnFile.png).
  10. You should see a message like:
    Starting audit...
    [ERROR] InstallationTest.java:14: 'method def modifier' has incorrect indentation level 4, expected level should be 3. [Indentation]
    [ERROR] InstallationTest.java:15: 'method def' child has incorrect indentation level 8, expected level should be 6. [Indentation]
    [ERROR] InstallationTest.java:16: 'method def rcurly' has incorrect indentation level 4, expected level should be 3. [Indentation]
    Audit done.
              
  11. Correct the indentation problems.
  12. Save the file and run Checkstyle again -- you should have no errors.

8 Testing the Installation from the Command Line

To test your installation from the command line:
  1. Open a terminal window (a.k.a., command shell window). If you don't know how to do this, search the WWW for "windows command shell window" or "OSX terminal window" or "Linux terminal window".
  2. Navigate to the directory containing the InstallationTest.java. If you don't know how to do this, search the WWW for the "cd command" in your operating system.
  3. Type javac InstallationTest.java.
  4. You shouldn't get any messages.
  5. Type java InstallationTest.
  6. You should see output like:
              Java is installed correctly.
              

If, at any time, you get a message like "unrecognized" or "not a command", you need to configure the terminal window (a.k.a., command shell) as discussed above.

Copyright 2020