Will Java's int
always and everywhere be a 32 bit signed integer?
views:
492answers:
3
+28
A:
Yes, it's defined in The Java Language Specification.
From Section 4.2: Primitive Types and Values:
The integral types are
byte
,short
,int
, andlong
, whose values are 8-bit, 16-bit, 32-bit and 64-bit signed two's-complement integers, respectively, andchar
, whose values are 16-bit unsigned integers representing UTF-16 code units (§3.1).
And additionally from Section 4.2.1: Integral Types and Values:
The values of the integral types are integers in the following ranges:
- For byte, from -128 to 127, inclusive
- For short, from -32768 to 32767, inclusive
- For int, from -2147483648 to 2147483647, inclusive
- For long, from -9223372036854775808 to 9223372036854775807, inclusive
- For char, from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535
coobird
2009-06-23 14:41:17
Beat me to it ;)
laginimaineb
2009-06-23 14:42:49
Excellent info :-)
joe
2009-06-23 14:44:24