Java Variables – A Variable is a container which holds the value while the Java program is
executed . A variable is assigned with a data type. Variable is a name of memory location. There are
three types of variable in java: local, instance, static
Data Type ------------
Data types is defined as a type of data. It specify the different sizes and values that can be stored in
the variable. There are two types of data types in Java:
1. Primitive data types: The primitive data types include boolean, char, byte, short, int, long,
float and double.
2. Non-primitive data types: The non-primitive data types include class, interface and Array
Java Primitive Data Types - In Java language, primitive data types are the building blocks of data
manipulation. These are the most basic data types available in Java Language
Boolean Data Type
The Boolean data type is used to store only two possible values: true and false. This data type is used
for simple flags that track true/false conditions.
Integer Data Type - The int data type is a 32-bit signed two's complement integer. The int data type is
generally used as a default data type for integral values unless if there is no problem about memory.
Int a=10;
Float Data Type
The float data type is a single-precision 32-bit IEEE 754 floating point. Its value range is unlimited. It is
recommended to use a float (instead of double) if you need to save memory in large arrays of floating
point numbers. The float data type should never be used for precise values, such as currency. Its default
value is 0.0F.
Char Data Type - The char data type is a single 16-bit Unicode character.
Char letter = ‘a’;
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