Saturday, August 28, 2010

SCJP Exam Watch 9 - Class and Interface Declaration

Look for illegal uses of extends and implements.  The following shows examples of legal and illegal class and interface declarations:


class Foo {}                        // OK
class Bar implements Foo {}         // No! Can't implement a class
interface Baz {}                    // OK
interface Fi {}                     // OK
interface Fee implements Baz {}     // No! Interface can't implement an interface
interface Zee implements Foo {}     // No! Interface can't implement a class
interface Zoo extends Foo {}        // No! Interface can't extend a class
interface Boo extends Fi {}         // OK
class Toon extends Foo, Button {}   // No! Class can't extend multiple classes
class Zoom implements Fi, Baz {}    // OK
interface Vroom extends Fi, Baz {}  // OK
class Yow extends Foo implements Fi {}    // OK


Burn these in, and watch for abuses in the questions you get on the exam.  Regardless of what the question appears to be testing, the real problem might be the class or interface declaration.  Before you get caught up in, say, tracing a complex threading flow, check to see if the code will even compile.


Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)

Thursday, August 26, 2010

My sons

My sons picture!
Great!


They are in China now, I miss them and my wife.

SCJP Exam Watch 8 - Obfuscate

The exam creators will tell you that they're forced to jam tons of code into little spaces "because of the exam engine." While that's partially true, they ALSO like to obfuscate.

The following code:

Animal a = new Dog();
Dog d = (Dog)a;
d.doDogStuff();

Can be replaced with this easy-to-read bit of fun:

Animal a = new Dog();
((Dog)a).doDogStuff();

In this case the compiler needs all of those parentheses, otherwise it thinks it's been handed an incomplete statement.


Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
Java, JavaScript, HTML, XHTML, AJAX, CSS, etc.