J2EEOnline J2EEOnline


Java Fundamentals  «Prev 

Java Initializer Program for initializing primitives, String, and Object

Initializer program

The Initializer program illustrates the use of automatic initialization.
It declares field variables of every primitive type, the String type, and object types.
It also declares a local array and then displays the values of these variables.

The Initializer program

class Initializer {
boolean bo;
byte by;
char c;
short s;
int i;
long l;
float f;
double d;
String str;
Object obj;

void run() {
short[] sh = new short[2];
System.out.println("boolean: "+bo);
System.out.println("byte: "+by);
System.out.println("char: "+c);
System.out.println("short: "+s);
System.out.println("int: "+i);
System.out.println("long: "+l);
System.out.println("float: "+f);
System.out.println("double: "+d);
System.out.println("String: "+str);
System.out.println("Object: "+obj);
System.out.println("sh[0]: "+sh[0]);
System.out.println("sh[1]: "+sh[1]);
}
public static  void  main(String[] args) {
Initializer app = new Initializer();
app.run();
}
}

Output of the above Java Program.
boolean: false
byte: 0
char: 
short: 0
int: 0
long: 0
float: 0.0
double: 0.0
String: null
Object: null
sh[0]: 0
sh[1]: 0