
CSc 335 Spring 2007 Practice Questions for Quiz 7, Thursday, 26-Apr, 2007
Answers are provided in Tuesday's presentation and at the Java Ranch
To practice for Thursday's quiz, all of the questions will be from these three sources
•Java gotchas presentation from Tuesday's class
•Answer as many of the 161 questions at http://www.javaranch.com/game/game2.jsp
oYou should know most (except a few things like bit shifting, synchronized, volatile)
If the question feels really obscure, it probably won't be on the quiz
Specifically: there will be no bit shifting questions, no need to know these ops
~ << >> >>> & ^ |
oYou may learn and/or relearn a few new things about Java
oTopics you may need to further explore (inspired by Java Certification Questions)
Java's switch statement (switch argument must be int-compatible, byte, short,
char, and int and Enums
int month = 8;
switch (month) {
case 1: System.out.println("January"); break;
case 2: System.out.println("February"); break;
// …
case 12: System.out.println("December"); break;
default: System.out.println("Invalid month.");break;
}
Overriding methods cannot throw new or broader exceptions
A static class can be used from outside the class. Example: Recangle2D.Double
needs to be static in order to be instantiated outside of Rectangle2D
Java promotion: widening (int to long) or narrowing (double to float)
http://www.javacertificate.com/scjp/docs/javapromotionandconversions.pdf
Override private methods? No, but it looks that way when redeclared
Can't reduce scope when overriding methods (public can not override protected)
Division by 0 different for ints vs. doubles
post increment, pre increment during assignment.
int y = 3;
int x = 0;
x = y++;
assertEquals(3, x);
assertEquals(4, y);
x = ++y;
assertEquals(5, x);
assertEquals(5, y);
•Matching Design Patterns. Know a synopsis of each of Pattern presented this semester. This question
will begin exactly like this on Thursday's quiz.
Here are the names of the 23 Object-Oriented Design Patterns cataloged in the GoF book and also in our required
Design Patterns Java Workbook. Factory, Builder, Prototype, Singleton, Adaptor, Bridge, Composite, Decorator,
Façade, Flyweight, Proxy, Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer,
State, Strategy, Template Method, Visitor. For each synopsis in the right column, write the matching design pattern
name in the left column after each of the letters a. through i. (10pts for the 10 Design patterns presented during C
Sc 335, Spring 2007).
Pattern Name Synopsis
a. Ensure a class has only one instance and there is a global point of access to that instance.
b. Example: A java stream object may add additional functionality to another stream object.
c. …