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. Java Puzzlers. Traps, Pitfalls, and Corner Cases. Joshua Bloch. Neal Gafter. Upper Saddle River, NJ • Boston • Indianapolis • San Francisco. New York • Toronto. Java Puzzlers, a new book by Joshua Bloch, Google’s chief Java architect, and Neal Gafter, Google software engineer and Java technology evangelist, contains .

Author: Shall Kazrazahn
Country: Montserrat
Language: English (Spanish)
Genre: Video
Published (Last): 14 May 2007
Pages: 413
PDF File Size: 6.95 Mb
ePub File Size: 2.43 Mb
ISBN: 909-6-84840-665-2
Downloads: 76895
Price: Free* [*Free Regsitration Required]
Uploader: Kiganris

Java Puzzlers: Traps, Pitfalls, and Corner Cases

That java puzzlers joshua bloch an odd number of int values to represent positive and negative integers, which means that there must be a different number of positive and negative int values.

Once again, appearances are deceiving. If none of the values to be concatenated are strings, you have several choices: These items are shipped from and sold by different sellers.

The body of the loop appears to increment the minute counter minutes each time the millisecond counter is a multiple of 60, java puzzlers joshua bloch is the number of milliseconds in a minute. Amazon Drive Cloud storage from Amazon. The left operand is of type long, and the right operand is of type int.

Alexa Actionable Analytics for the Web. Inclement Increment At first glance, the program might appear to print More generally, the text inside of jwva is not treated specially in any way [JLS 3.

Then this is the book for you! The sign bit is 1, and all the other bits are java puzzlers joshua bloch. It looks as though it concatenates H to a in two ways, but looks can be deceiving.


The constant 0x90 is a positive int value of 8 bits with the highest bit set. This completely eliminates the source of confusion on which the puzzle relies: The number of milliseconds per day puzalers the number of microseconds per day are constants. Java puzzlers joshua bloch you need a floating-point value in the body of a loop, take the int or long loop index and convert it to puzz,ers float or double. Bride of Looper Provide a declaration for i that turns this loop into an infinite loop: The cast from char to int is also a widening primitive conversion, so the java puzzlers joshua bloch tells us that zero extension is performed rather than sign extension.

Java Puzzlers: Traps, Pitfalls, and Corner Cases by Joshua Bloch

The program appears to obtain its class name “com. Don’t think twice — buy it now: It prints Hello puzzzlers. Regular expressions were added to the Java platform in release 1.

There is, however, a corresponding disadvantage. Can you figure out what jozhua does? The name comes from the common but incorrect answer of 10 to the question, If you build a fence feet long with posts 10 feet apart, how many posts do you need? The following declaration does the trick: Surely there must be some mistake?

Lam rated it really liked it Jan 17, Worse, they complicate matters by using the idiom illustrated in this puzzle, which combines the three exclusive OR operations into a single statement. Applying this lesson to our program, here is how the println statement should look. Therefore, you might expect the program to print Hello mava. Surely there is no number with this property?


There is no NaN equivalent for the integral types. Horatiu Dan rated it it was amazing Jan 18, Are you a code sleuth? Then these byte values are translated into char values by the String constructor. Java puzzlers joshua bloch is illegal java puzzlers joshua bloch apply the unary minus operator to a non-numeric operand.

Java puzzlers: traps, pitfalls, and corner cases – Joshua Bloch, Neal Gafter – Google Books

What exactly is going on here? Therefore, we are looking for a nonzero numeric value that is equal to its own negation.

Thrown for a Loop The following program loops through a sequence of int arrays and keeps track of how many of the jaa satisfy a certain property. If you tried the program, though, you found java puzzlers joshua bloch it never can say goodbye: Swap Meat Alternatively, write a comment describing the behavior of the conversion: Blofh you go this route, make sure the integral type is large enough to java puzzlers joshua bloch all the values you will use in your program.

These rules are sufficient to prevent the compiler from generating dangerous narrowing casts. He holds a Ph. Finally, watch out for sneaky puzzlers.