JavaTM Puzzlers: Traps, Pitfalls, and Corner Cases and over 2 million other books are available for Amazon Kindle . Learn more

Buy New

or
Sign in to turn on 1-Click ordering.
Buy Used
Used - Good See details
Price: 19.34

or
 
   
Trade in Yours
For a 4.97 Gift Card
Trade in
More Buying Choices
Have one to sell? Sell yours here
Sorry, this item is not available in
Image not available for
Colour:
Image not available

 
Start reading JavaTM Puzzlers: Traps, Pitfalls, and Corner Cases on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Java Puzzlers: Traps, Pitfalls, and Corner Cases [Paperback]

Joshua Bloch , Neal Gafter
4.7 out of 5 stars  See all reviews (3 customer reviews)
Price: 28.99 & FREE Delivery in the UK. Details
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Only 1 left in stock (more on the way).
Dispatched from and sold by Amazon. Gift-wrap available.
Want it tomorrow, 1 Aug.? Choose Express delivery at checkout. Details

Formats

Amazon Price New from Used from
Kindle Edition 14.30  
Paperback 28.99  
Trade In this Item for up to 4.97
Trade in Java Puzzlers: Traps, Pitfalls, and Corner Cases for an Amazon Gift Card of up to 4.97, which you can then spend on millions of items across the site. Trade-in values may vary (terms apply). Learn more

Book Description

24 Jun 2005

"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.




Frequently Bought Together

Java Puzzlers: Traps, Pitfalls, and Corner Cases + Effective Java: Second Edition + Java Concurrency in Practice
Price For All Three: 84.67

Buy the selected items together


Product details

  • Paperback: 312 pages
  • Publisher: Addison Wesley; 1 edition (24 Jun 2005)
  • Language: English
  • ISBN-10: 032133678X
  • ISBN-13: 978-0321336781
  • Product Dimensions: 23.4 x 18.8 x 1.9 cm
  • Average Customer Review: 4.7 out of 5 stars  See all reviews (3 customer reviews)
  • Amazon Bestsellers Rank: 281,733 in Books (See Top 100 in Books)
  • See Complete Table of Contents

More About the Author

Joshua Bloch, Google's chief Java architect and a former Distinguished Engineer at Sun Microsystems, won the prestigious Jolt Award from Software Development Magazine for his book, Effective Java Programming Language Guide. At Sun, he led the design and implementation of numerous Java platform features, including JDK 5.0 language enhancements and the award-winning Java Collections Framework. He holds a Ph.D. in computer science from Carnegie-Mellon University and is the co-author, with Neal Gafter, of Java Puzzlers.


Product Description

From the Back Cover

"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.



About the Author

Joshua Bloch is a principal engineer at Google and a Jolt Award-winner. He was previously a distinguished engineer at Sun Microsystems and a senior systems designer at Transarc. Josh led the design and implementation of numerous Java platform features, including JDK 5.0 language enhancements and the award-winning Java Collections Framework. He holds a Ph.D. in computer science from Carnegie Mellon University.

Neal Gafter is a software engineer and Java evangelist at Google. He was previously a senior staff engineer at Sun Microsystems, where he led the development of the Java compiler and implemented the Java language features in releases 1.4 through 5.0. Neal was a member of the C++ Standards Committee and led the development of C and C++ compilers at Sun Microsystems, Microtec Research, and Texas Instruments. He holds a Ph.D. in computer science from the University of Rochester.




Inside This Book (Learn More)
First Sentence
This book is filled with brainteasers about the Java programming language and its core libraries. Read the first page
Browse Sample Pages
Front Cover | Copyright | Table of Contents | Excerpt | Index
Search inside this book:

What Other Items Do Customers Buy After Viewing This Item?


Customer Reviews

