Java Data Types
Data types are utilized in Java to categorize the different types of data that may be stored within a variable. There are two categories of datatypes in Java:
- Primitive data type
- Non-Primitive data type
Primitive Data Types
There are 8 primitive data types are available in java.
- bool: Boolean datatype holds one bit of data, either true or false.
- char: char datatype is a single Unicode character that is 16 bits.
- byte: Byte datatype is an 8-bit signed two's complement integer.
- short: Short datatype is a 16-bit signed two's complement integer.
- int: It is a signed two's complement 32-bit integer.
- long: Long data type is a 64-bit signed two's complement integer.
- float: The float data type is a single-precision 32-bit IEEE 754 floating point.
- double:The double data type is a double-precision 64-bit IEEE 754 floating-point.
Data Type | Size | Range |
---|---|---|
bool | 1 bit | true, false |
char | 2 byte | 0 to 255 |
byte | 1 byte | -128 to 127 |
short | 2 byte | -32,768 to 32,767 |
int | 4 byte | -2,147,483,648 to 2,147,483,647 |
long | 8 byte | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
float | 4 byte | upto 7 decimal digits |
double | 8 byte | upto 16 decimal digits |