| help | account  


Java Puzzlers: Traps, Pitfalls, and Corner Cases
View Larger Image
Joshua Bloch, Neal Gafter
Addison-Wesley, Paperback, Published June 2005, 282 pages, ISBN 032133678X
List Price: $39.99
Our Price: $31.50
You Save: $8.49 (21% Off)


FREE Shipping on Orders over $40!*
Availability: In-Stock
Download an excerpt:
A Java Puzzlers Sampler

     

Excerpt provided courtesy of Addison-Wesley Professional. Copyright © Addison-Wesley. Written permission from the publisher is required for any use of this material.

Customer Reviews: 1     Average Customer Rating:

Write a Review and tell the world about this title!

People who purchase this book frequently purchase:

Books on similar topics, in best-seller order:Books from the same publisher, in best-seller order:

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


Preface

"Like many books, this one had a long gestation period. We've collected Java puzzles for as long as we've worked with the platform: since mid-1996, in case you're curious. In early 2001, we came up with the idea of doing a talk consisting entirely of Java puzzles. We pitched the idea to Larry Jacobs, then at Oracle, and he bought it hook, line, and sinker.

We gave the first "Java Puzzlers" talk at the Oracle Open World conference in San Francisco in November 2001. To add a bit of pizazz, we introduced ourselves as "Click and Hack, the Type-it Brothers" and stole a bunch of jokes from Tom and Ray Magliozzi of Car Talk fame. The presentation was voted best-in-show, and probably would have been even if we hadn't voted for ourselves. We knew we were on to something.

Dressed in spiffy blue mechanic's overalls emblazoned with the "cup and steam" Java logo, we recycled the Oracle talk at JavaOne 2002 to rave reviews--at least from our friends. In the years that followed, we came up with three more "Java Puzzlers" talks and presented them at countless conferences, corporations, and colleges in cities around the globe, from Oslo to Tokyo. The talks were almost universally well liked, and we got very little fruit thrown at us. In the March 2003 issue of Linux Magazine, we published an article consisting entirely of Java puzzles and received almost no hate mail. This book contains nearly all the puzzles from our talks and articles and many, many more.

Although this book draws attention to the traps and pitfalls of the Java platform, we do not mean to denigrate it in any way. It is because we love the Java platform that we've devoted nearly a decade of our professional lives to it. Every platform with enough power to do real work has some problems, and Java has far fewer than most. The better you understand the problems, the less likely you are to get hurt by them, and that's where this book comes in.

Most of the puzzles in the book focus on short programs that appear to do one thing but actually do something else. That's why we've chosen to decorate the book with optical illusions--drawings that appear to be one thing but are actually another. Also, you can stare at them while you're trying to figure out what in the world the programs do.

Above all, we wanted this book to be fun. We sincerely hope that you enjoy solving the puzzles as much as we enjoyed writing them and that you learn as much from them as we did.

And by all means, send us your puzzlers! If you have a puzzle that you think belongs in a future edition of this book, write it on the back of a $20 bill and send it to us, or e-mail it to puzzlers@javapuzzlers.com. If we use your puzzle, we'll give you credit. Last but not least, don't code like my brother."

Josh Bloch
Neal Gafter
San Jose, California
May 2005

 

Table of Contents

1. Introduction.

2. Expressive Puzzlers.

    Puzzle 1: Oddity

    Puzzle 2: Time for a Change

    Puzzle 3: Long Division

    Puzzle 4: It's Elementary

    Puzzle 5: The Joy of Hex

    Puzzle 6: Multicast

    Puzzle 7: Swap Meat

    Puzzle 8: Dos Equis

    Puzzle 9: Tweedledum

    Puzzle 10: Tweedledee

3. Puzzlers with Character.

    Puzzle 11: The Last Laugh

    Puzzle 12: ABC

    Puzzle 13: Animal Farm

    Puzzle 14: Escape Rout

    Puzzle 15: Hello Whirled

    Puzzle 16: Line Printer

    Puzzle 17: Huh?

    Puzzle 18: String Cheese

    Puzzle 19: Classy Fire

    Puzzle 20: What's My Class?

    Puzzle 21: What's My Class, Take 2

    Puzzle 22: Dupe of URL

    Puzzle 23: No Pain, No Gain

