The eight primitive data types in Java are byte, short , int , long , float , double , char and boolean.
data_type variable_name = initial_value;
The purpose of initializing a variable in Java is to assign it an initial value so that it can be safely used in program . By initializing a variable, it prevents runtime exceptions , avoid compilation errors and enhance safety & security.
data_type variable_name;
data_type variable_name;
In Java primitive data type store the actual value directly , while reference data type store a memory address that points to where the actual data is located .The size of the primitive variable is fixed whereas the size of reference variable is dynamic
Variables in Java are used to allocate specific amount of memory for the data and to inform the compiler about the type of data that will be stored.
The two main categories of data types in java are primitive data type and reference data type.
‘int’ is used for storing integer values. float is a single -precision floating -point data type, and double is a double-precision floating-point data type .The size of the ‘int’ data type is 4 bytes(32-bit), the size of the ‘double’ data type is 8 bytes( 64 -bit) and the size of the ‘float’ data type is 4 bytes(32-bit).
The default value of boolean variable in Java is ‘false’.
Data type in java defines the type and size of data a variable can store.
