Think you know Java? Really know it? Try the 95 Java puzzles in this book: You just might not know the language as well as you thought. Don’t worry if Java Puzzlers' mini-programs throw you for an occasional loop (or, perhaps, an exception). Each one illustrates some intriguing pitfall, trap, or surprise you really ought to know about. Read them. Think about them. Try them. Then let Joshua Bloch and Neal Gafter unravel them. By the time you’re done, you’ll be writing more robust, resilient, bug-resistant code.
Many of these puzzles are deceptively simple. Why does a method that purports to determine if its sole argument is an odd number fail 25 percent of the time? Why does a program that divides two numbers get the answer 5 when it ought to return 1000? (Lesson: “When working with large numbers, watch out for overflow -- it’s a silent killer.”) Some take you into shrouded areas of Java. For example, one puzzle tests your knowledge of the “question mark colon” conditional operator; you’ll only get it right if you know Java’s arcane rules for determining the result type of a conditional expression. Some are just plain devilishly difficult. For example, in one, the answer can only be found in compiler-generated bytecode.
The authors’ puzzles cover the waterfront: strings, characters, text, loops, iteration, exceptions, try-finally statements, classes, methods, fields, collections, dates, inheritance, overriding, threading, reflection, I/O, nested classes, generics, serialization, binary compatibility, and more. They won’t just stretch your brain: they’ll help you avoid problems you never knew existed. Bill Camarda, from the August 2005 Read Only