InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Book Excerpt and Interview: Effective Java, Second Edition

Posted by Ryan Slobojan on May 13, 2008

Sections
Development
Topics
Java ,
Language
Tags
Book ,
FindBugs ,
Guice ,
Language Features

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
what comment ? by anjan bacchu Posted
Re: what comment ? by Ryan Slobojan Posted
Probable small error on sample chapter by Rafael de F. Ferreira Posted
Re: Probable small error on sample chapter by Rai Singh Posted
Re: Probable small error on sample chapter by Joshua Bloch Posted
Re: Probable small error on sample chapter by Mark Shaffer Posted
  1. Back to top

    Great news

    by prashant jalasutram

    Josh,

    We all love you and you are the star!!!!!

    Thanks
    Prashant

  2. Back to top

    what comment ?

    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 ?

    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

    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

    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

    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

    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

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.