Hahahaha skoob you are quite the humorist. Skoob, if you're serious, learn a little more about OOP and encapsulation here:

http://en.wikipedia.org/wiki/Object-...ed_programming ... but I hope you're simply practicing polymorphism in real life -- are you a forum member, or a troll? Both! :)

Rooster Cogburn, you're correct that an int has 4 bytes. Each of these bytes has its own address. Each of these addresses is in sequential order. E.g. if the first byte is at memory address 500000, the second would be at 500001, etc. Because the compiler knows you're dealing with an int, it knows that it should look at bytes 500000 through 500003 when doing numeric operations on your variable. Fortunately, modern compilers know how to deal with 32-bit numbers natively, so math operations on numbers of this size are actually quite performant and don't require a trip up to the JVM for processing.

As for the range of integer values, how are binary numbers counted? You probably know this already: 1, 10, 11, 100, 101, 110, 111, 1000, etc. Do you see a pattern? First the least significant bit (LSB) is toggled. If its previous value was 1, then the operation carries over to the next significant bit. So in the case of 11, we toggle the LSB to get 10. But since the first bit was initially 1, we go to alter the second bit. Then we get 00, but since the second bit was initially 1, we go to the third bit. We toggle it to 1, to get 100, and since it was initially 0 we stop.

Given this algorithm, how do we subtract? I'll leave that for you to ponder the exact algorithm. So consider subtracting 1 from 0. What do you get? All ones. You get enough ones to fill up however large your number is -- in the case of ints, you get 32 ones. How processors and compilers tell the difference between negative and positive numbers is by looking at the most significant bit (MSB). If MSB=1, the number is negative, otherwise, it's positive. Given this design, the lowest number you can represent is all ones and the highest number has MSB=0, but the rest all ones. Given how binary counting works, if you have 8 bits, the smallest number you can represent is -128 and the biggest number is 127.

The double type is actually more complicated than what you're thinking. A double does not work the same as integers. Instead, it has one bit dedicated to positive/negative, a set of bits dedicated to what the number is without a decimal point, and another set of bits dedicated to where the decimal point goes.

Jon Emerson

http://www.jonemerson.net/