This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
because the max positive integer is not 2147483648 but 2147483647 because the 0 is also considered a positive int. so if you have an int of 2147483648, it is out of range. The couter of int goes: 2147483646 2147483647 -2147483648 -2147483647
For integer values, negation is the same as subtraction from zero. The Java programming language uses two's-complement representation for integers, and the range of two's-complement values is not symmetric, so negation of the maximum negative int or long results in that same maximum negative number. Overflow occurs in this case, but no exception is thrown. For all integer values x, -x equals (~x)+1.
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James