Thursday, January 9, 2020

Difference Between Primitive data type and Reference data type in Java

Data type in java

 Can be classified as :

1) Primitive
2) Reference Type (Non-Primitive)

Primitive: There are only 8 primitive types of data type
1) byte
2) short
3) int
4) long
5) float
6) double
7) char
8) boolean

Reference: Strings, Array & interfaces.

Difference Between them:
Regarding storing the data.
Example:
------------
int age=35;
Here the variable age store the actual value 35.

String greet="Hello";
Here the reference type does not store the actual data. It stores a reference to the data.
the compiler will not get the value of the data, it tells the compiler where to find the actual data.

The string Hello is created and stored in the computer's memory. The variable greet stores the address of the memory location.