Effective Java

  • ISBN13:


  • ISBN10:


  • Edition: 2nd
  • Format: Paperback
  • Copyright: 2008-05-08
  • Publisher: Addison-Wesley Professional
  • View Upgraded Edition
  • Purchase Benefits
  • Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • Get Rewarded for Ordering Your Textbooks! Enroll Now
  • We Buy This Book Back!
    In-Store Credit: $1.31
    Check/Direct Deposit: $1.25
List Price: $54.99 Save up to $8.25
  • Buy New
    Add to Cart Free Shipping


Supplemental Materials

What is included with this book?

  • The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.
  • The eBook copy of this book is not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.


Designed to help Java programmers make the most effective use of the Java programming language and its fundamental libraries, this updated edition includes more than 50 essays, each of which conveys one rule. Helping programmers sidestep common misconceptions and errors, each rule captures best practices that have been tested in the real world.

Author Biography

Joshua Bloch is chief Java architect at Google and a Jolt Award winner. He was previously a distinguished engineer at Sun Microsystems and a senior systems designer at Transarc. Bloch led the design and implementation of numerous Java platform features, including JDK 5.0 language enhancements and the award-winning Java Collections Framework. He coauthored Java™ Puzzlers (Addison-Wesley, 2005) and Java™ Concurrency in Practice (Addison-Wesley, 2006).

Table of Contents

Forewordp. xi
Prefacep. xiii
Acknowledgmentsp. xvii
Introductionp. 1
Creating and Destroying Objectsp. 5
Consider static factory methods instead of constructorsp. 5
Consider a builder when faced with many constructorparametersp. 11
Enforce the singleton property with a private constructorp. 17
Enforce noninstantiability with a private constructorp. 19
Avoid creating unnecessary objectsp. 20
Eliminate obsolete object referencesp. 24
Avoid finalizersp. 27
Methods Common to All Objectsp. 33
Obey the general contract when overriding equalsp. 33
Always override hashCode when you override equalsp. 45
Always override toStringp. 51
Override clone judiciouslyp. 54
Consider implementing Comparablep. 62
Classes and Interfacesp. 67
Minimize the accessibility of classes and membersp. 67
In public classes, use accessor methods, not public fieldsp. 71
Minimize mutabilityp. 73
Favor composition over inheritancep. 81
Design and document for inheritance or else prohibit itp. 87
Prefer interfaces to abstract classesp. 93
Use interfaces only to define typesp. 98
Prefer class hierarchies to tagged classesp. 100
Use function objects to represent strategiesp. 103
Favor static member classes over nonstaticp. 106
Genericsp. 109
Don't use raw types in new codep. 109
Eliminate unchecked warningsp. 116
Prefer lists to arraysp. 119
Favor generic typesp. 124
Favor generic methodsp. 129
Use bounded wildcards to increase API flexibilityp. 134
Consider typesafe heterogeneous containersp. 142
Enums and Annotationsp. 147
Use enums instead of int constantsp. 147
Use instance fields instead of ordinalsp. 158
Use EnumSet instead of bit fieldsp. 159
Use EnumMap instead of ordinal indexingp. 161
Emulate extensible enums with interfacesp. 165
Prefer annotations to naming patternsp. 169
Consistently use the Override annotationp. 176
Use marker interfaces to define typesp. 179
Methodsp. 181
Check parameters for validityp. 181
Make defensive copies when neededp. 184
Design method signatures carefullyp. 189
Use overloading judiciouslyp. 191
Use varargs judiciouslyp. 197
Return empty arrays or collections, not nullsp. 201
Write doc comments for all exposed API elementsp. 203
General Programmingp. 209
Minimize the scope of local variablesp. 209
Prefer for-each loops to traditional for loopsp. 212
Know and use the librariesp. 215
Avoid float and double if exact answers are requiredp. 218
Prefer primitive type
Table of Contents provided by Publisher. All Rights Reserved.


Preface to the Second EditionA lot has happened to the Java platform since I wrote the first edition of this book in 2001, and it's high time for a second edition. The most significant set of changes was the addition of generics, enum types, annotations, autoboxing, and the for-each loop in Java 5. A close second was the addition of the new concurrency library, java.util.concurrent , also released in Java 5. With Gilad Bracha, I had the good fortune to lead the teams that designed the new language features. I also had the good fortune to serve on the team that designed and developed the concurrency library, which was led by Doug Lea.The other big change in the platform is the widespread adoption of modern Integrated Development Environments (IDEs), such as Eclipse, IntelliJ IDEA, and NetBeans, and of static analysis tools, such as FindBugs. While I have not been involved in these efforts, I've benefited from them immensely and learned how they affect the Java development experience.In 2004, I moved from Sun to Google, but I've continued my involvement in the development of the Java platform over the past four years, contributing to the concurrency and collections APIs through the good offices of Google and the Java Community Process. I've also had the pleasure of using the Java platform to develop libraries for use within Google. Now I know what it feels like to be a user.As was the case in 2001 when I wrote the first edition, my primary goal is to share my experience with you so that you can imitate my successes while avoiding my failures. The new material continues to make liberal use of real-world examples from the Java platform libraries.The first edition succeeded beyond my wildest expectations, and I've done my best to stay true to its spirit while covering all of the new material that was required to bring the book up to date. It was inevitable that the book would grow, and grow it did, from fifty-seven items to seventy-eight. Not only did I add twenty-three items, but I thoroughly revised all the original material and retired a few items whose better days had passed. In the Appendix, you can see how the material in this edition relates to the material in the first edition.In the Preface to the First Edition, I wrote that the Java programming language and its libraries were immensely conducive to quality and productivity, and a joy to work with. The changes in releases 5 and 6 have taken a good thing and made it better. The platform is much bigger now than it was in 2001 and more complex, but once you learn the patterns and idioms for using the new features, they make your programs better and your life easier. I hope this edition captures my continued enthusiasm for the platform and helps make your use of the platform and its new features more effective and enjoyable.San Jose, California April 2008

Rewards Program

Write a Review