Lab 1b: Setting Up Your Computer

A. Installing Java

(This section is for Windows and OS X only. For Unix and Linux, continue on to Unix and Linux Setup.)

  1. You'll need to install the Java 1.8 JDK in order to compile your code for this class. First, head over to the Oracle website.

    Oracle Website

  2. Click the "Download" button for the JDK.

    Java JDK

  3. On the following page, find the download section entitled "Java SE Development Kit 8u144" and agree to the license. Then proceed to download the binary file for your operating system.

    Java Agreement

  4. Run the installation file and follow the prompts to install Java onto your computer.

Once finished, continue on to Windows Setup or OS X Setup.

B. Windows Setup

Complete the Installing Java section first if you haven't already.

  1. Install python3. We'll be using it to compile more complicated projects later on.
  2. Update your environment variables to include Java and Python. The fine-grain details of this will depend on your OS, but the first step is to open up your system (not user) environment variables...

    1. Windows 8/8.1/10: Press Windows and type Environment Variables. Select "Edit the system environment variables". Windows 7 and earlier: Search the control panel for the same thing.

      Windows 10 Search

      Windows 8.1 Search

      Windows 7 Control Panel

    2. Navigate to the "Advanced" tab, and click "Environment Variables...".

      System Properties

    3. Under "System variables" (this section will be unavailable if you are editing account or user variables), click "New..."

      System Variables

    4. Define the following variables and use the values specified below as the value of the variable. If the variable already exists, select the variable and click "Edit...", then add the value specified below to the front of the value, followed by a semicolon.

      • JAVA_HOME: Set this to the location which you installed Java JDK (for example, C:\Program Files\Java\jdk1.8.0_91).

        Define Environment Variable

      • PYTHON_HOME: Set this to the location where you installed Python, for instance, C:\Python35 or C:\Program Files\Python35.
      • PATH: (This most likely already exists!) Add %JAVA_HOME%\bin;%PYTHON_HOME%; to the beginning of the value of this variable. (The % symbols demarcate a path substitution in Windows. Note that there are NO spaces. Putting spaces in Windows path definitions can sneakily RUIN your day!)
    5. Save your changes by hitting OK to close out of "Environment Variables" and "System Properties". At this point, your javac should be working. Open Command Prompt and type in javac -version and ensure that it responds java version "1.8..... If it claims javac isn't a recognized command, something is wrong with your path setup. (Note that you must OK out of those configuration windows first for your changes to take effect.)
  3. Lastly, we'll need to install git. Head over here and grab git for Windows. Run the .exe file that is downloaded, make sure to check the options as indicated in the screenshot (Windows Explorer integration allows yourself to do git things upon right-clicking a file or folder (can be handy)), and continue clicking "Next" until it is installed. When you are finished, you should now have both git and Git Bash; Git Bash is a bash shell with built-in git support.

    Git Installation

At this point, everything should be working now. Continue on to the Test Run section and return here if something goes wrong.

C. OS X Setup

Complete the Installing Java section first if you haven't already.

  1. Install Homebrew, a very easy to use package manager. To install, go to your Terminal and enter the following:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Then, check to make sure brew is working properly on your system by typing:

    brew doctor

    You may encounter warnings like this, but you should be fine. Proceed to the next step. Homebrew Warnings

  3. If you encounter a warning asking you to download Command Line Tools, you will need to do this. Please follow the StackOverflow post here.
  4. Install python3 and git. You can do this by typing:

    brew install git
    brew install python3

At this point, everything should be working now. Continue on to the Test Run section and return here if something goes wrong.

D. Unix and Linux Setup

  1. If you are using a Linux/Unix distro, use your package manager (apt-get, yum, etc) to install the Java 1.8 JDK, python3, and git.

    First, check to see if Java 8 is already installed by typing:

    java -version

    If you see "The program java can be found in the following packages" or something similar, Java has not been installed yet. You can install java by typing:

    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java8-installer

    To install python3:

    sudo apt-get install python3

    To install git:

    sudo apt-get install git

    Again, be sure to use your distro-specific package manager. If you are using yum for example, substitute the apt-get command with yum.

    Finally, if you have an older version of java, you can check out these instructions for how to manage multiple Java installations.

Alternatively, follow these beautiful instructions for Ubuntu, Linux Mint, or these beautiful instructions for CentOS, Redhat, Fedora. If you're a different Debian system, you can follow the first link. If you're running a Linux distro that hasn't been mentioned, you probably already know how to install Java 8 and much more!

At this point, everything should be working now. Continue on to the Test Run section and return here if something goes wrong.

E. Test Run

Let's try running a Java program to try out your new setup! Just this once, we will tell you to do things without any explanation as to how or why they work. This dark magic will be explained in lab 1 and lecture 1, but for now, is just here for you to check your setup in a quick n' dirty manner.

  1. Open up your terminal (for Windows, use Git Bash or a related bash terminal) and run this magic:

    mkdir -p ~/temp && cd ~/temp

    (Note: This forcibly creates a folder "temp", and navigates there.)

  2. Then, do a platform specific action to open your file explorer in this directory:

    • Mac: open .
    • Windows: explorer .
    • Ubuntu: gnome-open .
    • Linux Mint: xdg-open . or mate .

    If this command does not work, you can always manually open the file explorer like you normally would.

  3. In this newly opened directory, create a file called HelloWorld.java with these contents (you can do this using an ordinary text editor):

    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello world!");
        }
    }

Okay. Now you're ready to start the real test. Here's a screenshot of your dream goal, a perfect, no-error run-through that indicates your java setup is just fine:

hello_world

  1. In your terminal, enter ls (list the files/folders in this directory). You should see HelloWorld.java listed.
  2. Run javac HelloWorld.java. If this produces any output, then something is wrong with your setup. If there is no output, when you ls, you should see both HelloWorld.java and a freshly created HelloWorld.class (the javac command created this file).
  3. Run java HelloWorld. It should print out "Hello world!" for you. If it didn't, something is wrong with your setup!
  4. You may now delete the "temp" folder and its contents. Either delete the folder manually or if you're feeling brave, you may use the command:

    cd .. && rm -rf ~/temp

    (This navigates you into the parent directory then removes the folder ~/temp and its contents.)

  5. You're done! You may now proceed to Lab 1.