What do you think?


Java Puzzlers: Traps, Pitfalls, and Corner Cases
"Every programming language has its quirks. This lively book reveals oddities of the Java programming language through entertaining and thought-provoking programming puzzles." --Guy Steele, Sun Fellow and coauthor of The Java™ Language Specification "I laughed, I cried, I threw up (my hands in admiration)." --Tim Peierls, president, Prior Artisans LLC, and member of the JSR 166 Expert Group How well do you really know Java? Are you a code sleuth? Have you ever spent days chasing a bug caused by a trap or pitfall in Java or its libraries? Do you like brainteasers? Then this is the book for you! In the tradition of Effective Java™ , Bloch and Gafter dive deep into the subtleties of the Java programming language and its core libraries. Illustrated with visually stunning optical illusions, Java™ Puzzlers features 95 diabolical puzzles that educate and entertain. Anyone with a working knowledge of Java will understand the puzzles, but even the most seasoned veteran will find them challenging. Most of the puzzles take the form of a short program whose behavior isn't what it seems. Can you figure out what it does? Puzzles are grouped loosely according to the features they use, and detailed solutions follow each puzzle. The solutions go well beyond a simple explanation of the program's behavior--they show you how to avoid the underlying traps and pitfalls for good. A handy catalog of traps and pitfalls at the back of the book provides a concise taxonomy for future reference. Solve these puzzles and you'll never again fall prey to the counterintuitive or obscure behaviors that can fool even the most experienced programmers.
312 pages, Paperback
First published June 24, 2005
About the author
Joshua Bloch
9 books145 followersThere is more than one Joshua Bloch in the GR database. This is Joshua^Bloch, author of computing books.
Ratings & Reviews
Friends & Following
Create a free account to discover what your friends think of this book!
Community Reviews
Displaying 1 - 25 of 25 reviews
May 19, 2009
If you program in Java, you _must_ read this book. It is a real eye-opener to the kind of traps in your code you wouldn't even imagine could be there.
I can guarantee you have written at least one of these issues into your code. And QA never caught it. And it is out in the wild RIGHT NOW. Arrgh!!
More at http://tardate.blogspot.com/2009/06/j...
I can guarantee you have written at least one of these issues into your code. And QA never caught it. And it is out in the wild RIGHT NOW. Arrgh!!
More at http://tardate.blogspot.com/2009/06/j...
January 27, 2011
If you are a Java-Guru this might be fun to read. I found a lot of the puzzles more annoying than educational (especially the problems regarding unicode). In general, I found the puzzles to be overly esoteric. If you want to learn something about Java, pick one of Joshua Bloch's other (excellent!) books.
May 14, 2014
Do not read this book if:
- you're looking to learn about the fundamentals of algorithm design and analysis.
Do read this book if:
- you'd like to know more about Java, the JVM, the intricacies of OOP, or the history of some cool visual illusions.
- you're looking to learn about the fundamentals of algorithm design and analysis.
Do read this book if:
- you'd like to know more about Java, the JVM, the intricacies of OOP, or the history of some cool visual illusions.
April 24, 2013
This book is more like a brain teaser than real computer book. Some of the tips are useful but it's more fun to read this book than functional from my point of view.
This entire review has been hidden because of spoilers.
April 12, 2008
This books has a lot of good puzzles designed to make you think about how Java works.
October 9, 2020
Although the puzzles are rather contrived, they will teach you about the deep internals of the JVM.
June 9, 2021
great book with tricky tasks in Java. Every task has great explanation to understand what's happening and why
April 21, 2026
Unless you are a Java language designer, prepare to be have your world rocked!
January 31, 2015
Full review also on my blog: http://codependentcodr.blogspot.ca/20...
Java Puzzlers is not so much a book, but a collection of obscure corner cases in the Java programming language. The author (Joshua Bloch) is well known as the author of "Effective Java" which is widely regarded as the premier text for the language, and furthermore he is one the designers and authors of the Java Collections Framework. So to say the least, he knows his stuff.
Each chapter of the book features a collection of "puzzlers" centered around a particular section of the language (examples include loops, strings, exceptions, classes, etc). Each "puzzler" is formulated where a puzzle (typically in the form of a code snippet) is given, and the reader is encouraged to try and predict what the output will be, or why the code is incorrect. Then an answer/explanation of the puzzler is given. All-in-all there are 95 different puzzlers across the book, and they range from the fairly common "if you thought about it a bit you'd figure it out" to the extremely obscure "unless you were a Java language designer you'd never have any hope of figuring this out". The explanations also often include commentary to language designers (ex: "the lesson for language designers here is...").
From an academic "curiosity" point of view the book is quite intriguing. As a fairly experienced Java developer I found myself surprised with the vast majority of the puzzlers. The programming languages guy in me found this fascinating (ex: wait, so you can have Unicode literals in comments, and those literals are interpreted by the compiler?).
Having said that, the book does reach a point where the puzzles and concepts hit upon by the puzzles are extremely obscure. For a typical Java developer you'll almost never run into most of the tidbits in this book. That's not to say that reading it isn't useful, you'll definitely learn a bit about the book, but if you're looking to learn "how to write good Java code" this is not the book for you (again, see Bloch's other book for that).
Java Puzzlers is not so much a book, but a collection of obscure corner cases in the Java programming language. The author (Joshua Bloch) is well known as the author of "Effective Java" which is widely regarded as the premier text for the language, and furthermore he is one the designers and authors of the Java Collections Framework. So to say the least, he knows his stuff.
Each chapter of the book features a collection of "puzzlers" centered around a particular section of the language (examples include loops, strings, exceptions, classes, etc). Each "puzzler" is formulated where a puzzle (typically in the form of a code snippet) is given, and the reader is encouraged to try and predict what the output will be, or why the code is incorrect. Then an answer/explanation of the puzzler is given. All-in-all there are 95 different puzzlers across the book, and they range from the fairly common "if you thought about it a bit you'd figure it out" to the extremely obscure "unless you were a Java language designer you'd never have any hope of figuring this out". The explanations also often include commentary to language designers (ex: "the lesson for language designers here is...").
From an academic "curiosity" point of view the book is quite intriguing. As a fairly experienced Java developer I found myself surprised with the vast majority of the puzzlers. The programming languages guy in me found this fascinating (ex: wait, so you can have Unicode literals in comments, and those literals are interpreted by the compiler?).
Having said that, the book does reach a point where the puzzles and concepts hit upon by the puzzles are extremely obscure. For a typical Java developer you'll almost never run into most of the tidbits in this book. That's not to say that reading it isn't useful, you'll definitely learn a bit about the book, but if you're looking to learn "how to write good Java code" this is not the book for you (again, see Bloch's other book for that).
April 3, 2021
This book may be read in different ways:
1. As what it essentially is: a collection of puzzlers, i.e. corner cases and obscure points of the Java Language Specification. It contains problems that would trip any Java senior developer, and for the most part they teach something. In this sense, it is a kind of companion to Effective Java (it gives some recommendations about what not use from the Java libraries and what to use instead, as well as practices to avoid).
2. As recommendations for API developers, which are sprinkled throughout the text (not many, but worthy). All the more valuable given Joshua Bloch's history and success with APIs.
3. As recommendations for language designers, which also come mixed with the "moral" of each puzzler.
If any of these three things sounds interesting to the reader, then the book will be worth reading. In my case, I'm giving it 5 stars because I consider the 3 of them worthwhile, and one has to admire the work put into each puzzler by Bloch and Gafter, quoting the relevant sections of the JLS and explaining them in simple terms in each of the solutions.
1. As what it essentially is: a collection of puzzlers, i.e. corner cases and obscure points of the Java Language Specification. It contains problems that would trip any Java senior developer, and for the most part they teach something. In this sense, it is a kind of companion to Effective Java (it gives some recommendations about what not use from the Java libraries and what to use instead, as well as practices to avoid).
2. As recommendations for API developers, which are sprinkled throughout the text (not many, but worthy). All the more valuable given Joshua Bloch's history and success with APIs.
3. As recommendations for language designers, which also come mixed with the "moral" of each puzzler.
If any of these three things sounds interesting to the reader, then the book will be worth reading. In my case, I'm giving it 5 stars because I consider the 3 of them worthwhile, and one has to admire the work put into each puzzler by Bloch and Gafter, quoting the relevant sections of the JLS and explaining them in simple terms in each of the solutions.
October 14, 2010
You wont find here good job interview questions , and you wont learn practical things about Java.
Most of the puzzles here are about cases you will probably never encounter. But it is a fun read that will show you that there are many things you don't know about Java .
Also, this book can make you more perceptive about details in code you usually don't notice.
Most of the puzzles here are about cases you will probably never encounter. But it is a fun read that will show you that there are many things you don't know about Java .
Also, this book can make you more perceptive about details in code you usually don't notice.
March 7, 2013
I had no idea about all the things that I didn't know :)
Java is a complicated language and after reading this book you'll think so too. I have also read Joshua Bloch's Effective Java and it's a good companion book for this one; they're book very good and worth the a read (or two).
Java is a complicated language and after reading this book you'll think so too. I have also read Joshua Bloch's Effective Java and it's a good companion book for this one; they're book very good and worth the a read (or two).
June 5, 2009
For nerds only. Mildy interesting, but not the kind of thing you'd want to use for interview questions.
November 9, 2009
very good.
April 8, 2011
Not terribly useful or entertaining but the appendix is worth going through.
February 13, 2013
Great way to learn the corner cases of the Java language up to Java 5. Java 6 and 7 editions would make interesting reads, when available.
March 4, 2013
boring boring boring and did I mention boring?
Read
March 15, 2013005.133 B6513 2005
Read
May 6, 2013Will make you answer well all the Trivial-pursuit questions on Java... not a really practical book, but very entertaining!
March 20, 2014
This book needs no introduction. A very fun and insightful read for those who want to master Java.
February 28, 2016
A book that'll make every Java developer go of "What?", "But..", "How the hell...". An expose of Java's known (and not so known) dirty secrets.
October 15, 2016
Got unnecessary details.
December 16, 2012
It's a definite must read ...
November 25, 2013
Book has old code but still its worth the price....
Read
March 8, 2017tkgoeprkpoer
Displaying 1 - 25 of 25 reviews


















