CPSC 124, Fall 2005
Information Sheet for Test #2
The second test will take place in class on Friday, November 4. It will cover Chapter 4, Sections 5.1 to 5.3, plus a few selected additional topics from the remainder of Chapter 5 and the beginning of Chapter 6. See the list below for full information. You are also responsible for the material on Labs 6 through 9. And of course, you need to know material from the first part of the course as background, even though the questions on the test will not be specifically about that material.
The test will be the usual mix of programming problems, short-answer questions, and perhaps a few longer essay questions. You will certainly be asked to write a couple of complete subroutines and perhaps a complete class. You might be asked to read some Java code and say what it does. You will also be asked to write code that uses subroutines and classes. There are certain built-in subroutines and classes that you should know about -- all of them are listed below. Note that you do not need to know anything about applets, frames, or HTML for this test.
Here are some of the things that you should know about:
Black box Interface of a black box Implementation of a black box Subroutine Subroutines considered as black boxes Contract of a subroutine Subroutine declaration Public, private, and protected Return type of a statement Using "void" as a return type Static subroutines Static member variables Local variables Using public members of a class from outside the class where they are defined Subroutine call statement Parameter list of a subroutine Parameters as part of the interface of a subroutine Formal parameters and actual parameters Rules for what types of actual parameters are allowed Overloading of subroutine names: two subroutines can have the same name, if they have different number or types of parameters Subroutines can call other subroutines Functions: subroutines that return a value Return value of a subroutine The return statement in a function Using a return statement in a void subroutine API (Application Programming Interface) Software toolbox Packages Standard Java packages, such as java.lang, java.io, java.awt, javax.swing Importing classes from a package Defining a class that is a member of a package The full name of a class that is a member of a package Top-down design and bottom-up design with subroutines Preconditions Postconditions Using preconditions and postconditions to define the contract of a subroutine Combining initialization with declaration ( for example: int x = 42; ) Declaring a variable in a for statement ( for example: for (int i = 0; ... ) Default initial values for member variables Named constants ("final static" member variables) Why use named constants? Objects Methods (subroutine defined in a class, hence any subroutine in Java) Classes as factories for objects Instance of a class Instance variables (non-static member variables) Instance methods (non-static subroutines) Classes are types (for declaring variables, formal parameters, return types) A variable cannot hold an object References (or "pointers") to objects The heap null Comparing objects with == and != Objects in assignment statements Using .equals to compare Strings and other objects How to write a class Constructors Creation and initialization of objects Calling a constructor with the new operator Return value of the new operator Using several constructors in the same class Default constructor (if none is explicitely programmed in a class) Garbage collection What makes an object available for garbage collection Object-oriented programming (OOP) Using objects in a program to represent entities in the problem domain Objects have data (variables) and behavior (methods) The software reusability problem Classes as reusable software components Extending an existing class ( public class NewClass extends OldClass ... ) Subclasses and superclasses Inheritance of member variables and methods from the superclass Overriding a method that is defined in the superclass Class hierarchy The class Object that is at the root of the hierarchy of all classes Events Events are "asynchronous" Event-driven programming The relationship between objects and events States and "state variables" Objects as "state machines" "Listening" for events Event-handling methods Interfaces such as MouseListener and MouseMotionListener Using private instance variables for safety Getter and setter methods for private instance variables Javadoc Using Javadoc comments for classes, member variables, and methods The @param and @return tags in Javadoc Javadoc comments can be automatically processed to produce HTML documentation The String class: str.charAt(i) str.length() str.equals(str2) str.replaceAll(original,replacement) The Color class: The constructor new Color(r,g,b) The Graphics class: The x,y coordinate system g.drawRect(x,y,w,h) g.fillRect(x,y,w,h) g.drawOval(x,y,w,h) g.fillOval(x,y,w,h) g.drawString(str,x,y) g.drawLine(x1,y1,x2,y2) g.setColor(color) Some event-handling methods from the MouseListener and MouseMotionListener interfaces: public void MousePressed(MouseEvent e) public void MouseReleased(MouseEvent e) public void MouseDragged(MouseEvent e) The MouseEvent class: e.getX() e.getY() e.isShiftDown()