Lab 01 for CS112: Recursion and Order Notation

Teaching Fellow: Diane H. Theriault (deht@cs.bu.edu, http://cs-people.bu.edu/deht)

Main course web page: http://www.cs.bu.edu/fac/byers/cs112.html

Lab page url: http://cs-people.bu.edu/deht/cs112_spring11
Lab times: Monday: 10-11, 11-12. Friday 2-3

Topics: Inheritance, Interfaces, Collections (Queue), Iterators, Generics

Class Notes

Skeleton Code: PartyRunner.java
(I have put all of the code in one file this time, so you won't have ten files that are five lines each. However, this is not good practice and you should really separate your work into multiple files.)

Solution Code: PartyRunner.java

Highlights

  • Inheritance reflects an "is a" relationship between two classes. The subclass is a more specific notion of the superclass.
  • Inheritance is indicated in Java by the keyword "extends."
  • Subclasses can override (change) the behavior of methods of the superclass.(This is polymorphism.)
  • An Interface is a declaration of a set of methods (and possibly some variables). When a class claims to implement an interface, it is promising to provide a certain set of functionality.
  • In Java, a class can only extend (inherit from) one other class, but may implement many interfaces.
  • "Collection" is a Java interface that includes methods like add(), remove(), size(), etc. It is implemented by a number of classes in the Java library.
  • Iterators provide a unified way to access elements of collections.
  • "Queue" is a Java interface. Classes that implement this interface promise to deliver items in a first-come, first-serve way.
  • Generics allow the programmer to promise what type of items are in a Collection. The syntax for a Generic is Collection<...>
  • Generics allow type-checking to be done at compile-time, instead of run-time.
  • The Lab for this week involves helping the casts of 3 popular Discovery Channel series arrive at my house for a party.
  • References

    The Java Doc. Keep this under your pillow.

    Inheritance and Interfaces
    Collection API, Linked List API, Queue API
    Generics