1) does a * b get evaluated first? Is Left to Right always the case with evaluation? Order of evaluation is described in detail in the
JLS (�15.7) For multiplication division, yes, it is from left to right.
2) a * b results in 2895729615. Which I know is larger than the integer range but how does Java arrive at -1399237681. If you are running under Windows, pull up the Calculator and set the view to Scientific. Select the "Dec" radio button, then type in 2895729615. Now select the "Bin" radio button. You will see the binary equivalent, which is (spaces added for readability):
1010 1100 1001 1001 0101 0011 1100 1111
The leftmost bit is the sign bit. 0 in the sign bit indicates a positive number, 1 indicates a negative number. That makes the binary representation above a negative number. To find out what the magnitude of that number is, you need to calculate its two's complement:
To get the two's complement of
1010 1100 1001 1001 0101 0011 1100 1111
invert all the bits (if you still have Calculator up, click on the "Not" button)
0101 0011 0110 0110 1010 1100 0011 0000
then add 1, which will give you
0101 0011 0110 0110 1010 1100 0011 0001
Now, select the "Dec" radio button and
you should see
1399237681
That is the magnitude of the negative number represented by the original: 1010 1100 1001 1001 0101 0011 1100 1111
[This message has been edited by JUNILU LACAR (edited June 21, 2001).]