
Java puzzlers
by Joshua Bloch · first published 2005
60% recommend40% neutral
Why HN recommends it
Fun, puzzle-style case studies of Java's corner cases, traps, and surprising behavior (generics, overriding, wrapper types) that build a deep grasp of the language; suits working Java programmers.
Summarised by Claude from recommending comments
Based on Bloch and Gafter's standing room only Java Puzzlers talk at JavaOne, the heart of the book comprises over 100 Java programming language puzzlers: brainteasers that challenge the intellect while alerting programmers to the traps, pitfalls, and corner cases that lurk in the nether regions of the Java platform. All the puzzles from the authors' popular JavaOne presentations are included, as are many puzzles never before seen in public. There are two major types of puzzles in the book. Most of the puzzles take the form of short programs that appear to do something but actually do somethin
Affiliate links. As an Amazon Associate I earn from qualifying purchases.







…understanding of that pattern, however, is that the key is not letting some other object walk off with a reference to your peer, which is exactly what has gone wrong here. (Aside: Josh Bloch's Effective Java & Java Puzzlers are fantastic. They are worth reading for programmers who use any language.)
on “My favorite bug: segfaults in Java” ↗Java Puzzlers[0] has a few entries similar to this. Some of the entries are things that would trip you up (but logically makes sense) rather than oddities, but it's an interesting read. Note that the book is from 2005…
on “Java language oddities” ↗Don't forget Java Puzzlers, also by Bloch: http://www.javapuzzlers.com/ Not only is it a fun read, but it delves very deeply into case studies of the dark corners of the Java language.
on “A few days of programming on iOS and Android illustrates a vast difference.” ↗…4. Bash FAQ As a Unix systems programmer I would choose 1. Mythical Man Month 2. Jon Bentley's Programming Pearls. 3. K&R C and Stroustrup C++ 4. A recent Java reference and Bloch's Java Puzzlers 5. a reference and cookbook for the language of your choice -- Python, Ruby, Perl, etc. 6. Google's style guides
on “Ask HN: What are the books you wish your colleagues had read?” ↗Many more Java language oddities are pointed out in the book "Java Puzzlers". One of its authors is Joshua Bloch, a major contributor to the Java language and libraries. http://www.javapuzzlers.com/
on “Java language oddities” ↗Java Puzzlers by Joshua Bloch and Jeremy Manson are pretty entertaining. For a pretty bog standard language, Java has some more exotic corners: https://www.youtube.com/watch?v=wbp-3BJWsU8
on “Ask HN: What are some of the best technical talks you've heard?” ↗…Concurrency in Practice: http://www.javapuzzlers.com/ Everything else is covered by the excellent online documentation, including the language and VM specification books: http://docs.oracle.com/javase/specs/ Java Puzzlers (http://www.javapuzzlers.com/) is a fun read that highlights many corner cases of the language and might be helpful for code reviews and debugging.
on “Java Leads Programming Language Popularity, by books sold?” ↗Java Puzzlers. It's a fun book that teaches you to really understand the language by making you deal with its corner cases. Highly recommended.
on “Ask HN: Good Java books for aspiring Clojurians?” ↗…--- PROGRAMMING --- Programming Pearls Effective Java The Algorithm Design Manual Advanced Programming in the UNIX Environment The Pragmatic Programmer Refactoring Java Concurrency in Practice Java Puzzlers Expert C Programming --- COOKING --- The Secrets of Cooking Revealed Cooking for Geeks The Bread Baker's Apprentice The Brewmaster's Table --- MISC --- Robot Building for Beginners Mountaineering…
on “Ask HN: Good books?” ↗Java can get into some weird cases with generics, super classes, and overriding. Joshua Bloc has some interesting ones in the fantastic (and horrific!) book, "Java Puzzlers: Traps, Pitfalls, and Corner Cases". For what it's worth, I think python's case is fairly simple and easy to remember. Python objects can define two different methods for operator * : __mul__(self,…
on “Rust Traits Deep Dive, Part 2” ↗My favorite books about languages are the ones that point out where the language is ambiguous or otherwise has surprising, e.g C Traps and Pitfalls and Java Puzzlers: Traps, Pitfalls, and Corner Cases, . It would be great if there were programming languages with no surprises, but I don't think that it's possible. Every language has to compromise on some things in…
on “Darker Corners of Go” ↗Have you got a chance to read "Java Puzzlers: Traps, Pitfalls, and Corner Cases"? Java is a very surprising language with a lot of strange corner cases (a lot of them related to reified generics and wrapper types). There is also a lot of magic…
on “Why Picnic Picked Java” ↗…a value hence it has a type. And that's where things start to be messy. Typing rules for the conditional operator are, well, not trivial and varie from language to language. Let's use an exemple from Java Puzzlers (Joshua Bloch and Neal Gafter) : char x = 'X'; int i = 0; System.out.print(true ? x : 0); System.out.print(false ? i : x); will print X88 but the same thing in C++ char x = 'X'; int…
on “Factor 0.96 now available – over 1,100 commits” ↗…operator precedence, so when you see an expression, you never have to puzzle over how the items are grouped. In simple cases of C expressions, of course, it's easy, but it can get complicated. See "Java Puzzlers" by Josh Bloch and Neal Gafter to see how C/Java-style syntax can get you into trouble and fool you. There are pros and cons to each approach (C/Java and Lisp). I've used all of them extensively, and…
on “The Failure of Lisp? A Reply To Brandon Werner” ↗not only C# books there: Java Puzzlers by Joshua Bloch and Neal Gafter Introduction to Algorithms, 3rd Edition by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein Purely Functional Data Structures by Chris Okasaki
on “A C# Reading List by Eric Lippert” ↗