Q1 answers: SWING is thread-safe. NO SWING uses double-buffering to avoid flickering. YES ActionListeners must call paint() to update the screen. NO MouseAdapter is an abstract utility class simplifying MouseListeners. YES Swing and AWT have nothing in common. NO Non-modal dialog demand user input before allowing further action. NO Generic types help the compiler catch more errors. YES Generic types reduce the number of casts needed. YES Threads stop once the run method finishes. YES Callables are like Runnables, but also return a result. YES You cannot have more threads than CPU cores in a ThreadPool. NO Synchronized methods are used to avoid inconsistencies. YES Any object in Java can be serialized. NO Readers and Writers are for textual IO only. YES Serialization handles shared structure correctly. YES Java uses automatic garbage collection, therefore has no memory leaks NO Objects in Java are always allocated on the runtime stack. NO Objects in Java are never allocated on the runtime stack. accepted both YES & NO because of Java 1.6 If two objects have the same hash-code, they are also equal. NO Any implementation of the equals method in Java must be transitive. YES ---------------------------------------------------------------------- Q2 answers: System.out.println("comp204b test".replaceFirst(" ",":")); "comp204b:test" System.out.println("comp204b test".matches(" ")); false System.out.println("comp204b test".matches("^\\d+")); false System.out.println(java.util.Arrays.toString("comp204b test".split("\\W"))); ["comp204b", "test"] or new String[]{"comp204b", "test"} or similar System.out.println(java.util.Arrays.toString("comp204b test".split("\\d+"))); ["comp", "b test"] or new String[]{"comp", "b test"} or similar ---------------------------------------------------------------------- Q3 code: public class C { public static void main(String[] args) { A object1 = new A(7); System.out.println(object1); System.out.println(""); A object2 = new B(3); System.out.println(object1); System.out.println(object2); System.out.println(""); B object3 = new B(); System.out.println(object1); System.out.println(object2); System.out.println(object3); } } class A { public A() { _a++; } public A(int a) { _a = a; } public String toString() { return "A: _a = " + _a + "; "; } private static int _a; } class B extends A { public B() {} public B(int b) { super(b); _b = b; } public String toString() { return "B: _b = " + _b + "; " + super.toString(); } private int _b; } Q3 output: A: _a = 7; A: _a = 3; B: _b = 3; A: _a = 3; A: _a = 4; B: _b = 3; A: _a = 4; B: _b = 0; A: _a = 4; ---------------------------------------------------------------------- Q4 code: class X { String m( X arg ) { return "in X got a " + arg.getClass(); } } class Y extends X { String m( Y arg ) { return "in Y got a " + arg.getClass(); } } public class O { public static void main(String[] args) { X x = new Y(); Y y = (Y) x; System.out.println( x.m(x)); System.out.println( x.m(y)); System.out.println( y.m(x)); System.out.println( y.m(y)); } } Q4 output: in X got a class Y in X got a class Y in X got a class Y in Y got a class Y ---------------------------------------------------------------------- Q5: public final class ImmutableMap implements Map { HashMap mapping; // // constructor which initialises from a given map of appropriate type // public ImmutableMap( Map someMap ) { mapping = new HashMap( someMap); } // // return the size of this map. // public int size() { // <=== return mapping.size(); // <=== } // // retrieve the value associated with the given key // public V get( K key) { // <=== return mapping.get(key); // <=== } // // update the value associated with the given key // public V put( K key, V value) { // <=== (also excepted other return types, e.g. boolean/void return null; // <=== // throw new RuntimeException("cannot modify ImmutableMap " + this); // <=== // or similar // <=== } }