Java 5: Other features

Java 5 includes many other changes, but there is little reason they would ever pop up in AP courses.

One that bears brief mention is the enum feature, which allows defining classes with a fixed number of instances. Rabbit Hunt's Direction class is a candidate for this.

public enum Direction {
    NORTH, NORTHEAST, EAST, SOUTHEAST,
    SOUTH, SOUTHWEST, WEST, NORTHWEST
}
C++ and Pascal have a similar feature. Java's feature, though, is much richer than the equivalent constructs in those languages. For example, you can have each individual value have instance variables and customized methods.
public enum Direction {
    NORTH( 0, 1), NORTHEAST( 1, 1), EAST( 1, 0), SOUTHEAST( 1,-1),
    SOUTH( 0,-1), SOUTHWEST(-1,-1), WEST(-1, 0), NORTHWEST(-1, 1);

    private int dx;
    private int dy;

    private Direction(int myDx, int myDy) {
        dx = myDx;
        dy = myDy;
    }

    public int getDeltaX() { return dx; }

    public int getDeltaY() { return dy; }
}

(next)