Appendix B. The Top Ten Topics that almost made it into the Real Book...

image with no caption

We covered a lot of ground, and you’re almost finished with this book. We’ll miss you, but before we let you go, we wouldn’t feel right about sending you out into JavaLand without a little more preparation. We can’t possibly fit everything you’ll need to know into this relatively small appendix. Actually, we did originally include everything you need to know about Java (not already covered by the other chapters), by reducing the type point size to .00003. It all fit, but nobody could read it. So, we threw most of it away, but kept the best bits for this Top Ten appendix.

This really is the end of the book. Except for the index (a must-read!).

#10 Bit Manipulation

Why do you care?

We’ve talked about the fact that there are 8 bits in a byte, 16 bits in a short, and so on. You might have occasion to turn individual bits on or off. For instance you might find yourself writing code for your new Java enabled toaster, and realize that due to severe memory limitations, certain toaster settings are controlled at the bit level. For easier reading, we’re showing only the last 8 bits in the comments rather than the full 32 for an int).

Bitwise NOT Operator: ~

This operator ‘flips all the bits’ of a primitive.

int x = 10;   //     bits are 00001010

x = ~x;        // bits are now 11110101

The next three operators compare two primitives on a bit ...

Get Head First Java, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.