InfoQ

News

Book Excerpt and Interview: Effective Java, Second Edition

Posted by Ryan Slobojan on May 13, 2008 09:00 PM

Community
Java
Topics
Language
Tags
Language Features ,
Book ,
FindBugs ,
Guice

Effective Java, Second Edition by Joshua Bloch is an updated version of the classic first edition, which was the winner of a 2001 Jolt Award. This edition has been updated to discuss Java 6 language features, and the back cover of the book describes some of the new topics covered as:

  • New coverage of generics, enums, annotations, autoboxing, the for-each loop, varargs, concurrency utilities, and much more
  • Updated techniques and best practices on classic topics, including objects, classes, libraries, methods, and serialization
  • How to avoid the traps and pitfalls of commonly misunderstood subtleties of the language
  • Focus on the language and its most fundamental libraries: java.lang, java.util, and, to a lesser extent, java.util.concurrent and java.io

The book's publisher, Addison-Wesley, made an excerpt available to InfoQ which includes the contents of the fifth chapter, entitled 'Generics'.

Read Book Excerpt and Interview: Effective Java, Second Edition

From the article:

InfoQ: Are there major changes between the previous version of 'Effective Java' and this one, or is it more of a refinement of existing ideas?

Joshua Bloch: It's a combination of additions and refinements. The second edition covers all the new language features. It has a chapter on generics, one on enums and annotations, and items on the for-each loop, autoboxing, varargs, and static import. The concurrency chapter has been thoroughly revised in light of java.util.concurrent. And all the existing items have been revised to reflect these new features, and to reflect seven more years of experience with the platform.

That said, I worked very hard not to alter the feel of the book. Hopefully it will feel like an old friend to readers of the first edition -- a little wiser and little heavier (21 items and 83 pages, to be precise), but an old friend.
Great news by prashant jalasutram Posted May 14, 2008 6:50 AM
what comment ? by anjan bacchu Posted May 14, 2008 9:51 PM
Re: what comment ? by Ryan Slobojan Posted May 15, 2008 10:07 AM
Probable small error on sample chapter by Rafael de F. Ferreira Posted May 15, 2008 7:48 PM
Re: Probable small error on sample chapter by Rai Singh Posted May 16, 2008 7:08 AM
Re: Probable small error on sample chapter by Joshua Bloch Posted May 16, 2008 11:45 AM
Re: Probable small error on sample chapter by Mark Shaffer Posted May 20, 2008 1:32 PM
  1. Back to top

    Great news

    May 14, 2008 6:50 AM by prashant jalasutram

    Josh, We all love you and you are the star!!!!! Thanks Prashant

  2. Back to top

    what comment ?

    May 14, 2008 9:51 PM by anjan bacchu

    "They also asked us to add the following comment:" which comment were you referring to ? BR, ~A

  3. Back to top

    Re: what comment ?

    May 15, 2008 10:07 AM by Ryan Slobojan

    My apologies - the comment being referred to is now found at the bottom of the article. When it was moved, the line you mentioned was not updated - it has been fixed now.

    Thanks for catching that!

  4. Back to top

    Probable small error on sample chapter

    May 15, 2008 7:48 PM by Rafael de F. Ferreira

    I'm very excited about this edition, and it is great to see InfoQ offering the generics chapter so we can take a peek before the book begins to ship. I don't know if this is the version that went to press, but I think there is a small error on a code snippet. On the bottom of page 121 we find:

    // Reduction without generics or concurrency flaw
    static Object reduce(List list, Function f, Object initVal) {
        Object[] snapshot = list.toArray(); // Locks list internally
        Object result = initVal;
        for (Object o : list)
            result = f.apply(result, o);
        return result;
    }
    
    But I believe the inner loop should have been:
    // Reduction without generics or concurrency flaw
    static Object reduce(List list, Function f, Object initVal) {
        Object[] snapshot = list.toArray(); // Locks list internally
        Object result = initVal;
        for (Object o : snapshot)
            result = f.apply(result, o);
        return result;
    }
    

  5. Back to top

    Re: Probable small error on sample chapter

    May 16, 2008 7:08 AM by Rai Singh

    I am not sure I agree with your change entirely since the index of the array is never referenced in your code from within the for-each loop. However, I can see what you mean by the book version being incorrect since snapshot is not used anywhere.

  6. Back to top

    Re: Probable small error on sample chapter

    May 16, 2008 11:45 AM by Joshua Bloch

    Rafael,

    You are absolutely right. What's worse, I caught this problem before the book went to print. I fixed it in the code example bundle (which will soon be posted on the book's web site). Somehow I failed to propagate the change into the book. I hope this is the only place where I did this.

    I will fix the problem in the second printing and put it on the (currently nonexistent) errata page as soon as possible.

    Thanks for spotting this!

    Josh

  7. Back to top

    Re: Probable small error on sample chapter

    May 20, 2008 1:32 PM by Mark Shaffer

    Josh,
    
    I'm wondering if you have revised Item 7 in the first edition, which contains this statement (in bold no less), which seems to me to be false:
    
    "There is simply no way to extend an instantiable class and add an aspect while preserving the equals contract."
    
    The example in the book missed these possible implementations for Point and ColorPoint respectively, which appear to me to fill the bill:
    
      public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        if (o.getClass() != getClass()) return false;
        Point p = (Point) o;
        return p.x == x && p.y == y;
      }
    
      public boolean equals(Object o) {
        if (!super.equals(o)) return false;
        ColorPoint p = (ColorPoint) o;
        return p.color == color;
      }
    

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.