Computer Laboratory

Course pages 2013–14

Object-Oriented Programming


The notes as printed

Annotated Slides

The annotated slides from lectures

Examples Sheet

The examples sheet. Please consult your supervisor for an appropriate subset of these questions to do.

Reference Examples

Here are a couple of detailed examples on the topic of references: Understanding Reference Swaps.

Code from Lectures

Getting started with Java at home

As with poly/ML, everything you need is installed on the MCS machines. However, you may prefer to develop your Java skills at home. To do so, you just need to install a JDK (Java Development Kit). 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).

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 shoudl 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.