A data type in Java represents the size and different values that can be stored in a variable. A Java data type is a set of values and operations defined on those values.
There are two types of data types in Java
- Non-primitive data types
- Primitive data types
1. Non-primitive data types :
Non-primitive data types are as belows
- Arrays
- Classes
2. Primitive data types :
Primitive data types are as belows
- byte
- short
- int
- long
- float
- double
- boolean
- char
Data Type | Size | Stores Value |
byte | 1 byte | from -128 to 127 |
short | 2 bytes | -32,768 to 32,767 |
int | 4 bytes | -2,147,483,648 to 2,147,483,647 |
long | 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
float | 4 bytes | 6 to 7 decimal digits |
double | 8 bytes | 15 decimal digits |
boolean | 1 bit | true or false values |
char | 2 bytes | single character/letter or ASCII values |
Syntax :
data type variable [ = value][, variable [ = value] ...] ;
Comments