Computer Laboratory

Course pages 2015–16

Object-Oriented Programming

Principal lecturers: Dr Robert Harle, Dr Andrew Rice, Dr Stephen Cummins
Taken by: Part IA CST, Part IA NST, Part I PBS
Past exam questions

No. of lectures and practicals: 12 + 5
Suggested hours of supervisions: 3 to 4


The goal of this course is to provide students with the ability to write programs in Java and make use of the concepts of Object-Oriented Programming. Examples and discussions will use Java primarily, but other languages may be used to illustrate specific points where appropriate. The course is designed to accommodate students with diverse programming backgrounds; it is taught with a mixture of lectures and practical sessions where students can work at their own pace from a course handbook. Each practical class will culminate in an assessed exercise.

Lecture syllabus

  • Types, Objects and Classes Moving from functional to imperative. Distinguishing state and behaviour. Primitive types. Function prototypes. Objects and classes as custom types. Introduction to parameterised types (templates/Generics).

  • Pointers, References and Memory Pointers and references. The call stack and heap. Iteration and recursion. Pass-by-value and pass-by-reference. Objects as reference types in Java.

  • Creating Classes Modularity. Encapsulation. Information hiding. Access modifiers.  Advantages of immutability. Creating Generic types in Java. Static data.

  • Inheritance Inheritance. Casting. Shadowing. Overloading. Overriding. Abstract Methods and Classes.

  • Polymorphism and Multiple Inheritance Polymorphism in ML and Java. Multiple inheritance. Interfaces in Java.

  • Lifecycle of an Object Constructors and chaining. Destructors. Finalizers. Garbage Collection. Copying Objects. Shallow and deep copies. Copy constructors. Cloning in Java. Cloneable as a marker interface in Java.

  • Java Collections Java Collection interface. Key classes. Collections class. Iteration options and the use of Iterator.

  • Object Comparison Comparing primitive and reference types. Equals. Comparable and Comparator in Java. Operator Overloading.

  • Error Handling Limitations of return values. Exceptions. Custom exceptions.

  • Design Patterns Introduction to design patterns. Examples of Singleton, Decorator, State, Strategy, Observer.

  • Case Studies and Worked Examples

Practical classes

  • Methods, operators and types. This class will concentrate on the fundamentals of imperative programming. Students will learn about Java primitive types, variable declaration, operators and method calls.

  • Control structures. Students will explore the control structures found in Java.

  • Arrays, references and classes. This week the students will explore arrays and references in Java and learn how to define and instantiate their own class.

  • Input/Output and Exceptions. This class will examine streams and Exceptions. Students will read and write data to and from the filesystem and network and learn to handle errors using Java Exceptions.

  • Inheritance and interfaces. This class will explore object-oriented programming as expressed in Java. Students will learn how to extend classes, as well as specify and provide implementations for Java interfaces.

  • Abstraction and graphical interfaces. Students will examine code-reuse through inheritance and the use of inner classes for encapsulation. Students will begin to construct a graphical interface using Swing.

  • Swing and event handling. Students will complete their graphical interface by writing event handlers to control the execution of a graphical application.


At the end of the course students should

  • be familiar with the main features and limitations of the Java language;

  • be able to write a Java program to solve a well specified problem;

  • understand the principles of OOP;

  • be able to demonstrate good object-oriented programming skills in Java;

  • be able to describe, recognise, apply and implement selected design patterns in Java;

  • be familiar with common errors in Java and its associated libraries;

  • understand a Java program written by someone else;

  • be able to debug and test Java programs;

  • be familiar with major parts of Java 8 SE libraries;

  • understand how to read Javadoc library documentation and reuse library code.

Recommended reading

No single text book covers all of the topics in this course. For those new to OOP, the best introductions are usually found in the introductory programming texts for OOP languages (such as Java, python or C++). Look for those that are for people new to programming rather than those that are designed for programmers transitioning between languages (the Deitel book is highlighted for this reason). The web is also a very useful resource -- look for Java tutorials.

* Deitel, H.M. & Deitel, P.J. (2009). Java: How to Program. Prentice Hall (8th ed.).
Flanagan, D. (2005). Java in a nutshell : a desktop quick reference. O’Reilly (5th ed.).
Flanagan, D. (2004). Java examples in a nutshell : a tutorial companion to Java in a nutshell. O’Reilly (3rd ed.).
Gamma, E., Helm, R., Johnson, R. & Vlissides, A. (1995). Design patterns: elements of reusable object-oriented software. Addison-Wesley.
Bloch, J. & Gafter, N. (2005). Java puzzlers. Addison-Wesley.