The T-Files


Sat, 24 Mar 2007

Sun Certified Programmer for Java 5

class Bird {
  { System.out.print("b1 "); }
  public Bird() { System.out.print("b2 "); }
} 

March is the end of the fiscal year and thus time for annual performance reviews. To beef up my sheet I took the SCJP exam today. Now this is an exam you want to prepare for, even if (or maybe especially if) you have to use Java on a daily basis. The test is a computerised multiple choice test, delivered at a Prometric Testing Center, same as with the Oracle exams. Prometric seems to be doing really well, they have hundreds of exams for dozens of subjects, lots of offices all over the place, the exams are not cheap, and there are always plenty of other people when I go. Being an automated test (you get your score immediately afterwards) makes it necessary for clear-cut right and wrong answers. But the wrong answers cannot be too obviously incorrect, otherwise the exam would be too easy. As a result, things are quite tricky, you have to really pay very close attention to (often terribly contrived and not at all real-life) details, and the exercise somewhat resembles a puzzle or quiz: It is kind of fun, in the same way Sudoku is fun. Just do not expect to survive on your school math skills alone.

class Raptor extends Bird {
  static { System.out.print("r1 "); }
  public Raptor() { System.out.print("r2 "); }
  { System.out.print("r3 "); }
  static { System.out.print("r4 "); }
}

In particular, you need to be prepared to watch out for things like

  • incorrect indentation to confuse you (which is normally taken care of by the IDE's code formatter),
  • funky interpunctuation that causes errors (which the compiler would catch for you),
  • calls to core API methods that do not exist or with the wrong parameters (again: compiler),
  • defining different variables in different scopes using the same name,
  • calling massively overloaded methods where it is not all obvious how the combination of widening, auto-boxing, and varargs would affect the dispatch.
class Hawk extends Raptor {
  public static void main(String[] args){
    System.out.print("pre ");
    new Hawk();
    System.out.println("hawk ");
  }
}

You get 72 questions and three hours (which is plenty, I finished in about half that).

What is the result?

A) pre b1 b2 r3 r2 hawk
B) pre b2 b1 r2 r3 hawk
C) pre b2 b1 r2 r3 hawk r1 r4
D) r1 r4 pre b1 b2 r3 r2 hawk
E) r1 r4 pre b2 b1 r2 r3 hawk
F) pre r1 r4 b1 b2 r3 r2 hawk
G) pre r1 r4 b2 b1 r2 r3 hawk
H) The order of the output cannot be predicted.
I) Compilation fails.