Thursday, April 3, 2008


1. Evaluation and execution –remember that evaluation is from left to right but
execution is from right to left.

2. There must be some statement after do keyword in do – while loop for it to
compile without error.
do ; while(false); //correct
do {;}while(false); //correct
do {}while(false); //correct
do while(false); //error

3. If “t” is a reference variable then ,
t.equals(null) is
(null).equals(t) compiler error
let’s say t2 is some other reference variable then
false and not error
t = null;
t.equals(t2); //not compiler error but runtime error

4. If a class is declared inside a package with public modifier then that class
becomes invisible to all other classes in other packages unless they import the
package or use extended form of addressing the class.

5. The Iterator method of collection interface when invoked returns an instance of
Iterator class.

6. given,
char c = ‘a’;
int i = 1;
c + =i; //correct
c = c+ i; //illegal

7. when use int numbers in basic arithmetic operation then the output is an integer
number. Hence ,
int i = 4/3;
“i” will have the value 1.

8. Native methods can be set to any access level - public , protected, private, default.

9. The methods in the immediate super class in the inheritance tree may be accessed
through the use of keyword “super” , but classes above the immediate super class
are not visible.

Valid comments
· /* this is a comment */
· /** this is a comment */
· /*this is a comment **/
· // /** this is a comment */ */
· /* //this is a comment */
11. invalid comments
· /** this is a comment */ */

12. If a method declares some exception in throws clause and the subclass of the
given class while overriding the method declares some new exception then before
assuming that it causes compiler error first check whether the new exception
thrown in the subclass’ method is unchecked exception or not.

13. After solving the logic inside the problem before jumping to conclusion check
whether some code is unreachable or not. Because if it happens so then it results
in compiler error.

14. The following form of instantiating a static inner class results in compiler error,
new ().new ();

15. long l = Integer.MAX_VALUE;
float f = l;
double d = l;
then “d==f” is false due to rounding of numbers in float literal.
But when we assign l to Long.MAX_VALUE or to Integer.MIN_VALUE then
we get the result of “d==f” as true.

16. We can place label statements around a block of code wherever we wish , unless
the name used is not a keyword and follows all the rules meant for identifier.
For eg.
…..some complex code….
…..some complex code….
break labelA;
this way we place break statement with label in any labeled block of code
which may break out of the code if something comes true.
Furthur the same labels can be used for other block of code as long as they
don’t overlap.

17. An abstract method cannot be marked as both
· Abstract and strictfp
· Abstract and native
· Abstract and synchronized
· Abstract and final
· Abstract and private
· Abstract and static

18. Shift operators can be used only on integers .

19. Switch statements can evaluate byte , short, char , int.
but not long, float.double.
i.e. long l = 10;
switch(l){}//causes compiler error
before jumping to conclusion about switch statements , verify whether
the case arguments are lying within the range of the switch argument.
For e.g. byte b = 10;
case 10: …….. complexcode………break;
case 1000: …….. complexcode………break;
here second case statement causes compiler error since it is out of range of
byte literal.

20. The case argument must be primitive literal type or final variable.

21. For loop declarations,
· for(int i=0,j=0;i<10;i++);invalid
· for(i=0,int j=0;;);
· int k =1;
for(int i=0,k=0;;);

Search Amazon for Best Books on Java J2EE


blogarama - the blog directory

Search your favourite topics