Thursday, 13 September 2012

Variables in JAVA


Variables are identifiers associated with values. They are declared by writing the variable's type and name, and are optionally initialized in the same statement by assigning a value.
int myInt;         /* Declaring an uninitialized variable called 'myInt',
                   of type 'int' */
myInt = 35;       // Initializing the variable
int myInt = 35;   // Declaring and initializing the variable at the same time
Multiple variables of the same type can be declared and initialized in one statement using comma as a delimiter.
int a, b;         // Declaring multiple variable of the same type
 
int a = 2, b = 3; // Declaring and initializing multiple variables of the same type