



Next: Michaelmas Term 2007: Part Up: Long Vacation 2007: Part Previous: Long Vacation 2007: Part Contents
Foundations of Programming (in Java)
Lecturer: Dr F.H. King
No. of lectures and practicals: 20 + 20
This course is normally held in the last two weeks of July for Part II (General) students; it is mandatory for those students to attend the course in July. Diploma students normally attend the course at the beginning of the Michaelmas Term (starting on the Monday before the start of Full Term), but any prospective Diploma students who can attend the July run of the course are urged to consider doing so.
The implementation of Java that is used on the course runs under a local version of Unix. Features of Unix are introduced as they are required during the course but, in the interests of readability, the information below is principally concerned with Java, and references to Unix are sparse.
Aims
The principal aim of this course is to introduce the rudiments of programming via the Java language. A secondary aim is to provide sufficient instruction in Unix to run both Java applications and Java applets using this operating system.
Lectures
- Introduction.
A practical introduction to programming in Java using Unix
and X-windows. Unix commands. X-windows.
- Files and directories.
The Unix filing system and associated commands.
- Elements of programming in Java.
Imperative programming. Compiling and running simple
Java programs. The Java Virtual Machine. Java classes,
data fields and methods. Method arguments and local variables.
- Some Java constructs.
Loops, conditions and relational operators. Reserved words.
Arrays.
- Types, classes and objects.
Types and strong typing. Variables, constants, operators, and
expressions. Primitive data types int and float.
Reference data types. Introducing objects: instantiation, this,
constructors. Visibility modifiers, encapsulation. The toString() method. The static modifier. Instance variables
versus class variables, instance methods versus class methods.
- Further Java types, more about objects.
Primitive data types double and boolean. Objects
continued: class hierarchy, inheritance, overriding, super(),
overloading.
- Yet more Java types, HTML.
Number bases. Primitive data types long, short and byte. Reference data type String. Formatted output. Call by
value versus call by reference. The switch statement.
Rudiments of HTML.
- Sorting, abstract classes.
Introduction to sorting. Rounding errors. Generic types, abstract
classes. Case study: abstract class Shape.
- Packages, recursion.
Java packages: the package statement and the import
statement. $CLASSPATH. Introduction to recursion. Case study:
the Tower of Hanoi.
- Multiple inheritance, interfaces. Multiple inheritance via interfaces. The instanceof operator. Case study: abstract class Shape continued. Mid-course exercise: the Power Problem, an O(log n) algorithm.
- Applets, bit-level programming.
Introduction to applets: the appletviewer command. The Abstract
Windowing Toolkit. Wrapper classes. Operations on bits. Case study:
the Eight Queens Problem.
- Exception handling.
Exceptions: declaring exceptions, throwing and catching exceptions,
try-catch-finally. Lists in Java.
- Input, enum.
Primitive data type char. Unicode. The Java InputStreamReader. Use of enum classes. Case studies:
extracting integers from unformatted data and an enum
illustration.
- Stylistic considerations.
Use and misuse of object oriented programming. Helper classes. Case
study: abstract class Shape improved. Eight-Queens-like
problems. Case study: the Croquet Fixtures Problem.
- Applets, GUIs, threads.
More on applets: adding an ActionListener, implementing an ActionEvent. Member classes. Case study: a simple Graphical User
Interface. Introduction to threaded code. The finalize()
method.
- More about threads.
The synchronized keyword, monitors. Case study: the Triangular
Solitaire Problem.
- Applets, Thread case studies.
Adding a MouseListener, the MouseAdapter class. A simple
buffer. Blocked on synchronized and blocked on wait().
Case study: the Dining Philosophers Problem.
- Class Shape concluded, trees and lattices.
Extending the inheritance hierarchy. Case study: abstract class Shape concluded. Tree representation of an arithmetic expression.
Tree searches versus lattice searches.
- Classes within classes.
Ordinary top-level classes. Nested top-level classes. Member
classes. Local classes. Anonymous inner-classes.
- An expression parser.
Hashing. The lexical analysis and syntax analysis of an
arithmetic expression.
Objectives
At the end of the course students should
- have some familiarity with Unix and the Emacs editor
- be able to write simple Java applications including those which
involve exception handling and threaded code
- be able to write simple Java applets
Recommended reading
* Flanagan, F. (1997). Java in a nutshell. O'Reilly.
* Eckel, B. (1998). Thinking in Java. Prentice Hall.




Next: Michaelmas Term 2007: Part Up: Long Vacation 2007: Part Previous: Long Vacation 2007: Part Contents