Computer Laboratory

Course material 2010–11

Object-Oriented Programming

Principal lecturer: Dr Robert Harle
Taken by: Part IA CST, Part IA NST, Part I PPS
Past exam questions
Information for supervisors (contact lecturer for access permission)


This web page is here to support the IA OOP course, which ran in Lent 2011. The course was an attempt to formalise some of the notions students have been exposed to in the Java ticks. It was intended to complement those practicals, but will stand up on its own for anyone not doing the CST paper 1 course.


The handout provided in lecture one is available here.


  • p. 6: "declaritive" should be "declarative"
  • p. 7 slide: "...understanding computer and computers" -> "...understanding computation and computers"
  • p.15 top para: "Looking back oat..." -> "Looking back at..."
  • p. 21 last para: "...are a plenty..." -> "are plenty"
  • p. 24 first para:"...I think this is rather confusing area for Java" -> "...I think this is a rather..."
  • p. 24 second para: The variable names got mixed up. It should have said: "The operating system allocates another int somewhere in memory (called i)and copies the value of the original (i=test_i). All subsequent operations in the procedure occur on the copy (i), which is then deleted at the end of the procedure."
  • p. 25 second para: "...see that really passes..." -> "...see that Java really passes.. ."
  • p.85 top para: " the references of the objects..." should be " the references or the objects..."
  • p.86 slide example: I think it's a bit misleading to use the String class as an example of overriding the equals method (since the == operator compares values for Strings but compares references for any other Object even if the equals method is overridden) -- after seeing this String example, the students may be expecting that p1 == p2 will work as long as the equals method of Person is overridden, but in truth, p1==p2 will still fail but p1.equals(p2) will work
  • p.89 slide: "...then creates and InputStream for it" -> "...then creates an InputStream for it"
  • p.94 top para: "You might that find they don't..." -> "You might find that they don't..."\
  • p.129 State definition: "Allow and object to..." -> "Allow an object to..."
  • p.129 Strategy definition: "...encapsulate each on..." -> "encapsulate each one..."
  • p.129 Composite definition: "...and compositions of objecta uniformly" -> "...and compositions of objects uniformly"
  • p.130 last para: "...if there even s a 'right'" -> "...if there even is a 'right'"
  • The general Abstract factory Pattern in the notes is wrong. The correct version is found in the lecture 9 annotated notes or in any design patterns book.


  • Lecture 1: Review of fetch-execute, pointers, references, Java VM (annotated slides)
  • Lecture 2: Argument passing, modularity, encapsulation (annotated slides)
  • Lecture 3: Bouncing ball example, inheritance, field shadowing (annotated slides). The bouncing ball code is available here. Unzip the file and then run java or java for lots of balls :-).
  • Lecture 4: Polymorphic functions, shape drawing example, abstract classes, interfaces. (annotated slides). The shape drawing code (all 3 versions) is available here. Unzip the file and then run java to view it. Alternatively substitute ShapesOption1 with ShapesOption2 or ShapesOption3 to play with those options.
  • Lecture 5: Constructors, destructors, Class level data, exceptions annotated slides)
  • Lecture 6: Cloning, Java class libraries, Collections (annotated slides). The cloning example I used in lectures can be found here
  • Lecture 7: Generics, comparing objects (annotated slides). The small examples I used in lectures can be found here
  • Lecture 8: Design Patterns: Decorator, State, Strategy, Composite, Singleton (annotated slides). The example Java code for the design patterns is available here.
  • Lecture 9: Design Patterns: Proxy, Observer, Abstract factory (annotated slides). Additionally the Java Puzzlers slides can be downloaded here.

All Source code

I have cherry picked code examples above, but if you really want all of the code I used or prodcued in lectures, look here. No warranties or guarantees that it was left in the optimal state - this is a copy of what was on my laptop after each lecture!

Examples Sheet

The examples sheet for the course can be downloaded here.


  • Q7. The question defines a function double(...), but "double" is a restricted word in java, so you can't compile it. It doesn't change the point of the question but it should have been dbl(...).
  • Q11. For some reason the code skips between calling the Wheel member "radius" and "rimSize". Pick one and change everything else to use it!

Sample Tripos Questions

I have started to produce a few sample exam questions for the course since it's a recent addition to the IA CST lineup.

Update 27/04/11: I have clarified Sample 1 and made solutions available:

At the end of the course I will put up the solutions to these samples.


When I write Java code in lectures I will tend to use Eclipse. This is a free program called and you can download it from here. You can download various add-ons to support different programming languages, but if you download and install the "Eclipse IDE for Java Developers" you should find that has everything you need to write and test Java programs.

If you're wondering why we don't use it in the ticks, it's because we're trying to do two things: i) teach you Java, and ii) make you familiar with UNIX (which is very popular, especially in scientific circles). The eclipse platform is great, but it masks away the UNIX stuff and can be quite bewildering. Once you're proficient in Java, using a tool like Eclipse is highly recommended. But for now, stick to UNIX for the coursework.

If you're looking for a way to do your ticks from home, you can download the Java tools (compiler, virtual machine, etc) here. Alternatively you can login to the PWF from your room (see here and here for details.