Quick notes for SCJP

Topics covered

Methods
Classes
Loop
Primitive
Modifiers
Thread
Operators
Others

Methods

  1. Over ridden methods should not have more restrictive accessibility
  2. Over ridden methods can only throw the same or sub classes of the exceptions thrown by the super class method
  3. Private methods in the super class are not visible to the sub class, hence are not over ridden by the sub class
  4. Event static methods can't declare static variables within it's scope
  5. Interface methods are by default public, even if no access modifier is mentioned. While implementing them in class the access modifiers should be public
  6. static methods can only be overriden by static methods
  7. non-static methods can only be overriden by non-static methods
  8. Method is invoked on the object created by the new method, not by the reference type
  9. Exceptions thrown by methods must be caught, while invoking them
  10. If methods are overriden then the most appropriate method is called at runtime
  11. Abstract methods can't be native OR private
Back

Classes

  1. Static initializer of the class with main method
  2. Static initializer of the super class
  3. Static initializer of the sub class
  4. Instance initializer of the super class
  5. Constructor of super class
  6. Instance initializer of the
  7. Constructort of sub class
  8. A class generates ' .class ' files of inner classes when compiled , such as OuterClass$InnerClass.class. Anonymous class are compiled as OuterClass$1.class - OuterClass$2.class - OuterClass$3.class . . . etc.
  9. Most of the classes declared in java.lang package such as String, StringBuffer and the wrapper classes are final and hence can't be sub-classes
Back

Loop

  1. If a statement in a loop is not reachable , then there is a compile time error e.g. :- - - - - - - - while(false) { retrun 9 } - is never reached , so there is a compile time error
  2. for(int i=0;i<5;i=i++) is an infinite loop, since i is being incremented after assigining its previous value to itself
Back

Primitive

  1. char can be defined as - '\udddd' where dddd are hexadecimal, . . . but '\u000d' & '\u000a' are not allowed as they are carrige return and line feed respectively
  2. Constant int can be assigned to char, byte and short if it is in range. i.e. final int i=2; char c=i; is valid. But int j=4; final int i=j; char c=i; is not valid since i is not detreminable as j can change
  3. The order of floating/double values is -Infinity --> Negative Numbers/Fractions --> -0.0 --> +0.0 --> Positive Numbers/Fractions --> Infinity
  4. Octal takes values from 0-7 & Hexadecimal takes values from 0-9 & a-f
  5. 10/0 results in Java.lang.ArithmeticException
  6. 4.0/0.0 results in INF (floating point divided by zero)
  7. -4.0/0.0 results in -INF (floating point divided by zero)
  8. 0.0/0.0 results in NAN
  9. Math.sqrt(-2) results in NAN , however Math.sqrt(-0) == 0
  10. -0==0
Back

Modifiers

  1. If blank final instance member variable is not initialized it must be assigned a value in the initializer or in every constructor
  2. Blank final static member variable must be initialized , it can't be done in the constructors since its static, else there will be compile time error. It can be given a value in a static initializer
  3. static inner classes and static methods of inner classes can't have Outerclass.this.variable since they can only access static members , and Outerclass.this.variable refers both static and instance members
Back

Threads

  1. wait() and Thread.yield() don't cause a thred to stop , they cause the thread to go to non-runnable state
  2. wait() , notify() , notifyAll() are defined in the object class
  3. wait() , notify() , notifyAll() throw java.lang.IllegalMonitorState Exception at runtime , no error at compile time is thrown
Back

Operators

  1. ' >> ' , ' >>> ' & ' << ' don't take float and double as arguments , and the result has the promoted type of the left hand argument
  2. ' ~ & | ^ ' the binary bitwise operators don't take float and double as arguments
  3. Explicit narrowing conversion is performed for postfix and prefix operators
  4. The simple way to calculate ~i where i an integral type is ~i = (-i) -1
Back

Others

  1. If any statement is unreachable by any reason, then there is a compile time error
  2. Where a class is inherited you have to ask if it represents the " is-a " relationship
  3. java.lang.InterrutpedException & java.io.IOException is never declared in try and catch block if there isn't any situtation which might cause the exception. However the same does not apply for throws statement
  4. set(i,Object) will cause runtime error , if size of the vector is larger than i
  5. Vector v=new Vector(5) will have capacity 5 , but the size will be zero
  6. If more space if made available BorderLayout allocates the space as North South , East , West , Center
  7. If more space if made available GridLayout allocates the space equally among the components
  8. If more space if made available FlowLayout allocates the space to components in the order they are added to the container , without compromising the size of the components
  9. If more space if made available GridBagLayout allocates the space equally among the components
  10. Constructors can't be native , abstract , synchronized , static or final
  11. -1 * Double.NEGATIVE_INFINITY results in INFINITY
Back