Computer Laboratory

Course pages 2014–15

Object Oriented Programming

Getting Access to a Java compiler

As with Poly/ML there many options for you to get access to a machine running a Java compiler, including:

  • MCS. MCS machines can be found throughout Cambridge, including the Intel Room in the Computer Laboratory and (very probably) your College. P More details on the MCS in general can be found here.
  • Remote MCS Linux. You can access an MCS linux machine from your own computer via SSH. More details are here.
  • Your computer See below.

Obtaining the basic Java compiler and libraries

Everything you need is rolled into what are called Java Development Kits (JDKs). Jave is an open specification and there are lots of JDKs you can choose from--any should be fine. The 'official' choice is the Oracle product: see here. Alternatively, you could use OpenJDK: see here. The latter is potentially easier for Mac users since you can use the MacPorts program you used to install poly/ML. Try running sudo port install openjdk7 (I think this is right, but haven't got a Mac to try it: let me know if it fails). If you want to play with Java 8 then obviously get the Java~8 varinat of the JDK.

Once installed, there are two programs you care about. One is the Java compiler (javac) and the other is the Java Virtual Machine that can run the bytecode (just java. If you have installed the JDK as per the instructions, starting up a terminal or console (as you did with poly) and typing either javac or java should do something (albeit not much that's useful.

You can do a full test as follows

  1. Create a new text file called
  2. Copy/paste the following code into the file and save it:
    public class Test {
       public static void main(String[] args) {
          System.out.println("Hello world");
  3. Compile the test code by running javac If all goes well, a Test.class file will appear in the same directory (this is the bytecode)
  4. Run your shiny new bytecode by typing java Test You should see "Hello world" printed.

Obtaining a Prettier Interface

In your practicals you will be encouraged to use the command line to compile and run your code. In the OOP lectures, however, an Integrated Development Environment (IDE) called Eclipse is used. If you wish to work using this at home, you can install it by clicking here. Note there are are lots of variants of the program: you are looking for the "Eclipse IDE for Java Developers".