Java Puzzlers: Traps, Pitfalls, and Corner Cases

Author: Joshua Bloch, Neal Gafter
This Month Stack Overflow 3


by anonymous   2019-07-21

I have done a similar test before. As previous answers have stated they tend to cover a wide range from obvious questions to problems that lead you to wonder about the sanity of the developers of the test...

One tip is to check the rules very carefully. Some allow you to use reference materials - if this is the case, it's worth having several tabs on your browser open to quick reference guides, as you usually have a few minutes per question. Some even allow you to run code - get yourself a good process for quickly running little test programs.

Another suggestion is to work through a book like Java Puzzlers: Traps, Pitfalls, and Corner Cases which has a lot of little quirky puzzles which help explain dusty corners of the Java spec. This will show you stuff that is similar to the really obscure puzzles that recruitment tests sometimes throw up.

by anonymous   2019-07-21

There's a collection of semi-official "gotchas", known as the Java Puzzlers, and documented in a book of the same name; you might also find a few screencasts on the web. Periodically, Joshua Bloch and Neal Gafter like to present a bunch of innocuous-looking challenges and proceed to systematically remove any notion you had that you understood even the vaguest basics of the Java language.

On a slightly less cynical note, if you're looking to avoid many of the common design and implementation cock-ups, you might take a look at Effective Java, by the aforementioned Joshua Bloch, which has a wealth of decent advice on how to go about designing several of the important - but frequently badly written - aspects of writing components in Java, including a comprehensive explanation of how to properly implement the contract of equals() and hashCode(), and why you should avoid clone() like the plague.

Oh, and don't compare strings with the == operator.

by anonymous   2019-07-21

See the JLS specification Choosing the Most Specific Method

It is one of the puzzle of Java Puzzlers by Joshua Bloch - Puzzle 46: Case of the Confusing Constructor

by noxToken   2018-02-18
Java Puzzlers[0] has a few entries similar to this. Some of the entries are things that would trip you up (but logically makes sense) rather than oddities, but it's an interesting read. Note that the book is from 2005 and uses Java 5.