What is primitive Type in Java ?

There are some types which we use very frequently in Java programs known as primitive type and these types get special treatment. As to create any variable we need to make instance of a type using new keyword which creates an object in heap which is not efficient in cases of very frequent uses.

In cases of primitive type we don’t need to use new keyword to make variable, it automatically creates a variable which has not reference and stored on stack and holds value of that variable that is why it is more efficient.

Java determines the size of each primitive type. These sizes don’t change from one machine architecture to another. This means size of primitive type is same on all type of machine.

Here is list of java primitive types

Type

Contains

Default

Size

Range

Wrapper

boolean

true or false

false

Not defined, represent 1 bit information

NA

Boolean

char

Unicode character
unsigned

u0000

16 bits or
2 bytes

0 to 216-1 or
u0000 to uFFFF

Character

byte

Signed integer

0

8 bit or
1 byte

-27 to 27-1 or
-128 to 127

Byte

short

Signed integer

0

16 bit or
2 bytes

-215 to 215-1 or
-32768 to 32767

Short

int

Signed integer

0

32 bit or
4 bytes

-231 to 231-1 or
-2147483648 to 2147483647

Integer

long

Signed integer

0

64 bit or
8 bytes

-263 to 263-1 or
-9223372036854775808 to
9223372036854775807

Long

float

IEEE 754 floating point
single-precision

0.0f

32 bit or
4 bytes

?1.4E-45 to
?3.4028235E+38

Float

double

IEEE 754 floating point
double-precision

0.0

64 bit or
8 bytes

?439E-324 to
?1.7976931348623157E+308

Double

All numeric types are signed. The size of the boolean type is not explicitly specified; it is only defined to be able to take the literal values true or false.

There are wrapper classes for the primitive data types allow you to make a nonprimitive object on the heap to represent that primitive type. For example:

char c = \'x\';
Character C = new Character(c);
Or you could also use:
Character C = new Character(\'x\');