Data Type In Java with Explanations

Data Type In Java with Explanations

The data type of a variable refers to the type of data the variable can have or store. The operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables.

The data type means to the type of data that can be stored into a variable. Java is known as a strongly typed language because when programmer declare a variable, it must specify the type of a variable. After that the compiler ensures that you or programmer don not try to assign the data of the wrong type to the variable.

See the following example It generates a compiler time error:

int a;
a= 2.14125;

Because a is declared as a variable of type int (int is use to hold integer value), and we assign float number to it.

The Correct declaration for above value should be like this :

float a;
a= 2.14125;

Types Of Data Type In Java

In Java , data type is divided into two types that is :
1 ) Primitive types and
2 ) Non-Primitive types.

Primitive Datatypes are the type of data that defined by the language itself or that is predefined in programming language.
On the other side, non- primitive or reference types are types defined by classes in the Java application programming libraries, interface or by classes and API that user create rather than by the language itself.

List Of Data Type

Data TypeSize of Data type(In Bytes)Default Value
boolean1false
char2‘\u0000’
byte10
short20
int40
long80L
float40.0f
double80.0d