3 star
0
2 star
0
1 star
0
4.7 out of 5 stars
4.7 out of 5 stars
Most Helpful Customer Reviews
13 of 13 people found the following review helpful
4.0 out of 5 stars For Effective Java fans 13 Oct 2005
By A Customer
Format:Paperback
Very much in the style of Effective Java, this expands on (and refers to) some of the themes in that book, so you might want to read it before this one.
Java Puzzlers highlights some workings of the Java language that might trip you up, particularly when it comes to instantiating and initialising class members and fields. These are represented as small code snippets, the output of which you are expected to predict.
To be honest, as long as you follow correct Java practices (naming packages, classes, methods etc according to standards) you won't be tripped up by most of these. Personally, I have no cause to be messing about with byte and char primitives types, attempting to cast them to ints, hex, octal, or carrying out obscure bit shifting - this seems rather a low-level C-ish thing to do.
That said, there is also some sage advice, particularly about the vagaries of overloading and overriding, and the advice is collected together into an appendix for easy access. It doesn't feel quite as cohesive as EJ, though.
A special mention should go to the various optical illusions that accompany the puzzles. A lot of these I've not seen before, and several of them may cause your optic nerve to melt.
Not as essential as Effective Java, but still worth reading.
Comment | 
Was this review helpful to you?
2 of 2 people found the following review helpful
5.0 out of 5 stars Read for fun, not to be a better programmer 7 May 2007
Format:Paperback|Verified Purchase
Josh Bloch/Neal Gafter have a talent for giving concise coding wisdom with rock solid examples, this book is no different to Effective Java in that respect.

However, those expecting to hear coding philosophies and common pitfalls to avoid are not going to find them here. This book is about exactly what is says on the cover: corner cases. You may never encounter any of these issues in your entire Java career.

That said, the puzzles are insanely difficult and I found them very entertaining to read. There are possibly 2 or 3 puzzles in the entire book that are "cheap tricks", but the rest are all to do with subtleties in the language itself. If I had any criticism it would be that the puzzles go straight from puzzle to explanation without explicitly showing the output as an intermediary step... the author suggests that you run the programs and try to reach an explanation yourself. I tend to read books when travelling or when taking a break from the computer screen, so this was not practical for me.

