Tuesday, May 20, 2008

What's new in Effective Java 2nd Edition

Effective Java 2nd Edition is finally here, and I couldn't find a detailed list of what's new anywhere. So besides updating the old items to Java 5 and 6, Joshua Bloch also added these new items:

Creating and Destroying Objects
Item 2 - Consider a builder when faced with many constructor parameters
Generics
Item 23 - Don't use raw types in new code
Item 24 - Eliminate unchecked warnings
Item 25 - Prefer lists to arrays
Item 26 - Favor generic types
Item 27 - Favor generic methods
Item 28 - Use bounded wildcards to increase API flexibility
Item 29 - Consider typesafe heterogeneous containers
Enums and Annotations
Item 31 - Use instance fields instead of ordinals
Item 32 - Use EnumSet instead of bit fields
Item 33 - Use Use EnumMap instead of ordinal indexing
Item 34 - Emulate extensivle enums with interfaces
Item 35 - Prefer annotations to naming patterns
Item 36 - Consistently use the Override annotation
Item 37 - Use marker interfaces to define types
Methods
Item 42 - Use varargs judiciously
Item General Programming
Item 46 - Prefer for-each loops to traditional loops
Item 49 - Prefer primitive types to boxed primitives
Concurrency
Item 68 - Prefers executors and tasks to threads
Item 71 - Use lazy initialization judiciously

So far, I feel like the 2nd edition was worth the price I paid for it. Some of the old items were revised quite a bit, and the new items on enums and annotations are very good. But here are my disclaimers: I haven't read all the new items, I work for the publisher (Pearson), I only paid $20 for the book after my employee discount, and it was expensed anyway. I love these perks.

1 comment:

Peter Pascale said...

Solid summary - I was wondering what had changed. But as I'm reading, I'm really impressed by the length to which he has updated existing items. They certainly account for changes to Java in 5/6. And they aren't just always language changes and example updates. For example - he explains why one should use instanceof in equals() implementations (following the Liskov substitution principle).

I'd have to say most of the items carried over from the 1st edition have been updated in ways that will be of great use to java programmers. This is a classic and anyone on the fence about getting an updated copy should go for it.

Example - h