Data Types in Java

Data Type tells us the size and type of data which can be stored in variable. Two types are

Primitive Data types : Data types such as int, boolean, char, short, long, byte, float, double are known as primitive data types.
Non Primitive Data types : Data types such as Array, class, interface are known as non-primitive data type.

Primitive Data types

byte Data Type
int Data Type
short Data Type
long Data Type
float Data Type
double Data Type
char Data Type
boolean Data Type

byte Data Type

byte data type allows us to store integer value which ranges from -128 to 127.size of byte data type is 1 byte. byte data type default value is 0. byte data type can be used to store integer values instead of int to save memory.
example: byte var = 6

short Data Type

short data type allows us to store integer value which ranges from –32,768 to 32,767.size of short data type is 2 byte. short data type default value is 0.
example: short var = 8

int Data Type

int data type allows us to store integer value which ranges from –2,147,483,648 to 2,147,483,647.size of int data type is 4 byte. int data type default value is 0.
example: int var = 4

long Data Type

long data type allows us to store integer value which ranges from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.size of long data type is 8 byte. long data type default value is 0.
example: long var = 8

float Data Type

float data type allows us to store integer value which ranges from 1.4e–045 to 3.4e+038.size of float data type is 4 byte. float data type default value is 0.0f.f in suffix in necessary becaus by default value like “40.5” i.e. real number is considered as double datatype value.
example: float var = 40.5f

double Data Type

double data type allows us to store integer value which ranges from 4.9e–324 to 1.8e+308.size of double data type is 8 byte. double data type default value is 0.0d.
example: double pi = 3.14

char Data Type

char data type allows us to store 16-bits Unicode character which ranges from 0 to 65,536.size of char data type is 2 byte. char data type default value is ‘u0000’.
example: char var = ‘v’

boolean Data Type

As name says it can save only one of the two possible values those are true and fales. Default value is false
example: boolean var = true

Leave a Comment