CS211 About Prelim 1

The prelim is
7:30-9:00PM, Thursday, 18 October 2001

The only reason for not taking it then is that you have a conflict with another evening prelim.
If this is the case, please let Gries know by Sunday evening, 14 October.

We will try to make the prelim reasonable in length. Someone who knows the material well should be able to complete the prelim in an hour.

Prelim I will cover the general topics of (1) recursion, (2) classes and subclasses, (3) abstract classes, (4) exception handling, and (5) interfaces, (6) nested classes, and (7) inner classes. To study for the prelim, review the handouts provided for the lectures and the appropriate pages in the text (Weiss). Also, learn definitions and practice writing programs (or program segments).

1. Recursion. Know the definition of (1) a recursive definition, (2) a recursive method, (3) base case, recursive case. Know our four steps in understanding a recursive method (see powerpoint slide 7 of the handout). Know and be able to carry out the steps in executing a method call. You will be asked to write at least one recursive method on the prelim, and you may be asked to execute a method call.

2. Classes and subclasses. The handout for the lecture that reviewed classes contains the important material that you must know: (1) the visibility levels (slide 6); (2) the class as a file drawer (what goes in it?) (slide 8); (3) the format of an instance of class, as a manila folder (slide 8); (4) the frame for a method call (slide 10); (5) the steps in executing a method call (slide 11); (6) how to evaluated a new expression (slide 13), the format for an instance of a subclass (slide 14); (7) overriding a method, and (8) explicit and implicit casting; (9) class Object and its methods equals and toString. Also: (10) writing constructors in a subclass and (11) the use of method toString.

On the prelim, you may be asked to write a class or subclass. You may be asked to execute a call on a method in an instance of a class, or to evaluate a new expression. Practice these things.

3. Abstract classses. The handout for recitation 5 contains the information you need to know about abstract classes. You should know how to make a method abstract and the consequences of doing so. You should know how to make a class abstract and the consequences of doing so.

4. Exception handling. Know: (1) how to write an Exception; (2) how to throw an Exception; (3) how to catch an Exception using a try statement; (4) the rules for propagating a thrown Exception or Error.

5. Interfaces. Know: (1) how to write an interface; (2) how to implement an interface and what that entails; (3) casting to and from interfaces; the class-interface hierarchy (see slide 10 of the handout on interfaces).

You should know interface Comparable (see slide 3 of the handout for interfaces) and be able to write a method that uses it (e.g. in a method that sorts an array whose base type implements class Comparable). You may be asked write an interface or to implement an interface.

6. Nested classes. See slides 4-7 of the handout titled "What's a class?" (25 Sept lecture). You should know that a nested class is a static class that is defined in another class, you should know how to draw nested classes (regular view or flattened view), and you should know the reasons for using a nested class. You may be asked to write a nested class.

7. Inner classes. See slides 8-15 of the handout titled "What's a class?" (25 Sept lecture). You should know that an inner class is a non-static class that is defined in another class, you should know how to draw inner classes (regular view or flattened view), and you should know the reasons for using an inner class. You may be asked to write an inner class.

Here are sample questions:

1. Write a recursive method for computing a*b for integer a and non-negative integer b; you can't use multiplication.

2. Write a recursive method for setting each element of an array to its negation.

3. Write a recursive method that makes changes each character of a String s to lowercase.

4. Define "base case". Write the steps in understanding a recursive method.

4. Write the steps in evaluating a new expression.

5. Write the steps in executing the constructor call in the expression new C(a+b);

6. Define "inner class". Define "nested class".

7. We may give you a specification of a class and ask you to write the class.

8. Consider a class that implements interface CS211List using an array. Define the variables that will be used to contain the stack (and right comments that explain how the stack is stored in the array). Write a toString method that yields the a representation of the stack, with ", "
between adjacent elements.

9. We may give you a program that contains two classes and ask you to make one an inner class of the other.

10. We may ask you to write part of a class that has to throw an exception (e.g. like method getItem in class TagEnumeration).

11. We may give you a class and a few subclasses and ask you to make the class into an abstract class (and some of its methods into abstract methods) and to explain what the purpose of this is.

12. We may ask yout to write a method that performs a linear search on any array of Comparable elements.