Monday 9 July 2012

Points to Remember


                                                  Points To Remember for SCJP


The datatype in a switch statement must be convertible to int, i.e., only byte, short, char and int
can be used in a switch statement, and the range of the datatype used must cover all of the cases
(case statements).
An integer literal (w/o a decimal pt) is assumed to be a 32-bit int primitive, but a value containing
a decimal point is assumed to be a 64-bit double.
Wrapper classes for primitives produce immutable objects.

• Java characters are 16-bit unicode characters, and they can be initialized in the following ways:
o char c1 = '\u0057'
o char c1 = 'w'
o char c1 = 87
o char c1 = (char) 87 (acc to RHE)
o char c1 = '\r'

• instanceof operator can take a class, an interface or an array type as an argument.
• To test if an object is an array, use: myObject.getClass().isArray();
• MenuContainer interface is implemented by Container, Frame, Menu and MenuBar
• An identifier must begin with a letter, a dollar sign ($), or an underscore. Subsequent characters
maybe letters, $, underscore, or digits, but NOT other characters liek %, &, etc.
• The keywords syncrhonized, private and protected cannot be used with a class.
• A variable declared inside a try block cannot be used in the catch block.
• If no super-class constructor is explicitly called, and there is no call to other constructor (using
this(..)), the default constructor of the superclass (w/o any arguments) is automatically called.
• wait(), notify() and notifyAll() are the instance methods of Object class, not Thread class (but they
are inherited by Thread class).
• stop(), suspend() and resume() are deprecated methods in Java 1.2
• References to member methods are resolved at runtime using the type of object, but the references
to member variables are computed at compile time using the type of the reference.
• Javadoc documentation does not list private variables and methods.
• A valid overload differs in teh number or types of arguments. Difference is return type only is not
a valid overload.
• Inner classes defined local to a block may not be declared to be static.
• Member inner classes cannot have the same name as enclosing class, but they CAN subclass the
enclosing class.

Basic Instructions


                                                  


What are the potential trips/traps in SCJP exam?
• Two public classes in the same file.
• Main method calling a non-static method.
• Methods with the same name as the constructor(s).
• Thread initiation with classes that don’t have a run() method.
• Local inner classes trying to access non-final vars.
• Case statements with values out of permissible range.
• Math class being an option for immutable classes !!
• instanceOf is not same as instanceof
• Private constructors
• An assignment statement which looks like a comparison if ( a=true)...
• System.exit() in try-catch-finally blocks.
• Uninitialized variable references with no path of proper initialization.
• Order of try-catch-finally blocks matters.
• main() can be declared final.
• -0.0 == 0.0 is true.
• A class without abstract methods can still be declared abstract.
• Map doesn’t implement Collection.
• Dictionary is a class, not an interface.
• Collection is an Interface where as Collections is a helper class.
• Class declarations can come in any order ( derived first, base next etc. ).
• Forward references to variables gives compiler error.
• Multi dimensional arrays can be sparce ie., if you imagine the array as a matrix, every row need not
have the same number of columns.
• Arrays, whether local or class-level, are always initialized,
• Strings are initialized to null, not empty string.
• An empty string is NOT the same as a null string.
• A declaration cannot be labelled.
• continue must be in a loop ( for, do , while ). It cannot appear in case constructs.
• Primitive array types can never be assigned to each other, eventhough the primitives themselves can be
assigned. ie., ArrayofLongPrimitives = ArrayofIntegerPrimitives gives compiler error eventhough
longvar = intvar is perfectly valid.
• A constructor can throw any exception.
• Initilializer blocks are executed in the order of declaration.
• Instance initializer(s) gets executed ONLY IF the objects are constructed.
• All comparisons involving NaN and a non-Nan would always result false.
• Default type of a numeric literal with a decimal point is double.
• integer (and long ) operations / and % can throw ArithmeticException while float / and % will never,
even in case of division by zero.
• == gives compiler error if the operands are cast-incompatible.
• You can never cast objects of sibling classes( sharing the same parent ), even with an explicit cast.
• .equals returns false if the object types are different. It does not raise a compiler error.
• No inner class can have a static member.