Jump to ratings and reviews
Rate this book

Effective Java : Programming Language Guide

Rate this book
The Definitive Guide to Java Platform Best Practices--Updated for Java 7, 8, and 9 Java has changed dramatically since the previous edition of Effective Java was published shortly after the release of Java 6. This Jolt award-winning classic has now been thoroughly updated to take full advantage of the latest language and library features. The support in modern Java for multiple paradigms increases the need for specific best-practices advice, and this book delivers. As in previous editions, each chapter of Effective Java, Third Edition, consists of several "items," each presented in the form of a short, stand-alone essay that provides specific advice, insight into Java platform subtleties, and updated code examples. The comprehensive descriptions and explanations for each item illuminate what to do, what not to do, and why. The third edition covers language and library features added in Java 7, 8, and 9, including the functional programming constructs that were added to its object-oriented roots. Many new items have been added, including a chapter devoted to lambdas and streams. New coverage includes
Functional interfaces, lambda expressions, method references, and streams Default and static methods in interfaces Type inference, including the diamond operator for generic types The @SafeVarargs annotation The try-with-resources statement New library features such as the Optional interface, java.time, and the convenience factory methods for collections Register your product at informit.com/register for convenient access to the web edition eBook, updates, and/or corrections as they become available.

252 pages, Paperback

First published June 5, 2001

Loading interface...
Loading interface...

About the author

Joshua Bloch

30 books135 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
5,000 (63%)
4 stars
2,094 (26%)
3 stars
578 (7%)
2 stars
127 (1%)
1 star
57 (<1%)
Displaying 1 - 30 of 412 reviews
Profile Image for Eric.
108 reviews17 followers
February 12, 2012
This is the single best book I have seen or read about Java to date. Bloch, who has been involved in the development of the latest versions of the Java language and specification, does not teach how to write Java code; he teaches how to write GOOD Java code.

This is a MUST READ for anyone who plans to write more than a little bit of Java code. But not only that, it is fairly easy to read and rather interesting.

I had a few second thoughts after writing the review above, so I thought I'd better add two things. First, make sure you get the most recent edition of the book as there have been substantial changes. Second, this is not a beginner's book - you won't find "HelloWorld" here. Learn the Java basics first.
Profile Image for Andrew.
132 reviews19 followers
April 11, 2013
Score: 3.5/5

Effective Java: even the title is concise and to-the-point, like the rest of the book's writing. This is not a book for beginners, but rather a book on general software design concepts, particularly with respect to Java itself. The book is organized into a few dozen "items", most of which follow this format:
1) "Here's a suggestion. You should probably follow it."
2) "Here's an example of following it, here's an example of why not following it is bad, and here's an example of when you can ignore this suggestion."
and then you've read that item.

The good examples are good, and there's a lot to learn about writing software in general. He starts off with a solid defense of static factory methods (Item 1), offers patterns for successfully avoiding multithreading issues (Item 48) and serialization issues (Item 54), and even has sound general programming advice (Item 30: "Know and use the libraries", or Item 37: "Optimize judiciously").

Some of the suggestions seem to hinge on the assumption that the code you write is well-thought-out, such as Item 13: "Minimize the accessibility of classes and members." On the one hand, a well-designed module will be self-contained, easily usable via its publicly exposed methods, and will be more maintainable because of limited scope. On the other hand, how much code duplication occurs because a module's fields are private when they could be protected, or because certain parts of its implementation aren't exposed that should otherwise be reused?

When faced with a compromise between writing extra code and entertaining the possibility of a client using your code in a way differently than you intended, Bloch always chooses writing extra code. The classic "favor composition over inheritance" (Item 14) is a great example of this, with his InstrumentedSet example marred by an unruly horde of "forwarding methods".

Bloch never questions the language itself, but instead sometimes uses its design "decisions" as justification for suggestions. From Item 35, "Prefer interfaces to reflection", after providing a code example of using reflection (emphasis added):
You can see two disadvantages of reflection in the example. First, the example is capable of generating three run-time errors, all of which would have been compile-time errors if reflective instantiation were not used. Second, it takes twenty lines of tedious code to generate an instance of the class from its name, whereas a constructor invocation would fit neatly on a single line.

I understand that this book is about how to code in Java, but using the inconvenience of writing meta-code in Java as a reason to not write it (especially after how willing he is to add plenty of forwarding methods), instead of commenting on the language's design or pointing out in how many languages you could write the example in one line, is inexcusable.

Bloch seems endlessly concerned with a potential "attacker" of your code (Item 3: "enforce noninstantiability with a private constructor", or Item 24: "make defensive copies when needed")---though not as much against "people maliciously accessing your servers" concern as "clients using your library in ways you did not intend them to." This has, of course, always been a dispute between Java programmers and Python/Perl/Ruby/JS developers in terms of how "open" libraries should be to manipulation if you need them to do something just slightly different than intended. I do find it amusing, however, given the existence of Java's reflection API---if someone wanted to "maliciously" misuse your API, the language won't stop them, but will just make it more difficult.

I'm reminded of the ending from Steve Yegge's "Wikileaks to Leak 5000 Open Source Java Projects With All That Private/Final Bullshit Removed":
"[This is what] Java developers who release Open Source […] code are saying: 'Here, I worked hard on this. I hope you like it. But use it exactly how I tell you to use it, because fuck you, it's my code. I'll decide who's the goddamn grown-up around here."


This book deserves its reputation for being good at what it does: teaches you to write better Java. But the context is still Java, with all of its strengths and weaknesses. For better or worse, Bloch is writing about Java as it is, and not as it could be, and his assumptions about the reader's quality of judgment make you wonder how much code duplication he has inadvertently caused.
Profile Image for Miloš.
67 reviews3 followers
April 16, 2020
Well, I've been staring at the screen and trying to rate this book for at least 20 minutes, all the while changing my mind every other minute or so. Writing a review for it is making me equally conflicted but at least in the review I'm not limited to only two options (3 or 4 stars, if anyone's wondering).

First thing to say is that Joshua Bloch is a competent enough author - a bit dry but always to the point, clear, precise and thorough. And he really knows his Java - so much so that I regret not having read this book (well, the previous edition at least) some 10 years ago when I was just starting out - it's definitely more useful to beginners and I could have learned a ton!

The items themselves present the reader with sound advice but the choice of the items is what I take issue with:
* some items read like they were written ~15 years ago for C++ folks moving to Java (enums and bitmaps, native code warnings)
* others read like they were written to highlight old anti-patterns that probably very few devs use in this day and age (finalizers, clone, Serializables, wait/notify, yield...)
* a few have disproportionate amount of space devoted to them given their importance (see previous point and add to it toString, hashCode & equals and probably a few others)
* lots of them (by author's own admission) are more applicable of you're writing a library or framework intended for wide audiences/public use and seem needlessly defensive

Summed up, the criticism amounts to this - while all the items included within are valid, the book would have had more to offer and reader to gain from cutting some of them short (or throwing them out completely) and replacing them with more practically useful items. What about I/O? Don't tell me there's nothing to say. And where are CompletableFutures, asynchronous and non-blocking programming? More from java.util.concurrency and Java's standard library in general?

Or maybe I'm just a splendid curmudgeon in the making...
Profile Image for Christian Brumm.
84 reviews19 followers
December 26, 2010
Effective Java is THE BOOK you want to read first when you start writing Java code professionally (for a living).

In the style of Scott Meyer's C++ books, Joshua Bloch - the head behind several modern Java libraries - presents the essential tricks of the trade and best practises when it comes to Java programming. This is essential when you want to write highly maintainable, efficient modern Java code.

The second edition puts a lot of emphasis on all the new language features that came with Java 5 and especially how they made past best practises obsolete. This is exactly what you don't get by reading general Java programming books or tips online - most of which is old and just not the best implementation possible. Implementation issues are treated from the perspective of API maintainability. This aims for very high quality standards (e.g. libraries) but is nevertheless interesting for every Java programmer. We are all writing APIs of some sort - in the extreme case just for ourselves.

This book can safe you a lot of future headaches!
Profile Image for Rafi.
20 reviews17 followers
March 21, 2017
I read this book as a recommended reading for the Java developers at Google. I found many "items" described in this book quite useful in real-life coding. Sometimes the author has gone a little too far to describe a single item, but overall the book is very well written.
Profile Image for Ashkan Entezari.
28 reviews2 followers
June 24, 2019
An amazing book about Java and its different features. If you are a Java programmer, you will benefit a lot and learn a lot by reading this book. Whenever you want to pick up this book, make sure you take the latest edition as it changes a lot to accommodate new updates in the language and its libraries.

I have summarized the entire book (3rd edition) here!

This includes a summary of each item with its code examples in a way that is more concise and understandable.
Profile Image for Andrijana.
31 reviews1 follower
August 8, 2019
Some items were a little bit advanced for me as a beginner. Not so much in a sense that they were hard to understand, but they seemed so far away from me to even think about them at the first place or grasp their importance. But, I'm pretty sure that as my programming career continues I'll pick up this book as a reference and be able to appreciate it more.
Profile Image for Jonathan Zanella.
3 reviews1 follower
January 27, 2017
I started reading it to improve my knowledge of java and it was exactly what I found.
The books is separated in 78 items with begin and end, so reading an item who is 2 to 3 pages long, you end with a new approach to something.
It is really an enjoyable experience :)
Profile Image for Rodrigo Almeida.
9 reviews3 followers
September 14, 2018
The introduction and middle of the book are awesome, with incredible new informations about Java. After, there are some chapters very boring, for example, about the JavaDoc.
Even if the book still very good.
Profile Image for Michael.
Author 7 books588 followers
April 16, 2009
Although it is a bit outdated, 90% of the book contains great advise for any Java programmer. If you have not read this then you do not know how to program Java.
-m
Profile Image for Anadi Vyas.
26 reviews
Currently reading
July 1, 2023
Not competent enough to review this book, the following are my mere notes:
Objects:
1)Consider static factory methods instead of constructors:
a. One advantage of static factory methods is that, unlike constructors, they have names & A class can have only a single constructor with a given signature
b. A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they’re invoked. The ability of static factory methods to return the same object from repeated invocations allows classes to maintain strict control over what instances exist at any time. Classes that do this are said to be instance-controlled.
c. the class of the returned object can vary from call to call as a function of the input parameters
d. The main limitation of providing only static factory methods is that classes without public or protected constructors cannot be subclassed.
2)Consider a builder when faced with many constructor parameters:
a. telescoping constructor pattern
b. JavaBeans pattern, in which you call a parameterless constructor to create the object and then call setter methods to set each required parameter and each optional parameter of interest:Unfortunately, Because construction is split across multiple calls, a JavaBean may be in an inconsistent state partway through its construction.
c. alternative that combines the safety of the telescoping constructor pattern with the readability of the JavaBeans pattern. It is a form of the Builder pattern. Instead of making the desired object directly, the client calls a constructor (or static factory) with all of the required parameters and gets a builder object. Then the client calls setter-like methods on the builder object to set each optional parameter of interest. Finally, the client calls a parameterless build method to generate the object, which is typically immutable. The builder is typically a static member class of the class it builds.
d. The Builder pattern is well suited to class hierarchies. Use a parallel hierarchy of builders, each nested in the corresponding class. Abstract classes have abstract builders; concrete classes have concrete builders
e. The Builder pattern is quite flexible. A single builder can be used repeatedly to build multiple objects. The parameters of the builder can be tweaked between invocations of the build method to vary the objects that are created. A builder can fill in some fields automatically upon object creation, such as a serial number that increases each time an object is created.
3)Enforce noninstantiability with a private constructor
A default constructor is generated only if a class contains no explicit constructors, so a class can be made noninstantiable by including a private constructor
4) Prefer dependency injection to hardwiring resources
Profile Image for Rob.
Author 2 books418 followers
May 7, 2020
Recommended for anyone who is doing full time professional Java development. Bloch well-codifies a lot of the otherwise cargo-culted tribal knowledge and conventions that are out there, as well as shedding light on many of the weird cases that we run into everyday. And/but/so then there's a bunch of items that are NOT a part of my everyday ... though I'm sure that's just a matter of circumstance, and for someone out there: they are.

It gets pretty technical in places and by necessity can get into the weeds, but most of the content should be accessible to journeyman developers, as well as committed novices.
June 21, 2020
I found this book by asking a simple question, which books are mandatory reading to learn about Java. Once I finished it I realized it also answered another question, "which books are recommended reading for any software developer". Often times when trying to learn a new language or improve knowledge on a familiar one, it feels like most available literature is aimed at students learning to code or at experienced developers trying to improve some highly technical knowledge. The books that I find the best are the ones that are about learning from experience. That's how this books feels, not as a glossary on how to code in Java, but instead as a personal blog of an experienced developer going through learned lessons and past mistakes.
Profile Image for dantelk.
165 reviews14 followers
July 21, 2024
I took a few pages worth of notes, and all in all, this booked helped me either grip a better understanding of concepts I had an idea of, or reminded me of certain ideas which I've lost in my memory. I enjoyed reading the chapters, the book is readable while commuting on railways etc. Maybe Serilization and Generics chapters could have been edited better, but all in all, quite understandable concepts.

I wish the book had some more up-to-date editions; almost all new version of Java since 9 had some new features in terms on concurrency.

I would recommend watching Venkat Subramaniam's conference recordings on Youtube over reading this book - I think his seminars complement this book nicely.
Profile Image for Giovani Facchini.
47 reviews4 followers
July 7, 2019
This is an amazing book for Java developers and it shows that Joshua really knows his stuff. It clarifies and shows in deep details the internals of Java and how it should be used in order for you to be more effective.

It is a great reading and I strongly recommend it. It is important to notice that as this book shows 90 recommendations, it is hard for the reader to remember everything, so you should use it as a reference book when you are going to implement something. Personally, I have printed the chapter titles, so I remember to study the specific recommendation when I am creating something new.

The author was responsible for architecting and implementing many Java features and he exposes good and bad practices of many libraries that we use today, so we have a better understanding of what to use and not to use.

In summary, read this book! :)
Profile Image for Alexander.
67 reviews
October 20, 2020
Fantastic book that any Java developer should read at some point in their career (preferably earlier on)! Very well laid out and contains many invaluable principles/conventions with good explanations that, when followed, will improve the code you produce.
Profile Image for Hayley Hu.
164 reviews1 follower
July 25, 2022
Really helped me build the craftsmanship of writing Java
Profile Image for Erik Nilson.
15 reviews8 followers
December 27, 2019
The very best book about this topic. I learned lot from this book — thanks to authors.
Profile Image for Tomáš.
300 reviews33 followers
July 10, 2018
Můj osobní etalon skvělé programátorské knížky: spousta užitečných informací; minimum balastu; užitečné reference, kam jít dál; vysvětlení, proč věci jsou tak, jak jsou.

Je to již potřetí, co jsem tuto knížku četl, pokaždé v nové edici. A popravdě je to poprvé, co jsem nad pěti hvězdami zaváhal. Nemůže za to ale asi autor, ale samotná podstata věci. Java je prostě už stará. Knížka už ani tak neřeší, jak psát věci efektivně, jako kterým oblastem jazyka se vyhnout. Nějak automaticky se mi vybavuje název české knížky o C++: "Pasti a pastičky". Občas mi totiž při čtení bylo smutno, čím vším si případný nováček musí projít a co na něj číhá za strašidla.

Samozřejmě jsem se naučil řadu nových věcí (hlavně řadu "pomocných" metod postupně přidaných do knihovny jazyka), ale zároveň vím, že jsem daleko víc nepobral a budu rád, když si o těchto tématech alespoň udržím povědomí a pak budu moct "šáhnout do šuplíku" a znova zapátrat.

Čtěte, kupujte... nevím, je to patetické, ale nic lepšího mě nenapadá.
Profile Image for Andrzej.
6 reviews
October 5, 2018
I have read the 3rd edition of this book, which is updated for Java 8. It’s a collection of 90 best practices for developers. Those practices cover a wide range of mostly used Java features, including generics, exceptions, concurrency, serialization, lambdas and many others.

A lot of relevant code examples showing both the good and the bad code followed by a robust explanation. The focus is on developers who create APIs that others will use, however IMHO everyone writing in Java would benefit from this book.

I wouldn’t recommend this book to beginners who are not yet fluent in various aspects of Java. The examples are complex and can be confusing for someone with little experience. I tried to read the previous version when I still had little experience. I have found the book too difficult and I gave up after just 30 pages. Having a couple more years of Java coding in my life I have tried again and this time it has been a blast. I have learned a lot and will use this book as reference throughout my career.

Thanks to mr Bloch for this great book.
47 reviews
June 20, 2010
This is a unique and very worthwhile work for experienced Java developers who want to take their Java skills to the next level. It assumes that the reader is fully comfortable programming in Java, and gives a collection of tips on how to exploit certain language features, how to avoid various pitfalls, and so forth. The book makes frequent reference to design patterns, but it is not a design patterns book. It is also distinct from a “software engineering” book, but rather concentrates on aspects of Java that are do (or do not) accomplish various software engineering goals. The author does not hesitate to point out inadequacies and inconsistencies in the Java language itself, often as cautionary tales to illustrate the consequences of insufficiently thought-out design decisions made early in the language’s life.

I give Effective Java my highest recommendation.
Profile Image for Tomasz.
100 reviews52 followers
May 13, 2012
If most programmers consider Core Java to be the best book for beginners, they should think about “Effective Java” as the best book for intermediate and more advanced Java programmers.
After this book my awareness about how good Java code should look like improved a lot. I learnt a lot of interesting and useful approaches to developing code in different situations. And, in spite of being heavily packed of knowledge, I can not say that reading this book was difficult. It was a nice lecture although some topics are more complicated and forced me to slow down and analyse paragraphs one by one. More on my blog post.
Profile Image for Nick Black.
Author 2 books838 followers
November 4, 2013
Before I head off to Google in NYC next February, I'm doing three months of contract work for a Java shop in Atlanta. I picked this up to refresh my Java skills, which have grown rusty in the decade-plus since taking and then TA'ing the Java-based Introduction to Computer Science as a freshman at GT. A quick and useful guide in the line of Scott Meyers's Effective C++ and More Effective C++, on which Mr. Bloch seems to have consciously based his book.
22 reviews21 followers
July 9, 2010
If you program Java, you must read this book. You won't learn any new syntax, language feature, library, or framework, but you will be a much better programmer as a result of reading this book. Its the best anything on Java I have read. I don't agree with 100% of the material in this book, but Joshua Bloch has a strong, clear opinions and he argues them well. This book is so good, I think you should read it even if you aren't a Java programmer but program C#, C++, or something else along those lines. Even Ruby and Python programmers will probably get a lot out of this book.
13 reviews1 follower
August 10, 2010
This book impressed me with the amount of practical use-cases of Java subtleties and intricacies -- for example, the proper implementation of "equals" method in classes.

The author not only shows us some common misconceptions about the "low level" Java mechanics (not the native level, but the basics of the language and the Java API), but also gives us many examples from his rich carreer.

It is my opinion that understanding the basics of Java (it turns out many of us don't) is the key to avoiding mistakes which are subsequently very hard to track, and this book helps exactly with this.
Profile Image for Denis.
8 reviews1 follower
July 15, 2013
This book is simply brilliant. Updated to the most recent language specification it covers a lot of issues and caveats that almost every Java developer encounters every day. The author is the guy who has designed and implemented the Collections framework and he knows his subject very well. This book can and definitely will increase one's productivity dramatically. The only obvious prerequisite is that a reader should already know and have experience in Java. Otherwise it would be better to invest some time and learn the language itself.
18 reviews
January 6, 2013
If you have already done a few years of programming in an object oriented programming language like Java, this book might make you very uncomfortable. More than saying what to do, this book stresses on what not to do in Java and you'll thank for it in the long term.

The tips are organised into items each of few pages and can be read independently.
Displaying 1 - 30 of 412 reviews

Can't find what you're looking for?

Get help and learn more about the design.