Slashdot Mirror


Effective Java

benjiboo writes "From the back page: 'Are you looking for a concise book packed with insight and wisdom not found elsewhere? Do you want to gain a deeper understanding of the Java programming language? Do you want to write code that is clear, correct and reusable?' I did, so I bought the book and decided to use it for my first review :)" Read on for bejiboo's review of Effective Java. Effective Java Programming Language Guide author Joshua Bloch pages 252 publisher Addison Wesley rating 8/10 reviewer Ben ISBN 0201310058 summary 57 pieces of Java wisdom.

Introduction

Effective Java is a book very much in the style of Scott Myers' earlier C++ "Effective" series. The book contains 57 individual snippets of Java wisdom, broadly categorised into 10 sections including Classes and Interfaces, Exceptions, Threads and Serialisation. Scott Myers' books are classics; I was interested to see how this would compare.

The author, Joshua Bloch, has been involved in writing many industrial-strength Java libraries. His background is very much evident, in this, his first text. He consistently demonstrates the virtues of favouring libraries, clean APIs and advance design. I found the author very readable, and able to make a convincing argument, even in his more 'controversial' pieces. As with Scott Myers' books, there is a real-world, rather than purist approach taken to the language, with most of the code examples having a real-world feel to them. This is a breath of fresh air when lots of programming books tend to use more contrived examples.

The items

The author has endeavoured to keep the book accessible to less-experienced programmers throughout, while providing food for thought for the more advanced reader. For the most part this is succesful, but a small percentage of articles tend toward the simple side. Examples include 'Minimise the accessibility of classes and embers,' 'Write doc comments for all exposed API elements,' and 'Know and use the libraries.' We've all heard this advice many times and I don't feel that these add value. The vast majority however, are pitched at the right difficulty level. The selection of items is well balanced and broad, although unfortunately there are none pertinent to GUI programming.

Many of the articles are fundamentally based on known design patterns and idioms. Although a useful index to these patterns is included, I would have liked to see the virtues of design patterns summarised and demonstrated to a greater extent, perhaps in the introduction.

I was highly impressed with all code examples. Where used, they are consistently short, relevant and concise, with more verbose examples included on the website. The chosen code examples only ever assist in explaining complex concepts clearly.

The strongest area of the book for me was the section on threading. The author clearly demonstrates, for instance, how overuse of synchronised methods can lead to deadlock. He also provides food for thought on how the thread scheduler might trip us up. A section on moving from C constructs, which initially struck me as an odd category, proved very interesting and thorough. 'Replace enum constructs with classes' is a particularly interesting item, demonstrating the fragility of C enums, and indicating why the often-used replacement in Java (a bunch of public static constants) suffers from the same failings.

In conclusion

Ideally I would have liked to see some of the thinner items removed, and perhaps replaced with a section on the GUI libraries. I also liked the short prose sections, and thought the author could have spent more time setting out his stall before launching in to the items. Having said this, this is one of those rare books which could help a good programmer become an excellent one. Many of the books currently out there are aimed at either the beginner or the guru, and this book fills a gap.

I find this style of book very useful, in that I could foresee meeting the vast majority of the described situations at some point or another. So long as you aren't looking for tips to help you with your GUIs, this title is more than worth the investment.

For anyone interested, those sections in full:

  • creating and destroying objects
  • methods common to all objects
  • classes and interfaces
  • substitutes for C constructs
  • methods
  • general programming
  • exceptions
  • threads
  • serialisation

You can purchase Effective Java from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

