Primitive type and Reference type in Java

Kinds of Data Type in Java

Primitive type

  • Java provides 8 kinds of Primitive type.
  • Primitive data types cannot contain null
  • actual value will saved in Stack memory.
data typebase memorydefult valuerange of datarange of data in number
boolean1 bytefalsetrue, falsetrue, false
byte1 byte0-127 ~ 128$-2^{7}$~ $(2^{7}-1)$
short2 byte0-32,768 ~ 32,767$-2^{15}$~ $(2^{15}-1)$
int4 byte0-2,147,483,648 ~ 2,147,483,647$-2^{31}$~ $(2^{31}-1)$
long8 byte0L-9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807$-2^{63}$~ $(2^{63}-1)$
float4 byte0.0F0.000…0034 ~ 3400…000$3.4 \cdot 10^{-38}$ ~ $3.4 \cdot 10^{38}$
double8 byte00.00000000…00017 ~ 17000…000000000$1.7 \cdot 10^{-308}$~$1.7 \cdot 10^{308}$
char2 byte‘\u0000’0~65,535$0$ ~ $(2^{16}-1)$

Reference type

  • If not primitive type, it is Reference type.
  • Reference data types can contain null
  • address will saved in Heap memory.
data typebase memorydefult value
Array4 byteNULL
Enumeration4 byteNULL
Class4 byteNULL
Interface4 byteNULL

 Share!

 
comments powered by Disqus