...
- For byte, from â“128 to 127, inclusive
- For short, from â“32,768 to 32,767, inclusive
- For int, from â“2,147,483,648 to 2,147,483,647, inclusive
- For long, from â“9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, inclusive
- For char, from
\u0000
to\uffff
inclusive, that is, from 0 to 65,535
...
A related pitfall is the use of the Math.abs()
method that takes a parameter of type int
and returns its absolute value. Because of the asymmetry between the two's complement representation of negative and positive integer values (Integer.MAX_VALUE
is 2147483647 2,147,483,647 and Integer.MIN_VALUE
is -2,147,483,648, which means there is one more negative integer than positive integers), there is no equivalent positive value (+2,147,483,648) for Integer.MIN_VALUE
. ConsequenlyConsequently, the Math.abs()
returns Integer.MIN_VALUE
when the value of its argument is Integer.MIN_VALUE
; this may surprise many programmers.
...