11 of 157 comments (clear)

  1. The author by dubbayu_d_40 · · Score: 5, Informative

    J. Bloch wrote the collections framework. His code is clean... I mean, really clean. Given the author's credentials, I suspect this'll stand out in the vast ocean of Java lit...

  2. Re:From the people who brought you: by blinder · · Score: 5, Insightful

    having developed many effective applications for a few years using java, i can, with confidence respond that "Effective Java" is not a contradiction. i've found that most "java haters" are those whose experience goes no further than the applet. too bad sun ever conceived of that little painful abomination.

    java is like any other language, its a tool to get your job done, and contrary to popular belief, it gets it done rather nicely.

    of course i don't mean to wax religious here... there's enough of that here.

  3. Absolutely the best Java book I've read by dknj · · Score: 5, Informative

    This book is the best resource I've encountered for someone who knows the Java language, but wants to master its use. I can virtually guarantee that the rules and techniques covered in "Effective Java" will form the new foundation on which you will build the rest of your best practices for writing excellent Java code.

    Written by the Joshua Bloch, the acknowledged expert on the subject, it is as authoritative as they come and extremely well-written. After six and a half years as a senior developer architecting and implementing algorithms and class libraries in Java, this book shocked me by summarizing much of what I knew about how to use the language effectively, while teaching me much that I did not know. It continues to top my recommended reading list for all new software developers at my company.

    -dk

    1. Re:Absolutely the best Java book I've read by goul · · Score: 5, Interesting

      Indeed. It might be worth noting that James Gosling (one of the parents of Java) describes this as a book he needs.
      This book will show you any bad habits that you have picked up, and teach you why they are bad. I've not found a single developer of any level of experience who has not found this book useful.

  4. Re:Advice: Stick with a real OO language by FiskeBoller · · Score: 5, Insightful
    Java is slow, as annoying to program as Microsoft's C# language, and just plain impractical.

    Java is slow? Maybe that's just your coding. These guys (among others) don't agree with you...

    http://www.sosnoski.com/Java/Compare.html
    http://www.javagrande.org/jgsc98/index.html

    IBM has achieved 90% the speed of C in Java. I personally use the CERN numerical libraries ... very cool, very fast. Java certainly can be fast. I've seen distributed Java beat C++ implementations hands down (that was hard to everyone to believe ... problem was C++ CORBA marshalling and the RTTI overhead in C++).

    I've used Squeak, and have a background in coding Smalltalk (Digitalk, ParcPlace, IBM VA). Squeak is a great up-and-coming environment, but FAR from commercial. Can you name one commercial implementation in Squeak?

    I think that lack of commercial viability makes Squeak impractical. Java, on the other hand, has scads of drop-in commercial libraries and components. This makes economic sense in business. Java also has a proven track record on the server side, and there are many, many successful commercial implementations in mission critical environments.

    And NO, I don't think Java is the perfect enviroment; far from it. I've yet to see my ideal language, and I keep looking on the horizon for a dynamic functional/object/aspect language that performs and holds up in a commercial setting. In the meantime, I've got real work to do.

  5. This book is invaluable. by Hirofyre · · Score: 5, Interesting

    There are a lot of Java books out there, but this is one that will help an intermediate-to-advanced Java developer. The code examples in here are concise, clean, and hard-hitting. The layout of the book allows you to pick it up and learn something if you have 10 minutes or 2 hours.
    When I was first learning Java, I often had that nagging feeling that I was making things harder on myself than need be. This book cleared up a lot of those feelings, and helped get me on the right track for some of the great tools hidden away in the Java API. The API documentation is great for showing you what members and functions are available to an engineer, but this book shows you how to use the API. The review cites the author's avocation of knowing the libraries, I would contend that this book would help you get the most out of those libraries, and increase your understanding of them.
    This book has become a must-have around my office, and if you are looking to get over-the-hump and move from an intermediate to advanced java software engineer, pick up this book. It is dense with information, and will save you a ton of time and energy. What more could you ask for from a book?

  6. Scott Myers by kzinti · · Score: 5, Informative

    Effective Java is a book very much in the style of Scott Myers' earlier C++ "Effective" series

    This is about the highest praise you can give a language-specific programming guide. In his books Scott not only listed many of the ways you could get in trouble in C++, but also gave clear explanations of why they were trouble and why his recommendations were good practices. His books are top of the list I recommend to people who know the language and want to write solid fast code. If Effective Java is as good, I'll soon be adding a copy to my bookshelf.

    --Jim

    1. Re:Scott Myers by MSBob · · Score: 5, Informative
      It's not as good. I own this book and own both C++ books by Scott Meyers and this one is not nearly the level of Meyers' titles.

      The topics it discusses are much more obvious than the traps that Meyers covered. Java's a simpler language, that's fair enough but there are areas of Java, especially around concurrent programming and network and io apis that may surprise even experienced developers. Those areas are precisely where 'Effective Java' is thin on content and I found it disappointing overall.

      Just because it's sectioned the same way as Scott Meyers' books doesn't mean it's just as good!

      --
      Your pizza just the way you ought to have it.
  7. A few more good words by melquiades · · Score: 5, Informative

    This is a fantastic book, and anybody's who's serious about writing good Java code should study it carefully. It's one of the best-written books -- may the best -- on the practical details of programming that I've ever encountered, and the advice is gold. The section on correctly implementing equals() and hashCode() alone is almost worth the price of the book.

    The reviewer complains about some of the thinner or more "obvious" items, but I disagree. Heaven only knows how many times I've wished that really good and experienced programmers follow what seems the obvious maxim: "Minimise the accessibility of classes and members."

    It's true that "Know and use the libraries" seems rather obvious and vague advice, but Bloch's exposition drives home the fact that you may not follow this advice as well as you think. As always, his examples are excellent: he shows how an innocuous-seeming abuse of java.util.Random creates serious problems, and how proper use of the libraries fixes the problem. How often do you write a loop to print the contents of an array? I never realized until Bloch pointed it out that System.out.println(Arrays.asList(array)) accomplishes the same thing much more simply.

    If you're a Java programmer, get this book. If you're a technical author, aspire to it.

  8. I have read a little bit... by SecretAsianMan · · Score: 5, Informative
    ...of this book, and I will most definitely finish it when I have the time. Unless you are a balls-to-the-wall guru already (99.999% chance you aren't), you will become a better Java developer by reading this book. It pays to read even some of the simpler and more obvious tips, as your viewpoint on those issues might not be as omniscient as you think.

    Best of all, it's not 3 feet think like Effective Java Unleashed or The Effective Java Bible would be. You get lots of info with minimal fluff.

    --

    Washington, DC: It's like Hollywood for ugly people.

  9. Sample Chapters by darkpurpleblob · · Score: 5, Informative

    Four sample chapters from the ten in the book are available in PDF format at the books website.