Tuesday, September 6, 2011

Default Values of primitive data type in java


Variable Type          Default Value
Object reference        :null (not referencing any object)
byte, short, int, long   :   0
float, double              :  0.0
boolean                    :  false
char                          : '\u0000'

Monday, August 22, 2011

Hello world without main method in java!!!!!


class WithOutMainMethod{
static {
System.out.println("Hello world!");
System.exit(0);
}
}


*static block executed once by JVM when class loaded.
*System.exit(0) it say jvm to exit .
*If you are not giving System.exit(0) ,Hello World will print and give some Execption like
   Exception in thread "main" java.lang.NoSuchMethodError: main.