Join Amazon Prime and ship Two-Day for free and Overnight for $3.99. Already a member? Sign in.
Java- Puzzlers: Traps, Pitfalls, and Corner Cases and over 300,000 other books are available for Amazon Kindle – Amazon’s new wireless reading device. Learn more

 

or
Sign in to turn on 1-Click ordering.
 
 
More Buying Choices
52 used & new from $23.69

Have one to sell? Sell yours here
 
   
Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases
 
 
Start reading Java- Puzzlers: Traps, Pitfalls, and Corner Cases on your Kindle in under a minute.

Don’t have a Kindle? Get yours here.
 
  

Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases (Paperback)

by Joshua Bloch (Author), Neal Gafter (Author) "This book is filled with brainteasers about the Java programming language and its core libraries..." (more)
Key Phrases: eager initialization, widening primitive conversion, enclosing instance, Character Solution, Loopy Puzzlers Solution, Expressive Puzzlers Solution (more...)
4.5 out of 5 stars See all reviews (30 customer reviews)

List Price: $44.99
Price: $35.99 & this item ships for FREE with Super Saver Shipping. Details
You Save: $9.00 (20%)
  Special Offers Available
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
In Stock.
Ships from and sold by Amazon.com. Gift-wrap available.

Want it delivered Tuesday, July 21? Choose One-Day Shipping at checkout. Details
34 new from $27.42 18 used from $23.69
Also Available in: List Price: Our Price: Other Offers:
Kindle Edition (Kindle Book) $17.59

Special Offers and Product Promotions

  • Purchase this entertainment book and get 12 issues to either Rolling Stone, Men's Journal or Us Weekly for $2.95 each. That's less than $0.25 an issue. Here's how (restrictions apply)

Frequently Bought Together

Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases + Effective Java (2nd Edition) (Java Series) + Java Concurrency in Practice
Price For All Three: $118.44

Show availability and shipping details

  • This item: Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases by Joshua Bloch

    In Stock.
    Ships from and sold by Amazon.com.
    This item ships for FREE with Super Saver Shipping. Details

  • Effective Java (2nd Edition) (Java Series) by Joshua Bloch

    In Stock.
    Ships from and sold by Amazon.com.
    This item ships for FREE with Super Saver Shipping. Details

  • Java Concurrency in Practice by Brian Goetz

    In Stock.
    Ships from and sold by Amazon.com.
    This item ships for FREE with Super Saver Shipping. Details


Customers Who Bought This Item Also Bought

Java Concurrency in Practice

Java Concurrency in Practice

by Brian Goetz
4.8 out of 5 stars (59)  $37.79
Java Generics and Collections

Java Generics and Collections

by Maurice Naftalin
4.6 out of 5 stars (23)  $23.09
Head First Design Patterns

Head First Design Patterns

by Elisabeth Freeman
4.6 out of 5 stars (275)  $29.67
Effective Java: Programming Language Guide (Java Series)

Effective Java: Programming Language Guide (Java Series)

by Joshua Bloch
4.8 out of 5 stars (122)  $44.85
Spring in Action

Spring in Action

by Craig Walls
4.1 out of 5 stars (64)  $31.49
Explore similar items

Editorial Reviews

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

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.





See all Editorial Reviews

Product Details

  • Paperback: 312 pages
  • Publisher: Addison-Wesley Professional (July 4, 2005)
  • Language: English
  • ISBN-10: 032133678X
  • ISBN-13: 978-0321336781
  • Product Dimensions: 9.1 x 7.3 x 0.9 inches
  • Shipping Weight: 1.3 pounds (View shipping rates and policies)
  • Average Customer Review: 4.5 out of 5 stars See all reviews (30 customer reviews)
  • Amazon.com Sales Rank: #193,729 in Books (See Bestsellers in Books)

Inside This Book (learn more)

What Do Customers Ultimately Buy After Viewing This Item?

Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases
47% buy the item featured on this page:
Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases 4.5 out of 5 stars (30)
$35.99
Effective Java (2nd Edition) (Java Series)
27% buy
Effective Java (2nd Edition) (Java Series) 4.9 out of 5 stars (35)
$44.66
Java Concurrency in Practice
17% buy
Java Concurrency in Practice 4.8 out of 5 stars (59)
$37.79
Java Generics and Collections
4% buy
Java Generics and Collections 4.6 out of 5 stars (23)
$23.09

