CSCI 136 :: Fall 2020

Data Structures & Advanced Programming

Home | Schedule | Labs | Handouts | Links | CS@Williams

Document Overview

"Structure5" is the name of the software library that includes the code associated with the course textbook. Since we will be using data structures from the textbook throughout the semester, it is important that we are all able to compile programs that rely on structure5 code. This document includes backround on the various structure5 resources, as well as instructions that let you compile structure5-based programs on your personal computing environment.

Structure 5 Background

There are several download links that refer to various parts of the structure5 software. You should be familiar with them all; they are all useful resources. Here we describe the ways that we hope you will use them.

Setup Instructions

The first step is to download bailey.jar and move that file to a location on your computer that you would like it to "live" for the duration of the semester. (Note: For these instructions, I will use my setup as an example, so whenever you see a path to bailey.jar, you should replace that path with the location of bailey.jar on your machine.) I have a directory called cs136/ inside my home directory where I placed the file. From the terminal, I can navigate to that directory using cd and then type pwd; after doing so, I am told that the location of this directory is /Users/bill/cs136/. Do this yourself and take note of your directory's path; we will use it later.

The rest of the steps are logically similar for macOS, Linux, and Windows, but the particulars of the "preferred approach" vary slightly. Therefore we have created two sets of instructions below, one for macOS/Linux users and one for Windows users. Follow the instructions that apply to your operating system.

At a high level, the steps below will guide you through the process of setting up the environment variable that Java uses to determine the location of imported libraries. Since the structure5 libraries are not part of the default Java installation, we need to add the location of the structure5 libraries to this environment variable so that javac knows where to find it.

Note: All instructions assume you have completed your environment setup according to the instructions in Lab 0.

MacOS and Linux users

When we lauch a new "shell" (aka terminal) in a Unix-like operating system, a lot of things happen in the background. Many of those are explored in detail in the course CSCI 432: Operating Systems, but the "initialization" steps are important to us now. A particular instance of the terminal has a its own "environment" that includes a set of so-called "environment variables". The CLASSPATH environment variable is where javac looks to find imported classes. These instructions explain how to set the CLASSPATH environment variable so that it includes a reference to structure5.

Windows Users

When we open a new Git-Bash window (aka terminal) in Windows, the operating system initializes a set of variables, called environment variables that hold information that various commands need to function properly. Some of these, like the $Path variable that you might have modified when you installed Java, are system-wide, while others are user-specific. To allow your program to access the compiled Java classes contained in bailey.jar, you will need to create (or modify) one such user-specific environment variable, the CLASSPATH variable.

To begin, let's assume that you have created a cs136 directory somewhere in your file system. First be sure to move the bailey.jar file to that directory. For example, if your bailey.jar file is in your Downloads folder and your cs136 directory is in your Documents folder, you can open a Git-Bash window and type


        >mv Downloads/bailey.jar Documents/cs136
      

To get the full name of that directory, in the same Git-Bash window, move to the directory containing bailey.jar then type the pwd command. For example


        >cd Documents/cs136
        >pwd
        /c/Users/Bill/Documents/cs136
      

Now, following the approach taken to install Java, type env into the Windows 10 search box and select Set the system environment variables. Select the Advanced tab and press the Environment Variables... button.

In the dialog box that appears, there should be two lists of variables: user variables and system variables. You will need to add a new user variable (the upper list) called CLASSPATH. Press the New button below the user variables list and a dialog box appears. Enter CLASSPATH for the variable name and enter %CD%;C:\Users\Bill\Documents\cs136\bailey.jar for the variable value. Then select ok in each dialog box to close them all.

Changes to environment variables only take effect in Git-Bash windows that are opened after the variable is created/edited. So, close any open Git-Bash windows and open a new one. Then type echo $CLASSPATH. The result should be


      >echo $CLASSPATH
      %CD%;C:\Users\Bill\Documents\cs136\bailey.jar
    

If this is the case, you should now be able to test whether Java can successfully access the structure5 classes by following the instructions below.

Sample Testing Program

You can copy and paste this program into a file called Sample.java. If you can successfully compile that program, then you are done!

import structure5.Vector;

public class Sample {
	public static void main(String[] args) {
		Vector<String> v = new Vector<String>();
		System.out.println("Success!");
	}
}