Lab 1b: Setting Up Your Computer

Installing Java

  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 8u112" (or a higher version number, if this is out of date) and agree to the license. Then proceed to download the binary file for your operating system.

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

A. Windows Setup

  1. First, install Java (instructions provided under the previous Installing Java section). "Windows x86" is for 32 bit systems and "Windows x64" is for 64 bit systems. You can check which yours is by searching for "System" in the Windows Menu or Cortana and then checking the "System type".

    Windows System

    Note that steps 2 and 3 below were done in CS 61A.

  2. Install Python 3. We'll need this for scripts to help make later projects run more smoothly. Let the Python installer add Python to your system's path.
  3. Lastly, we'll need to install git and optionally, a bash shell. Head over here and grab Git for Windows and run the installer. If at any time you don't know what any of the jargon or options mean, you can just stick with the default options already selected for you.

    Git Download
    1. Checking Windows Explorer integration will let you do git things upon right-clicking a file or folder, more specifically, run Git Bash and the Git GUI respectively. This is not required, but might be handy.

      Git Installation 1
    2. Git Bash is a bash shell with built-in git support and lets you use some MinGW/Linux tools. If you don't have a favorite bash terminal or shell (such as Cygwin), Git Bash is a good place to start. Using Git from Git Bash is the recommended option.

      Git Installation 2
    3. Windows and Unix based systems use different things to denote line endings in files. Use the recommended option (the first one) to avoid seemingly mysterious bugs down the road.

      Git Installation 3
    4. If you decide to use MinTTY, note that in the future if you want to run programs like interactive Python, they will need to be launched through winpty. However don't let that scare you, there are plenty of StackOverflow posts on this subject. You can also set up an alias so that you can use python to execute the interactive interpreter instead of winpty python by including the line alias python='winpty python' in your bash profile at ~/.bash_profile.

      Git Installation 4

      At this point, check to make sure everything has been installed properly.

      • Open up your shell (e.g. Git Bash). Make sure javac and java are recognized commands and that javac -version and java -version respond with the appropriate 1.8.0_112 version (or whatever is the most up to date version you installed).
      • Make sure git is a recognized command.
      • Also check that you have the correct Python version installed by running the command python -V (or the command winpty python -V if you are using MinTTY and don't have aliases set up; you can see the bullet above for more information). If python doesn't give you Python 3, you can try python3 or py.

      If all this works, congratulations! You defeated Windows Java Setup! If not, try updating your environment variables, explained below.

Updating 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: Search for Environment Variables in the Windows Menu or Cortana. 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 -- click "New..." 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 (e.g. C:\Program Files\Java\jdk1.8.0_112). Here's an old screenshot for Java 7 (remember, you're installing Java 8!):
    Define Environment Variable
    • PYTHON_HOME: Set this to the location where you installed Python (e.g. C:\Python35 or C:\Program Files (x86)\Python36-32).
    • PATH: (This most likely already exists! It may be lower case.) 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 on the window. At this point, your javac should be working. Close and reopen your terminal (such as Git Bash or 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. It should be noted that java installation and git installation are independent, and don't affect each other.
  6. At this point, check one last time to make sure javac, java, git, and python are all recognized terminal commands. If they are, you finished Windows Java Setup!

B. OS X Setup

  1. First, install Java using the instructions provided under the Installing Java section. Downloading the JDK should also provide javac, a Java compiler on the terminal.
  2. Install Homebrew, a very easy to use package manager. To install, go to your Terminal and enter the following:

    ruby -e "$(curl -fsSL"

    Note: During the process, you may be prompted to enter a password. When you enter your password, nothing will display on the terminal, but the computer is actually recording your password. This is a security measure. Just type your password and hit enter.

  3. 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
  4. If you encounter a warning asking you to download Command Line Tools, you will need to do this. Please follow the StackOverflow post here.
  5. Install python3 and git. You can do this by typing:

    brew install git
    brew install python3

C. Unix and Linux Setup

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 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 apt-get install openjdk-8-jdk

To install python3:

sudo apt-get install python3

To install git:

sudo apt-get install git

D. 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. First, open up your terminal (such as Git Bash) and run this magic:

    mkdir -p ~/temp && cd ~/temp # Forcibly creates a folder "temp", and
    navigate 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 .
  3. In this newly opened directory, create a file with these contents:

    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:

  1. In your terminal, enter ls (list the files/folders in this directory). You should see listed.
  2. Run javac If this produces any output, then something is wrong with your setup. Now if you ls, you should see both 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're done! You can also delete the "temp" folder and its contents as you please.