Data types in Java are splitted into two general categories: primitive and reference.
These types of data are essentially intended to store numbers. They are further divided into following three subcategories:
Integral for integer numbers, or numbers without a decimal part.
Data type | Range | Size |
---|---|---|
byte | -128 . . 127 | 1 byte |
char | 0 . . 65,535 | 2 bytes |
short | -32,768 . . 32,767 | 2 bytes |
int | -2,147,483,648 . . 2,147,483,647 | 4 bytes |
long | -922,337,203,684,547,758,808 . . 922,337,203,684,547,758,807 | 8 bytes |
Floating-point for decimal numbers. In Java floating-point notation the letter E is for the decimal exponent (power of 10). For example, 2.65·10-5 in Java notation becomes 2.65E-5.
Data type | Range | Size |
---|---|---|
float | -3.4E+38 . . 3.4E+38 | 4 bytes |
double | -1.7E+308 . . 1.7E+308 | 8 bytes |
Boolean for logical values that can take on only two values: true and false.
Data type | Range | Size |
---|---|---|
boolean | true or false | 1 bit |
These data types are designed for objects. When Java assigns an object to a variable, it copies the memory address of that object into the variable. The objects can be of the following three types:
array
class
interface