Computer Laboratory > Teaching > Course material 2008–09 > Programming Methods


Programming Methods

Principal lecturer: Dr Robert Harle
Taken by: Part IA CST, Part IA NST, Part I PPS


The syllabus was written before I had a good understanding of the programming level of the students (and, indeed, before the Java workbooks were set in stone). Consequently the official syllabus mentions things that will not now be covered (or examined!). Rather than distribute a second syllabus (which may lead to confusion about which is correct), I will highlight the key things that students should understand from each handout as we go. You will find this information further down this page.

Information for Students and Supervisors

This course is unusual in that it presents material in relation to a set of example programs. The goal is to consolidate what has been covered in the practicals and overlap a bit with Software Design. Only design patterns are taught in the usual lecturing sense.

In presenting the examples it is necessary to cover the basics of the application area (this might be a bit of physics or the notion of a colour space, for example). This material is not to be considered examinable. The interest is in the process of going from given theory to implementation (in Java).

The wide range of abilities evident in the Java practicals means that some students will find parts of the material easy - I would encourage supervisors to challenge such students with more demanding questions. On the topic of supervisions, I see anything given for Programming Methods as a direct continuation of their Java supervisions.

It is inevitable that some students will worry about the exam question (marked "Programming Methods & Java"). For clarity, the material addressed by this question may come from anything covered by the Java practicals or Programming Methods, and will likely be a mix of the two.

Books and resources

The course touches a lot of things without going into depth, so it is hard to recommend specific texts. However, I can recommend:

  • Thinking in Java (Bruce Eckel) - good if you are struggling with Java in general.
  • Java in a Nutshell (O' Reilly Publishing) - although primarily a reference on the Java standard library, the first 100 pages or so are a very good intro to Java and Object Oriented programming in general, with examples.
  • Java Puzzlers (Bloch and Gafter) - great for testing your understanding of Java.
  • Design Patterns: Elements of Reusable Object-Oriented Software (Gamma et al.) - the original design patterns book. Good explanations and examples.

You will also finds a lot of good tutorials, explanations and examples just by googling the relevant topic. Wikipedia is pretty good for the design patterns, and the Sun official Java tutorials are good for getting to grips with specific topics in Java.


In lectures I used Eclipse to show code and debug/run programs. Eclipse is free and can be downloaded at I would encourage you to download and try it if you haven't already.

Examples Sheet

Download the examples sheet here: ExamplesSheet.pdf

NOTE TO SUPERVISORS: It is not appropriate to set all the questions. Instead, you should pick a subset based on the programming experience of your students. As a core example set I would go for these questions (some of which are very short):

2, 4, 5, 6, 8, 12, 13, 15, 16, 19, 21, 23, 26, 27, 30, 33

Solution notes ARE available to supervisors from or Student Admin.

Sample Tripos Questions

Since there are no past years of tripos to look at, I will try to come up with a set of tripos-esque questions. I will distribute them in a single document (that will probably update as I come up with more sample questions).

Download the latest set here (solution notes also available on request): SampleExamQuestions.pdf

Handout 1

This material should allow students to:

  • Understand how to make a class immutable.
  • Understand the use of final and static.
  • Understand shallow and deep cloning/copying.
  • Implement a Cloneable class.
  • Appreciate what a marker interface is and why it is useful
  • Appreciate that simulations are not perfect.
  • Appreciate the difference between a-priori and a-posteriori event detection.
  • Appreciate that discretizing time can cause problems.

Notes: PDF | Annotated Powerpoint


Handout 2

This material should allow students to:

  • Define what a design pattern is and describe when it is useful
  • Recognise the Decorator, State, Strategy, Composite, Singleton, Proxy, Observer and Abstract Factory patterns
  • Discuss the advantages and disdvantages of the above patterns
  • Apply the above patterns to solve problems
  • Implement the simpler patterns in Java

Notes: Annotated PDF

Handout 3

This material should allow students to:

  • Use interfaces sensibly to decouple classes
  • Identify and use the MVC pattern
  • Understand the disadvantages and advantages of the MVC pattern
  • Explain how MVC is used in Swing
  • Discuss the use of the Composite pattern in Swing
  • Discuss the use of the Observer pattern in Swing
  • Understand the basics of List, Set and Map and choose amongst them appropriately.
  • Use a Map as a quick way to sort things without a custom comparator

Notes: PDF | Annotated Powerpoint


Handout 4

This material should allow students to:

  • Understand the basics of Sockets and ServerSockets
  • Understand that Java abstracts data input and output to streams in exactly the same way as it does for files.
  • Implement a really basic non-threaded server
  • Understand that notion of a thread and have a vague idea that concurrency causes problems (solutions not important at this stage)
  • Create a basic explicitly-threaded program in Java by extending Thread appropriately.

Notes: PDF | Annotated Powerpoint


Handout 5

This material should allow students to:

  • Understand the basics of handling video in Java
  • Understand that algorithm choice is very important to maximise performance
  • Realise that logically-correct algorithms may not be practical (esp. if recursive)
  • Implement and use a custom comparator to sort in a custom fashion

Notes: PDF | Annotated Powerpoint


Lecture 6

This lecture was not taught material per-se, but a look at some Java puzzles that illustrate interesting facets of Java. It was not given as a handout (or everyone would have known the answers!). Instead the students voted for their answers. The explanations are included in the slides for offline review. The annotated pptx file contains some (very) rough estimates of the voting splits scrawled next to the answers.

The last few slides provide a review of cloning and sorting and would probably be worth a read through if nothing else.

Slides: PDF | Annotated Powerpoint