Topics for Exam 1 in Com S 362 This exam covers topics from homeworks 1 and 2. REMINDERS This test is open book and notes. However, it is to be done individually and you are not to exchange or share materials with other students during the test. If you need more space, use the back of a page. Note when you do that on the front. This test is timed. We will not grade your test if you try to take more than the time allowed. Therefore, before you begin, please take a moment to look over the entire test so that you can budget your time. For diagrams and programs, clarity is important; if your diagrams or programs are sloppy and hard to read, you will lose points. Correct syntax also makes some difference. READINGS Read at least chapters 1-2 and 8 of Ken Arnold, James Gosling, and David Holmes's book, The Java Programming Language Third Edition (Addison-Wesley, Reading, Mass., 2000). If you are new to Java you might also want to read the interesting (to you) parts of the "new to Java" section on-line at http://developer.java.sun.com/developer/onlineTraining/new2java/ If you have more time, you might want to read further (at least chapters 3-4) in the Java Programming Language Third Edition book. See also the syllabus for further readings. TOPICS Topics marked + below are more important than topics marked - below. Topics marked with ++ are almost certain to be on the test. In general, subjects and skills that are more like the homework will be more important, but those covered in the exercises will also be somewhat important. * Object Orientation + Explain the features of object-oriented (OO) languages like Java that make it easier to cope with change, and give examples to illustrate these ideas. - What are the disadvantages of OO programming techniques? - For what kinds of programming projects would OO techniques not be needed? * Running Java + Explain what the CLASSPATH is and how it affects compiling and running Java programs. - Manipulate the CLASSPATH and/or Eclipse to run Java programs. + Explain the connection between packages and directories in file-system implementations of Java. * Exception Handling + What are the reasons someone would design a method that throws exceptions? + What are the alternatives to exception handling and when might exceptions be better? ++ Write Java code that throws and catches exceptions [HW1]. + Give the output of simple Java programs that use exceptions. + Write code for methods that throw exceptions. + Write code to declare checked and unchecked exception classes. + Use a finally clause and to explain when it should be used. * Objects and Classes + Understand questions using Java terms (such as method, field, final, static, abstract method). + Describe the difference between static and non-static (instance) fields and methods. - What advantages does the singleton design pattern have over using static fields and methods? + Explain what happens when Java executes a new expression, such as new Vehicle(). + Read Java code that defines an abstract data type (ADT). + Give the output of simple Java programs using instance and static variables, and instance and static methods. + Explain what statements or expressions violate Java's privacy rules. This includes understanding packages and default privacy in Java. - Diagnose violations of Reil's heuristics for Java class that define ADTs, as found in chapter 2 of his book. + Write code for a Java class that maintains some information, such as the Vehicle example. + Give the Java interface that corresponds to a Java class. ++ Write code that does file I/O in Java, especially reading and writing strings from files. [HW1] ++ Write correct Java code for simple methods, given an interface, and specifications in javadocs, JML annotations, and/or JUnit tests. [HW2] ++ Declare fields to represent a specified ADT's data, and to write Java code for methods to implement that specification. * Inheritance and Polymorphism + Explain what the purpose of writing a subclass (using inheritance) is. + Explain the advantages and disadvantages of using inheritance vs. composition. + Explain what is meant by (subtype) polymorphism. Why is it important? + What problem does the polymorphism pattern solve? Describe the solution that polymorphism offers to this problem. Give an example. - When should one use the template method design pattern? How does it differ from the polymorphism pattern? Give an example. + Explain the differences, in Java, between a class and an interface. - Explain the difference between inheritance and behavioral subtyping. - Read Java code that defines recursive, tree-like ADTs. - Answer questions about the fields and methods found in a subclass object given Java code for the superclass and subclass. - Determine the effects of method calls when subtyping and polymorphism are used (in subclasses and implementations of interfaces), especially in for down calls to overridden methods. - Read and write constructors and methods that use "super" to inherit behavior from the class's superclass. - Explain what an abstract method is, and when to use it in Java; explain what an abstract class is. - Explain what statements or expressions violate Java's privacy rules for clients and subclasses when the superclass's uses "protected" visibility. - Diagnose violations of Reil's heuristics for inheritance, as found in chapter 5. - Refactor code for recursive types so that it no longer violates these design heuristics. This includes knowing when to use interfaces (implements in Java), instead of inheritance (extends in Java) for implementing a class.