Tags Customers Associate with This Product

 (What's this?)
Click on a tag to find related items, discussions, and people.
Check the boxes next to the tags you consider relevant or enter your own tags in the field below.
(12)
(2)

Your tags: Add your first tag
 
Help others find this product — tag it for Amazon search
No one has tagged this product for Amazon search yet. Why not be the first to suggest a search for which it should appear?

 

Customer Reviews

30 Reviews
5 star:
 (24)
4 star:
 (1)
3 star:
 (2)
2 star:
 (2)
1 star:
 (1)
 
 
 
 
 
Average Customer Review
4.5 out of 5 stars (30 customer reviews)
 
 
 
 
Share your thoughts with other customers:
Most Helpful Customer Reviews

 
57 of 59 people found the following review helpful:
5.0 out of 5 stars Ooh. Ow. Ouch. Eek. Argh. ... Aha., November 22, 2005
By Bob Carpenter (New York, NY) - See all my reviews
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.
Comment Comment | Permalink | Was this review helpful to you? Yes No (Report this)



 
19 of 19 people found the following review helpful:
5.0 out of 5 stars Unique book finds pitfalls in both programs and the language itself, May 26, 2006
By calvinnme "Texan refugee" (Fredericksburg, Va) - See all my reviews
(TOP 10 REVIEWER)      
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.
Comment Comment | Permalink | Was this review helpful to you? Yes No (Report this)



 
16 of 16 people found the following review helpful:
5.0 out of 5 stars Most Excellent, July 15, 2005
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 www.javapuzzlers.com. 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.
Comment Comment | Permalink | Was this review helpful to you? Yes No (Report this)


Share your thoughts with other customers: Create your own review
 
 
Ad
 
Most Recent Customer Reviews

2.0 out of 5 stars Totally useless
The "puzzles" in the book are cases which no programmer would come across in real life 99.99% of the times. Read more
Published 6 months ago by Mayur Sharma

5.0 out of 5 stars I loved it - I must be a Geek!
Don't buy this book if you other chores to do. You won't be able to put it down! Both fun and challenging. A one-of-a-kind book for Java lovers.
Published 9 months ago by Jerome Alter

5.0 out of 5 stars one of my best for Java
This is an amusing and at the same time amazing book that helps avoiding some very dark corners you might not have been aware of when programming in Java. Read more
Published 12 months ago by Vassilis Michalitsis

5.0 out of 5 stars Interesting and funny
This book presents several problems that maybe even expert Java developers never thougt about. Some of them are only curious corner cases, others present tricky behaviours of the... Read more
Published 12 months ago by Diana Francesco

5.0 out of 5 stars Great Book!
Completing the puzzles in this book will increase your knowledge of the Java language spec. This book was written by 2 of the world's foremost Java experts.
Published 18 months ago by JadeBailey24

5.0 out of 5 stars Was so much Fun
This book was so much fun to read but more importantly it surprised me a couple of times ... which is what i expected when i got it ... Read more
Published 19 months ago by Anirudh

3.0 out of 5 stars Not a Bloch Classic - Only a Special Interest Book
I really do love "Effective Java(TM) Programming Language Guide" by Joshua Bloch und so I read "Java Puzzlers" by him in the expectation to deepen my Java knowledge in a... Read more
Published 19 months ago by ws__

2.0 out of 5 stars Very esoteric
You really have to be a language weenie to care about many of these. If you're looking to become a better programmer, or simply to be entertained, this probably isn't the right... Read more
Published on June 26, 2007 by Alexander Rosen

5.0 out of 5 stars Great book for people who like puzzlers/Java
The book is very friendly and readable.
Some of the examples are real unique and in most cases you are not going to meet them but it's fun to read, use your mind and check... Read more
Published on January 16, 2007 by Ido Green

5.0 out of 5 stars another cracker from Josh ...
Disclaimer: the fact that I have known and worked with Josh on and off for around 10 years now has little bearing on my review of this book. Read more
Published on June 29, 2006 by Laurence Cable

Only search this product's reviews



Customer Discussions

 Beta (What's this?)
New! See all customer communities, and bookmark your communities to keep track of them.
This product's forum (0 discussions)
  Discussion Replies Latest Post
  No discussions yet

Ask questions, Share opinions, Gain insight
Start a new discussion
Topic:
First post:
Prompts for sign-in
  [Cancel]


Active discussions in related forums
  Discussion Replies Latest Post
Philosophy of programming 0 1 hour ago
C# or Java? 35 20 hours ago
Jobs for Self Taught Programmers? 41 1 day ago
   


Product Information from the Amapedia Community

Beta (What's this?)



Look for Similar Items by Category


Items Eligible for Free Super Saver Shipping

Beauty benefit tint
Check out all items in beauty that are elligible for free super saver shipping and prime.

See more Prime-eligible beauty items

 

Big Savings in Books

Bargain Books
Find great titles at fantastic prices in our Bargain Books Store.
 

Buy Three Books, Get a Fourth Free

4-for-3 Books
Order any four eligible books under $10 and get the lowest-price book free in our 4-for-3 Books Store. See more details.
 

Best Books

Best of the Month
See our editors' picks and more of the best new books on our Best of the Month page.
 
Ad

 

Feedback

If you need help or have a question for Customer Service, contact us.
 Would you like to update product info or give feedback on images?
Is there any other feedback you would like to provide?

Your comments can help make our site better for everyone.


Where's My Stuff?

Shipping & Returns

Need Help?

Your Recent History

  (What's this?)
You have no recently viewed items or searches.

After viewing product detail pages or search results, look here to find an easy way to navigate back to pages you are interested in.

Look to the right column to find helpful suggestions for your shopping session.

Continue shopping: Top Sellers
Free
Free by Chris Anderson
Paranoia
Paranoia by Joseph Finder
The Adventures of Sherlock Holmes
The Adventures of Sherlock Holmes by Arthur Conan, Sir, 1859-1930 Doyle
Glenn Beck's Common Sense

Conditions of Use | Privacy Notice © 1996-2009, Amazon.com, Inc. or its affiliates