If you haven't read Effective Java, I'd strongly recommend you read it first. I'd recommend this book to those that like a challenge or enjoy reading about Java subtleties.
Comment | 
Was this review helpful to you?
1 of 2 people found the following review helpful
5.0 out of 5 stars Another gem from Joshua and Neal 13 Mar 2009
Format:Paperback
You can think of this book as the Java illusionists cookbook.
Full of examples designed to trip you up. Full of "Now you see it. Now you don't" effects. This analogy transcends from the examples to the images too. Optical overloading if you will! I really enjoy reading Joshua's books. He has a memorable style that conveys the nuances of the Java language in such a way as to be informative yet very entertaining at the same time. I thoroughly recommend this book.
Comment | 
Was this review helpful to you?
Most Helpful Customer Reviews on Amazon.com (beta)
Amazon.com: 4.4 out of 5 stars  38 reviews
99 of 102 people found the following review helpful
5.0 out of 5 stars Ooh. Ow. Ouch. Eek. Argh. ... Aha. 22 Nov 2005
By Bob Carpenter - Published on Amazon.com
Format:Paperback|Verified Purchase
My wife popped this book open after dinner. Big mistake -- we had planned to spend the night watching Firefly on DVD. She read the first puzzle. We went to the blackboard (yes, we're so geeky and our NY apartment's so small that there's a blackboard in the dining nook). Between us, we had half a dozen possible answers about what a three-line program was going to do. We found at least four boundary conditions and were pretty sure about two of them. For the record, the first puzzle she opened to involved the compound XOR assignment statement x^=y^=x^=y. They're not all that bit-fiddly; some of the other puzzles include class and method mazes, integer or double arithmetic oddities, unexpected exception/initialization interactions, string/charset twistiness, etc.

I thought I'd be good at this kind of puzzle. As an academic, I wrote about programming languages. I read Bloch's "Effective Java" book. Twice. I follow its advice religously and make my coworkers read it. I've read most of the source code for String, StringBuffer and the collections framework and I/O streams. I just came off a week-long coding project where I did exclusively bit-level I/O with all the shifts and masks you could ask for. I was wrong. I got about 1/5 of the puzzles right if I give myself partial credit for diagnosing the boundary condition in the question and having the right answer be in my top two or three guesses.

Unless you've written the bit fiddling parts of a JVM implementation, or are the kind of person who can remember minute details of the specification, you'll most likely suffer. And love it. Then you can relate the puzzles at gatherings of geeks and look on with a smug grin as they twist in the wind. These would be perfect interview questions for a sadistic HR person.

Overall, this book's a jaw-dropping, eye-opening, brain-melting overview of the kind of boundary conditions you can run into with very simple constructions. Most of the puzzles seem to involve implicit conversions done by the JVM, some involve 1.5 features, some involve class inheritance, others exceptions. Almost all of the puzzles contain links to the boundary-condition definition in the Java language spec.

I'll do better next time. Really.
28 of 29 people found the following review helpful
5.0 out of 5 stars Unique book finds pitfalls in both programs and the language itself 26 May 2006
By calvinnme - Published on Amazon.com
Format:Paperback
This book is filled with brainteasers about the Java programming language and its core libraries. Anyone with a working knowledge of Java can understand these puzzles, but many of them are tough enough to challenge even the most experienced programmer. Puzzlers are grouped according to the features they use, but you cannot assume that the trick to a puzzle is related to its chapter heading.

Most of the puzzles exploit counterintuitive or obscure behaviors that can lead to bugs. Every platform has them, but Java has far fewer than other platforms of comparable power. The goal of the book is to entertain the reader with puzzles while teaching you to avoid the underlying traps and pitfalls. By working through the puzzles, you become less likely to fall prey to these dangers in your own code and more likely to spot them the code of others over which you have maintenance priveleges.

This book is meant to be read while you have access to a computer that has a Java development environment installed, ideally JDK 5.0, which is the latest release at the time I am writing this. That is because some of the puzzles rely on pitfalls in this particular release of Java.

Most of the puzzles take the form of a short program that appears to do one thing but actually does something else. It's the reader's job to figure out what each program does. It would be best if you first study the program/puzzle and determine what you think it will do. Next, run the program and see if its expected behavior matches its actual behavior. Try to fix the program if you believe it is "broken". Finally, read the solution and see if it matches your answer. What is really great about this book is that it sticks to pitfalls in the core language and doesn't delve into any of the add-on API's or J2EE. You'll be surprised that so many pitfalls can be conjured up in the core language. Amazon does not show the table of contents, so I do that here along with a brief description of the type of puzzles in each chapter.

1. Introduction
2. Expressive Puzzles - The puzzles in this chapter are simple but not necessarily easy and involve only expression evaluation. My personal favorite : the statement "System.out.println(2.00 - 1.10);" displays 0.8999999999999999 instead of .9. There is a solution, but it is not pretty and showcases a pretty bad weakness in the Java language.
3. Puzzlers with Character - This chapter contains puzzles that concern strings, characters, and other textual data. This section contains several puzzles involving unicode characters, and one is a cautionary tale for language designers in character overloading. Example: System.out.print('H' + 'a'); prints the number 169 not the word "Ha" as you might imagine.
4. Loopy Puzzlers - All the puzzles in this chapter concern loops, such as coming up with declarations that turn simple loops into infinite ones.
5. Exceptional Puzzlers - The puzzles in this chapter concern exceptions and the closely related Try-finally statement. Most exhibit odd behavior such that simple changes in the program cause completely different types of exception handling to occur.
6. Classy Puzzlers - This chapter contains puzzlers that concern the use of classes and their instances, methods, and fields.
7. Library Puzzlers - The puzzles in this chapter concern basic library-related topics, such as Object methods, collections, Date, and Calendar. One particularly interesting puzzler illustrates that, in Java, integer literals beginning with a "0" are interpreted as octal values. This obscure construct is a holdover from the C programming language and the 1970s, when octal was much more commonly used than today. Thus "012" is seen by Java as 10 base 10.
8. Classier Puzzlers - The puzzles in this chapter concern inheritance, overriding, and other forms of name reuse.
9. More Library Puzzlers - The puzzles in this chapter feature more advanced library topics, such as threading, reflection, and I/O. Here you will learn, for example, that "write(int)" is the only Java output method that does not flush a PrintStream on which automatic flushing is enabled. Thus you must explicitly invoke "flush" on its stream to print any message, making the "write" method seem unfriendly and outright pointless.
10. Advanced Puzzlers - The puzzles in this chapter concern advanced topics, such as nested classes, generics, serialization, and binary compatibility.
A. Catalog of Traps and Pitfalls - This chapter contains a concise taxonomy of traps and pitfalls in the Java platform. Each entry in the catalog is divided into three parts - A short description of the pitfall, how to avoid the trap, and pointers to additional information on the trap.
B. Notes on the Illusions - This appendix contains brief descriptions of the graphical illusions that appear throughout the book. The descriptions are grouped loosely by category. Within each category, the order is roughly chronological.

This book is very good practice for anybody who enjoys programming in the Java language, but it will probably appeal the most to the geekiest among us of which I proudly count myself.
18 of 18 people found the following review helpful
5.0 out of 5 stars Most Excellent 15 July 2005
By Kevin J. Schmidt - Published on Amazon.com
Format:Paperback
Many C and C++ books exist that discuss traps and pit falls with each language. Now Java has such a book. This book is fun to read and will challenge even the best Java programmers. Be sure to get the source code from [...] Study each puzzle and try figure out what it does or does not do. Then run the example code and see if you were right. If you weren't right, then try to figure out why you guessed wrong and figure out how to fix the program. Then turn the page and read the solution.

Working through the puzzlers is not only fun, but it will definitely make you a much better Java programmer and a better troubleshooter.
13 of 13 people found the following review helpful
5.0 out of 5 stars Wonderful stretches for your Java-soaked brain 14 July 2005
By Cliff L. Biffle - Published on Amazon.com
Format:Paperback
I've been passing this book around my office, describing it alternately as "C Traps and Pitfalls on steroids" or "The most fun that can be had with the Java Language Specification with your clothes on." Thus far, it has not failed to frustrate, educate, enlighten, and amuse each reader, usually in that order. I can't think of any better way to become more familiar with the ins, outs, and warts of the Java language: the puzzles, memorable and clever as they are, stick with you.

The writing is fluid, friendly, and full of wit, from the names of the puzzles (like "The Lock Mess Monster" or "Dyslexic Monotheism") to the commentary on the finer points. Even the layout shows thought, with the answers out of plain sight behind the next page.

If your brain burns out on the puzzles, check out the optical illusions in between. (Note: do not, during a car ride, show them to anyone who is prone to motion sickness. I learned this the hard way, so you don't have to.)

I strongly recommend this book if you spend any time in or around Java code. I've had to deal with many of the pitfalls it highlights, and boy, would it have been more pleasant if I'd already read this book.
8 of 8 people found the following review helpful
3.0 out of 5 stars Not really a puzzles book 28 Dec 2009
By J.S.R. - Published on Amazon.com
Format:Paperback
I picked up this book after being asked a question from it in an interview (actually, I was unaware it was from this book until browsing through it at a bookstore).

It's quite an interesting read, even for seasoned java programmers. There's a lot of little quirks and oddness in the Java specification that one rarely encounters in the real world - for good reason, as many of these things should be avoided like the plague. Examples are unicode pre-parsing and passing nulls into overloaded methods with same number of arguments.

If you're looking for logic puzzles, look elsewhere. The title would be more accurate with "puzzlers" removed. This is about the intricacies and flaws of the language. It's more academic than practical. Unless, of course, you're asked an interview question from it.
Were these reviews helpful?   Let us know
Search Customer Reviews
Only search this product's reviews

Customer Discussions

This product's forum
Discussion Replies Latest Post
How does the real book compare to the free sample? 0 22 Sep 2009
See all discussions...  
Start a new discussion
Topic:
First post:
Prompts for sign-in
 

Search Customer Discussions
   


Look for similar items by category


Feedback