4. Loopy Puzzlers.

    Puzzle 24: A Big Delight in Every Byte

    Puzzle 25: Inclement Increment

    Puzzle 26: In the Loop

    Puzzle 27: Shifty i's

    Puzzle 28: Looper

    Puzzle 29: Bride of Looper

    Puzzle 30: Son of Looper

    Puzzle 31: Ghost of Looper

    Puzzle 32: Curse of Looper

    Puzzle 33: Looper Meets the Wolfman

    Puzzle 34: Down for the Count

    Puzzle 35: Minute by Minute

5. Exceptional Puzzlers.

    Puzzle 36: Indecision

    Puzzle 37: Exceptionally Arcane

    Puzzle 38: The Unwelcome Guest

    Puzzle 39: Hello, Goodbye

    Puzzle 40: The Reluctant Constructor

    Puzzle 41: Field and Stream

    Puzzle 42: Thrown for a Loop

    Puzzle 43: Exceptionally Unsafe

    Puzzle 44: Cutting Class

    Puzzle 45: Exhausting Workout

6. Classy Puzzlers.

    Puzzle 46: The Case of the Confusing Constructor

    Puzzle 47: Well, Dog My Cats!

    Puzzle 48: All I Get Is Static

    Puzzle 49: Larger Than Life

    Puzzle 50: Not Your Type

    Puzzle 51: What's the Point?

    Puzzle 52: Sum Fun

    Puzzle 53: Do Your Thing

    Puzzle 54: Null and Void

    Puzzle 55: Creationism

7. Library Puzzlers.

    Puzzle 56: Big Problem

    Puzzle 57: What's in a Name?

    Puzzle 58: Making a Hash of It

    Puzzle 59: What's the Difference?

    Puzzle 60: One-Liners

    Puzzle 61: The Dating Game

    Puzzle 62: The Name Game

    Puzzle 63: More of the Same

    Puzzle 64: The Mod Squad

    Puzzle 65: A Strange Saga of a Suspicious Sort

8. Classier Puzzlers.

    Puzzle 66: A Private Matter

    Puzzle 67: All Strung Out

    Puzzle 68: Shades of Gray

    Puzzle 69: Fade to Black

    Puzzle 70: Package Deal

    Puzzle 71: Import Duty

    Puzzle 72: Final Jeopardy

    Puzzle 73: Your Privates Are Showing

    Puzzle 74: Identity Crisis

    Puzzle 75: Heads or Tails?

9. More Library Puzzlers.

    Puzzle 76: Ping Pong

    Puzzle 77: The Lock Mess Monster

    Puzzle 78: Reflection Infection

    Puzzle 79: It's a Dog's Life

    Puzzle 80: Further Reflection

    Puzzle 81: Charred Beyond Recognition

    Puzzle 82: Beer Blast

    Puzzle 83: Dyslexic Monotheism

    Puzzle 84: Rudely Interrupted

    Puzzle 85: Lazy Initialization

10. Advanced Puzzlers.

    Puzzle 86: Poison-Paren Litter

    Puzzle 87: Strained Relations

    Puzzle 88: Raw Deal

    Puzzle 89: Generic Drugs

    Puzzle 90: It's Absurd, It's a Pain, It's Superclass!

    Puzzle 91: Serial Killer

    Puzzle 92: Twisted Pair

    Puzzle 93: Class Warfare

    Puzzle 94: Lost in the Shuffle

    Puzzle 95: Just Desserts

Appendix A: Catalog of Traps and Pitfalls.

Appendix B: Notes on the Illusions.

References.

Index.


About the Author

Joshua Bloch is a Principal Engineer at Google. Previously he was a Distinguished Engineer at Sun Microsystems and a Senior Systems Designer at Transarc. He led the design and implementation of numerous Java platform features, including the JDK 5.0 language enhancements and the Java Collections Framework. He holds a Ph.D. in Computer Science from Carnegie-Mellon University and a B.S. in Computer Science from Columbia University.


Customer Reviews

Customer Reviews: 1     Average Customer Rating:

Sep 5, 2005     Mahesh from USA
Great reading
This book is for an experienced Java programmer. It mentions the common thing we programmers tend to miss out in learning Java. The overall presenatation is informal that makes reading very easy.



Forgot your password?
FAQs
Shipping Options
Returns
Your Orders
Your Account