Skip to main content

Java Puzzlers strikes JavaONE

Posted by felipegaucho on May 8, 2007 at 4:46 PM PDT

Dr. Joshua Bloch and a representative of Dr. Neal Gafter just finished a fantastic presentation about weird behaviour of apparently simple programs, the tricky behaviour they call Java Puzzlers. They not only showed the puzzles but also the way to fix it in day-by-day life. The contents included this assertions:

  • Short and Integer are different, don't try to use primitive integer values to look for a Short object in a map.
  • Different URL Strings that point to different web pages can represent the same Map keys.
  • JUnit doesn't support concurrency.
  • Classloader ignores recursive class initialization.
  • I/O Streams skip() method does not skips the amount of bytes you asked to be skipped.
  • Math.abs doesn't guarantee nonnegative result Integer.MIN_VALUE == -
    Integer.MIN_VALUE

  • (?:) operator present weird behaviour handling mixed wrapper classes.

  • Conversion form int to float is dangerous.

Seems easy? Are you not understanding these fragments captured live during a lecture? Ok, I agree it is a bit raw, but I will not try to translate all the reasoning done during the presentation in this small blog entry. My only tip here is that the attendees was invited to answer the puzzles during the presentation and almost none was consensus and for sure none was responded correctly by the majority of people in the room. Very challenger.

Java Puzzlers is a book, and if you are curious about what that means or you want to contact the authors, you can check the book site.
I bought mine in the JavaONE's book store and I am proud to have my exemplar signed by Dr. Bloch - an excellent speaker and a gentleman.

bloch.jpg