Java Data Types

Data Types — Integer Data Types

Java's basic data types are almost identical to C/C++ data types. The main difference is that Java's types all have a set size regardless of platform, while C/C++'s data types only have a minimum number of bits, which causes some variation between platforms. It also has the same two categories; Integer and Floating Point.

Integer types:

Name Size Range Notes
boolean 1 true or false like C++'s bool, but it can't be assigned with a number
char 16 0 to 65535 This is bigger than C's char. This is because Java strings are Unicode, not ASCII. It's also unsigned by default.
byte 8 -128 to 127 Standard issue 'byte'
short 16 -32768 to 32767 just like a char, but signed by default
int 32 -2147483648 to 2147483647 standard-issue integer number type
long 64 -9223372036854775808 to 9223372036854775807 For very huge integers

Floating Point types:

Name Size Range Notes
float 32 +/- 1.4023x10-45 to 3.4028x10+38 general purpose real-number
double 64 +/- 4.9406x10-324 to 1.7977x10308 higher-precision real number

All data types in Java are always signed (except for boolean, of course). Also note that long is guaranteed to be 64 bits long.

Styles: Default · Green · Sianse