David J. Barnes and Michael Kölling: Objects First With Java

A Practical Introduction using BlueJ (Pearson, 2003)

(Summary by PR.)

  1. Objects and Classes

    Creating objects. Example: Shapes class. Calling methods. Parameters. Data types. Multiple instances. State. What is in an object? Object interaction. Source code: compilation. Example: Student class. Return values. Objects as parameters.

  2. Understanding Class Definitions

    Example: TicketMachine class. Examining a class definition. Fields, constructors, methods. Passing data via parameters. Assignment. Accessor methods: header, body, return. Mutator methods. Printing from methods (println). Reflecting on the design of TicketMachine. Making choices: the conditional statement. Local variables. Scope. private. Examining Student class from previous chapter.

  3. Object Interaction

    Clock example. Abstraction and modularization. Modularization in the clock example. Implementing the clock display. Class diagrams versus object diagrams. Primitive types and object types. The ClockDisplay source code. Logic operators. Strings, concatenation, modulo. Objects creating objects. Multiple constructors. Method calls: internal, external. Debuggers. Example: mail system. this. Setting breakpoints. Single stepping.

  4. Grouping Objects

    Grouping objects in flexible-sized collections. Example: a personal notebook. A first look at library classes. ArrayList. Object structures with collections. A memory model for ArrayList. Numbering within collections: staring from zero. Removing an item from a collection. Processing a whole collection: the while loop. Iterating over a collection (iterators). Example: auction system. Casting when retrieving objects from collections. Fixed-size collections: arrays. Example: log-file analyzer. Declaring array variables, creating array objects (with memory model). Using array objects. The for loop.

  5. Documentation for library classes

    Example: The TechSupport system (Eliza-like). Reading the code. Reading class documentation. Interfaces (informally, not Java) versus implementation. Using library-class methods. Checking string equality. Adding random behaviour. Packages and import. Using maps for associations. Map, HashMap. Sets, HashSet. Tokenizing strings. Writing class documentation: javadoc. Public vs private. Example: balls project. Learning about classes from their interfaces. Class variables (static) and constants.

  6. Well-Behaved Objects

    Testing and debugging. Unit testing within BlueJ. Test automation: regression testing, test rigs, automated checking of test results. Modularization and interfaces. Example: calculator. Commenting and style. Manual walkthroughs. Using print statements to debug.

  7. Designing Classes

    Example: World of Zuul (adventure game). Coupling and cohesion. Code duplication. Making extensions. Using encapsulation to reduce coupling. Responsibility-driven design. Localizing change. Implicit coupling. Thinking ahead. Cohesion of methods and of classes. Cohesion for readability and reuse. Refactoring. Design guidelines. Executing withoutBlueJ: class methods, main method.

  8. Improving Structure With Inheritance

    Example: CD/video database. Code duplication in a first attempt. Using inheritance to reduce code duplication. Inheritance hierarchies. Inheritance in Java: access rights, initialization. Adding other types of items to the database. Subclasses and subtyping. Polymorphic variables. The class Object. Polymorphic collections: ArrayList, HashSet, HashMap revisited. Casting revisited. Wrapper classes. The collection hierarchy.

  9. More About Inheritance

    Developing a polymorphic print method for the database. Static and dynamic type. Overriding. Dynamic method lookup. Super call in methods. Method polymorphism (polymorphic method dispatch). toString. Protected access. World of Zuul revisited: transporter rooms using inheritance.

  10. Further abstraction techniques

    Example: foxes and rabbits (predator-prey). Examining the simulation. Improving the simulation. Abstract classes ("Animal"). Abstract methods. The need for multiple inheritance. Limited multiple inheritance through interfaces. Interfaces as types and as specifications. Abstract classes versus interfaces.

  11. Handling Errors

    Example: address-book project. Defensive programming: client-server interaction, argument checking. Server error reporting: notifying the user, notifying the object. Throwing exceptions. Principles of throwing exceptions. Exception classes. The effect of an exception. Unchecked exceptions. Preventing object creation. Exception handling: throws clause, try block. Throwing and catching multiple exceptions. Propagating an exception. Finally. Defining new exception classes. Error recovery and avoidance. Case study: text I/O. Readers, writers, streams. FileWriter, FileReader. Object serialization.

  12. Designing Applications

    The verb/noun method. CRC classes. Scenarios. Class design. Designing class interfaces. User interface design. Documentation. Cooperation: pair programming. Prototyping. Software growth: waterfall model, iterative development. Using design patterns: Decorator, Singleton, Factory method, Observer.

  13. Other Chapters

    Chapter 13 is a complete case study for a taxi company. There are six brief appendices.

This is an objects-early book. Furthermore, it is designed to work with a specific educational IDE, BlueJ. The IDE allows the user to interactively call methods and instantiate objects, without the use of main(). This allows the gradual introduction of concepts instead of their being introduced in a rush just to compile and run "Hello, world!". The book has a preface by James Gosling himself, in which he talks about watching his daughter and her middle-school classmates struggle with a commercial IDE. (This strikes me as something close to child abuse, but I suppose this is acceptable, perhaps even de rigueur, in Silicon Valley.) I have not used the BlueJ application, but Andrew Malton reports that it can be made to work with his quite different proposed approach to CS1, and says it is "way cool".

I am not a fan of the objects-early approach, because I do not think it is appropriate for our curriculum at UW. But I must admit that if I wanted to teach someone object-oriented programming, as opposed to teaching them a first course in computer science, I would have to give serious consideration to this book. Time and again I waited to pounce on some pedagogical weakness, only to end up admiring how the authors handled a new concept. Freed by BlueJ from a language-feature-based treatment, they can introduce ideas when they are natural, and they have chosen well-motivated examples. Thus the progression collection, ArrayList, fixed-size arrays, which I would have thought quite backwards, works (I think -- they may be sweeping some details under the rug and hoping students don't notice). Folded into this are while loops (for going over collections) and for loops (over arrays). Quite nice.

The authors use many predefined classes, but they dissect them, tear them down, make them better, and have the student extend them in quite nontrivial ways. There are no "templates" or "magic" -- BlueJ takes away the need. They actually introduce interfaces (informally) before inheritance, which I would like to see more books do, and their explanation of the various uses of inheritance is careful and sensible. The chapter on Well-Behaved Objects is a model of its type (regardless of language), and the one on Exceptions is the clearest treatment I have seen to date. The one chapter I would fault is the one on software engineering ("Designing Applications"): verb/noun still seems risible to me, and the other material is covered too fast, too soon, too shallow. This should all be put off to another course.

I still think students who go this route will have difficulty in building tools based on sophisticated algorithms, as they are called upon to do in most upper-year courses. But they may well have less difficulty than with any other objects-early book I have seen to date.