Course pages 2013–14
Object-Oriented Programming
Handouts
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
- Toy code for the bouncing ball simulation
- Polymorphism shape drawing example
- Code used to demonstrate the use of interfaces
- Code used to demonstrate exceptions and error handling
- Cloning code: (manual field copy) (copy() function) (copy constructors) (Java's clone()) and examples of deep copying.
- Collections Examples
- Comparable/Comparator code
- Design Patterns code: Composite, Observer, State, Decorator, Singleton, Strategy
- Code from the examples class (TickStore, Logger, and a binus ChristmasTree to demo cloning)
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
- Create a new text file called Test.java
- 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"); } }
- Compile the test code by running
javac Test.java
. If all goes well, a Test.class file will appear in the same directory (this is the bytecode) - Run your shiny new bytecode by typing
java Test
You should see "Hello world" printed.