Java-Tutorials-4-Java Variables

Java Variables:

Java is a strongly typed programming language. This means that every variable must have a data type associated with it. For example, a variable could be declared to use one of the eight primitive data types: byte, short, int, long, float, double, char or boolean.

Data Type Default Value Default size
boolean false 1 bit
char ‘\u0000’ 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte

 

Why do we use static keyword in Java?
The static keyword in Java means that the variable or function is shared between all instances of that class as it belongs to the type, not the actual objects themselves. So if you have a variable: private static int i = 0; and you increment it ( i++ ) in one instance, the change will be reflected in all instances.
Relevant Code: