Effective Java
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.
Do not talk of this Java Sanctuary. There is no such thing.
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...
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.
sad robot making broken music
Man, I'm barely done with Douglas Dunn's
Java Rules and now I gotta read this?
Actually, I'm glad to see more book son coding effectively as opposed to the dummy approach which is a sure way to Shoot yourself in the foot when the maintenance phase rolls around.
That said, one thing copiously missing from the review is whether or not the book covers J2EE at all -- which by and far requires some guidance in the developing the most effective Java applications.
--- have you healed your church website?
Have you actually used it lately? Speed has been the biggest improvement. Sure, it used to be slow as hell, I concur, but with Java 2 (1.4) it is wicked quick. And for windows apps, it's far better than VB in at least one aspect - grids. Java has a grid object that works the way you'd want it to, resizeable, sortable, column-rearrangeable... And for data drive apps, this is a major thorn out of my side.
How are you going to keep them down on the farm once they've seen Karl Hungus?
In a Windows dominated enviorment, is there any other better alternative to what I am already using?
.NET seems to work alot better than the hideous quivering zygote that is VB6, IMHO. In particular C#.
.NET. I'd also go with Java if your IT department had any plans to change platforms in the future. .NET and company allow MS to keep a string tied to your IT decisions unless you're willing to abandon your code.
The abortion that is
Really, I would say that it depends on the environment. If the back end is Oracle or DB2, I'd probably go with Java; if it's SQL Server I'd be more inclined to go with
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
Java is slow? Maybe that's just your coding. These guys (among others) don't agree with you...
http://www.sosnoski.com/Java/Compare.htmlhttp://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.
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?
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
What does 'setting out his stall' mean? I picture somebody settling on to the toilet and opening the newspaper, but in the context I don't think that's what you meant.
Thank you, a good review of an excellent book. I have maybe 10 java books, most of them from O'Reilly and none have been as beneficial to my development in Java as this one.
The code and the text are both very clear and concise, and you can read the book cover to cover, coming back later to study each advice more in depth.
I think you can get it from reading between the lines in the review, but just to make it clear to any curious beginner, this is not the first book you should buy if you are just starting to learn java. Use
The Java Tutorial instead, and maybe
Learning Java.
Being bitter is drinking poison and hoping someone else will die
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.
Many important Java techniques and idioms are described so well in this book that I have been known to insert comments to the effect of:
(or some such) into my code. Most of the author's items should be as engrained in the mind of a Java developer as terms like 'singleton' and 'event listener'.
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.
When this came out in 2001, James Gosling showed a copy of it at his keynote at JavaOne. They sold out every copy they had at the show, and the Effective Java talk later that day/week, was so packed you couldn't even get it. Great book.
I rarely find a tech book that offers more than a few examples I ear-mark. This book however has me re-reading it from time to time. The lessons picked up take time to sink in, and IMO no one can truly pick up all of the lessons on one read through.
Four sample chapters from the ten in the book are available in PDF format at the books website.
...that Effective Java talks about by using a static code analyzer. Like this one:
http://pmd.sf.net/
PMD will find places where you've used concrete collections rather than interfaces, left unused code lying around, etc., etc.
Tom
The Army reading list
I've found in my experience that Java is good when it's highly specialized and kept very small and simple (yes, Java is good for APPLETS!). For enterprise applications, it _sucks_.
Interesting observation...
Why don't you give us some specific examples to back up that sweeping statement?
I'm not a big fan of Java, but I was impressed by everything that has been said here about how much Java has matured, so I figured I'd put it to the test.
I dug up some old benchmarks (the BYTEmarks, which includes a jBYTEmark, normalized to that same P90) that I can use to fairly compare Java and C performance.
I've got a 1.2Ghz Duron, and the C version of the BYTEmarks seems to reflect this accurately--with scores of 26.6 Integer and 21.4 FP, with a P90 being 1.00.
I'm comparing this against two separate Java implementations--Sun's JVM for Linux, and gcj (I also tried out a program that translates Java bytecodes to C, but the resultant executable didn't perform correctly). Here's a table of results:
C Bytemark: INT: 26.6 FP: 21.4
SUN (--server) INT: 4.21 FP: 1.80
GCJ INT: 3.63 FP: 1.71
SUN (Default) INT: 2.18 FP: 2.14
Now, I'm not surprised that the C version ran so fast, but I am surprised the the Java benchmarks did so badly, considering that both benchmarks were normalized to an index of 1.0 for the same Pentium 90! Maybe I got a bad copy of the jBytemarks--it was hard to find a copy at all--but it looks pretty legit.
Do any of you Java people have some amazing tips for me? I did use all the optimization flags I could find. Or is this typical performance for Java, making a 1.2Ghz Duron run as slow as a P200 or a K6/300?
pb Reply or e-mail; don't vaguely moderate.