March 26, 2009

(TIPS & TRICKS) What are the potential trips/traps in the SCJP exam?

(TIPS & TRICKS) What are the potential trips/traps in the 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 variables.
  • Case statements with values out of permissible range.
  • Math class being an option for immutable classes!!
  • instanceOf is not the 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.
  • RandomAccessFile descends from Object and implements DataInput and DataOutput.
  • Map does not 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 give compiler error.
  • Multi dimensional arrays can be sparse i.e. 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, even though the primitives themselves can be assigned. i.e., ArrayofLongPrimitives = ArrayofIntegerPrimitives gives compiler error even though longvar = intvar is perfectly valid.
  • A constructor can throw any exception.
  • Initializer 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 always result in 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.
  • File class has NO methods to deal with the contents of the file.
  • InputStream and OutputStream are abstract classes, while DataInput and DataOutput are interfaces.

 

No comments:

Post a Comment

Please Leave your valuable comments here. Thanks in Advance.

Disclaimer

Spend time by reading assumes no liability for the accuracy or completeness of any of the information contained on this web site. Furthermore, spend time by reading neither assumes liability for the accuracy or completeness, nor endorses the contents of, any outside links from our web site. This information is provided as a public service for convenience purposes only. Reliance upon the accuracy or completeness of the information contained herein is at the user’s risk. Users are strongly encouraged to make every effort to verify the accuracy and/or completeness of the information before reliance thereon.