Quick notes for SCJP
Topics covered
Methods
- Over ridden methods should not have more restrictive accessibility
- Over ridden methods can only throw the same or sub classes of the exceptions thrown by the super class method
- Private methods in the super class are not visible to the sub class, hence are not over ridden by the sub class
- Event static methods can't declare static variables within it's scope
- Interface methods are by default public, even if no access modifier is mentioned. While implementing them in class the access modifiers should be public
- static methods can only be overriden by static methods
- non-static methods can only be overriden by non-static methods
- Method is invoked on the object created by the new method, not by the reference type
- Exceptions thrown by methods must be caught, while invoking them
- If methods are overriden then the most appropriate method is called at runtime
- Abstract methods can't be native OR private
Back
Classes
- Static initializer of the class with main method
- Static initializer of the super class
- Static initializer of the sub class
- Instance initializer of the super class
- Constructor of super class
- Instance initializer of the
- Constructort of sub class
- 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.
- 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
- 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
- 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
- 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
- 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
- The order of floating/double values is -Infinity --> Negative Numbers/Fractions --> -0.0 --> +0.0 --> Positive Numbers/Fractions --> Infinity
- Octal takes values from 0-7 & Hexadecimal takes values from 0-9 & a-f
- 10/0 results in Java.lang.ArithmeticException
- 4.0/0.0 results in INF (floating point divided by zero)
- -4.0/0.0 results in -INF (floating point divided by zero)
- 0.0/0.0 results in NAN
- Math.sqrt(-2) results in NAN , however Math.sqrt(-0) == 0
- -0==0
Back
Modifiers
- If blank final instance member variable is not initialized it must be assigned a value in the initializer or in every constructor
- 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
- 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
- wait() and Thread.yield() don't cause a thred to stop , they cause the thread to go to non-runnable state
- wait() , notify() , notifyAll() are defined in the object class
- wait() , notify() , notifyAll() throw java.lang.IllegalMonitorState Exception at runtime , no error at compile time is thrown
Back
Operators
- ' >> ' , ' >>> ' & ' << ' don't take float and double as arguments , and the result has the promoted type of the left hand argument
- ' ~ & | ^ ' the binary bitwise operators don't take float and double as arguments
- Explicit narrowing conversion is performed for postfix and prefix operators
- The simple way to calculate ~i where i an integral type is ~i = (-i) -1
Back
Others
- If any statement is unreachable by any reason, then there is a compile time error
- Where a class is inherited you have to ask if it represents the " is-a " relationship
- 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
- set(i,Object) will cause runtime error , if size of the vector is larger than i
- Vector v=new Vector(5) will have capacity 5 , but the size will be zero
- If more space if made available BorderLayout allocates the space as North South , East , West , Center
- If more space if made available GridLayout allocates the space equally among the components
- 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
- If more space if made available GridBagLayout allocates the space equally among the components
- Constructors can't be native , abstract , synchronized , static or final
- -1 * Double.NEGATIVE_INFINITY results in INFINITY
Back