Primitive types


There are eight primitive types in Java. These are the fundamental "atoms" from which all other types are constructed.

Type What it means Example literals Range Comments
byte An eight-bit integer -5, 0, 5 -128 to 127 Seldom used
short A two-byte integer -5, 0, 5, 200 -32768 to 32767 Seldom used
int A four-byte integer -5, 0, 5, 200, 50000 Negative to positive two billion Typically used for integers
long An eight-byte integer -5L, 0L, 5L, 999999999999L -9 * 1018 to 9*1018 Used only when very large integers are needed
char A single character (usually two bytes)

'a', 'A', '5', '+', ' ', '\n', '\'', '\\'

Most of the world's characters, including Chinese, Arabic, etc. Can be treated as integers; some characters cannot be typed as single characters
float A four-byte decimal number 5.23F, -123.45678F 1.4*10-45 to 3.4*1038 Seldom used
double An eight-byte decimal number 5.23, -123.45678 4.9*10-324 to 1.8*10308 Typically used for decimal ("floating point") numbers
boolean A logical value (one byte long) true, false Only the two values true and false Used mostly for remembering the results of tests

In addition, Java defines literally thousands of object types (which you can explore at, and every program you write has additional programmer-defined object types of its own.


Any primitive type (except boolean) can be cast to any other primitive type (except boolean).