Home > Store > Programming > Java

larger cover

Add To My Wish List

Effective Java™ Programming Language Guide

Register your product to gain access to bonus material or receive a coupon.

  • Description
  • Extras
  • Reviews
  • Sample Content
  • Updates

PTR Overview

Effective Java Programming Language Guide distills the hard-won wisdom of today's best Java programmers into 50 techniques for designing and constructing more robust, high-performance software. Josh Bloch, one of Sun's most widely respected Java developers, focuses on the practical problems virtually every Java developer encounters, offering specific solutions and top-notch code examples.KEY TOPICS:Josh Bloch identifies 50 practices that lead directly to better code -- including better alternatives for common practices that have proven undesirable in real-world development. The techniques are specific, thoroughly explained, and supported by top-notch code examples. Among the highlights: why developers should avoid finalizers; when to use delegation instead of inheritance; and how to make the most of Java's powerful typesafe enum pattern. Nearly all 50 practices relate to the "core" of the Java platform -- the language itself -- making the book relevant to virtually every Java developer.MARKET:For all experienced Java programmers, and for C++ programmers who want to maximize their Java expertise and productivity as quickly as possible.

PTR Bullets

50 powerful techniques for improving every Java program and design!

  • The book that does for Java what Scott Meyers' Effective C++ does for C++.
  • Top-notch code examples and real-world Java development "war stories."
  • This is the "most asked for" book!

Product Author Bios

Joshua Bloch is a principal engineer at Google and a Jolt Award-winner. He was previously a distinguished engineer at Sun Microsystems and a senior systems designer at Transarc. Josh led the design and implementation of numerous Java platform features, including JDK 5.0 language enhancements and the award-winning Java Collections Framework. He holds a Ph.D. in computer science from Carnegie Mellon University.



A new edition of this title is available, ISBN-10: 0321356683 ISBN-13: 9780321356680

Customer Reviews

194 of 197 people found the following review helpful
5.0 out of 5 stars This is what you need to know to become a Java guru!, September 5, 2001
By 
Doug Bell "Java guru" (San Diego, CA USA) - See all my reviews
(REAL NAME)   
Amazon Verified Purchase(What's this?)
This review is from: Effective Java: Programming Language Guide (Java Series) (Paperback)
This book contains a generous cross-section of the knowledge that differentiates Java gurus from advanced Java programmers.

I've been working full-time in Java since 1995, prior to version 1.0. I've also written books and articles on Java and have been teaching Java at the University level as a sideline for four years. In that time I've accumulated a great deal of "expert" knowledge about the language, the JVM, and the APIs and developed opinions on the best approaches to use in Java. At this point, reading books such as this that contain a collection of tips and advice I am usually satisfied to gain one new piece of knowledge; I learned at least six new things from this book.

Of the 50+ books on Java I've read, this book contains by far the most comprehensive and useful collection of that hard-won knowledge of core Java. The bonus is the clear and concise manner in which it is presented.

Bloch is dead-on. There isn't a single factual error or piece of bad advice... Read more

Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No


31 of 31 people found the following review helpful
5.0 out of 5 stars The best book on how to program in Java, July 25, 2001
By 
This review is from: Effective Java: Programming Language Guide (Java Series) (Paperback)
I spend a lot of time thinking and talking about programming, languages, style, etc. This book is without question the best thing I've read about how to program in Java.

The book contains 57 suggestions on what to do or not to do when writing Java code. Most are common sense, though not all -- the material on serialization was new to me, for example. But it's common sense that's developed over time, and much of it is not obvious until you have a lot of experience using the language. Even then, it's worth reading; I consider myself a fairly experienced Java programmer, and I'd say that a quarter of the book was new material for me. Even when I knew a technique he was recommending, it was really good to read the arguments Bloch made for doing something in a particular way. And I found that I agree with almost everything he wrote.

The book is very Java-specific. Some of the tips generalize to other, similar, object-oriented languages, or to systems with similar thread models,... Read more

Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No


23 of 23 people found the following review helpful
5.0 out of 5 stars Brilliant, succinct and highly professional, May 2, 2002
By 
Goldin Evgeny (Berlin, Germany) - See all my reviews
(REAL NAME)   
This review is from: Effective Java: Programming Language Guide (Java Series) (Paperback)
IMHO, The Java Bible is out. It is that simple. I think this book deserves no
less popularity and respect than "Effective C++" which set the high standard
to the "Effective" series.

It's definitely not a beginners book, this is the book that core Java developers
should memorize by heart. This book is written by the Sun expert who both
design and develop Java run-time libraries (Collections, in particular, which is
one of the prettiest species in Java) and is definitely aware of their successes
and failures. Out of his experience Joshua brings hundreds of "how about this"
unexpectable situations - those I doubt you was ever thinking of before.

It contains 57 issues covering topics about:
- creating objects (how about static factories vs constructors ?)
- methods common to all objects (ever thought that overriding clone, equals, hashCode
and toString is easy ?),
- designing interfaces of your classes and interfaces (ever... Read more

Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No


Share your thoughts with other customers:
 See all 120 customer reviews...

Praise For Effective Java™ Programming Language Guide

"Anyone aspiring to write good JAVA code that others will appreciate reading and maintaining should be required to own a copy of this book. This is one of those rare books where the information won't become obsolete with subsequent release of the JDK library. A definite must-have for any JAVA developer/ programmer." - JavaRanch.com

"Effective Java is the best Java book in years and simply essential to every Java programmer from intermediate to advanced level…this book is incredibly informative and very well written." - Comp.Lang.Java. Programmer Newsgroup

"I sure wish I had had this book ten years ago. Some might think that I don't need any Java books, but I need this one." - James Gosling, Fellow and Vice President, Sun Microsystems, Inc.

"An excellent book, crammed with good advice on using the Java programming language and object-oriented programming in general." - Gilad Bracha, Computational Theologist, Sun Microsystems, Inc., and co-author of The Java Language Specification, Second Edition

"Effective Java Programming Language Guide is the best Java book in years and simply essential to every Java programmer from intermediate to advanced level…this book is incredibly informative and very well written."- comp.lang.java.programmer Newsgroup, August 2001

10/10 rating: "Anyone aspiring to write good JAVA code that others will appreciate reading and maintaining should be required to own a copy of this book. This is one of those rare books where the information won't become obsolete with subsequent release of the JDK library. A definite must-have for any JAVA developer/programmer." - JavaRanch.com, August 2001

"Anyone aspiring to write good JAVA code that others will appreciate reading and maintaining should be required to own a copy of this book. This is one of those rare books where the information won't become obsolete with subsequent release of the JDK library. A definite must-have for any JAVA developer/programmer." - JavaRanch.com, August 2001

"This is the Java book that I need...I tend to get caught up in the heat of the hack and slap stuff together that doesn’t stand the test of time. For me, one of the big values of the books is as something to re-read and remind myself of the True Path”-James Gosling, Fellow and Vice President, Sun Microsystems Inc., September 2001

“My favorite recently published book is Effective Java...This second generation book patterned after Meyer’s Effective C++ is aimed at intermediate to more advanced Java developers. It is filled with excellent examples and outstanding advice." -Richard S. Wiener, Editor, Journal of Object-Oriented Programming (JOOP), September 2001

"[This] is the book that James Gosling recommended to his conference-goers during his keynote address at JavaOne 2001...We can say upfront that this is an excellent book. In fact, compared to other books in the same league, this is one of the best so far...It is an excellent book and a must-read for serious Java programmers..."-DevX: Java Zone, September 2001

Online Sample Chapter

Java Methods

Table of Contents



Foreword.


Preface.


Acknowledgements.


1. Introduction.


2. Creating and Destroying Objects.

Consider Providing Static Factory Methods Instead of Constructors.

Enforce the Singleton Property with a Private Constructor.

Enforce Noninstantiability with a Private Constructor.

Avoid Creating Duplicate Objects.

Eliminate Obsolete Object References.

Avoid Finalizers.



3. Methods Common to All Objects.

Obey the General Contract when Overriding Equals.

Always Override HashCode When You Override Equals.

Always Override to String.

Override Clone Judiciously.

Consider Implementing Comparable.



4. Classes and Interfaces.

Minimize the Accessibility of Classes and Members.

Favor Immutability.

Favor Composition Over Inheritance.

Design and Document for Inheritance or Else Prohibit It.

Prefer Interfaces to Abstract Classes.

Use Interfaces Only to Define Types.

Favor Static Member Classes Over Non-Static.



5. Substitutes for C Constructs.

Replace Structures with Classes.

Replace Unions with Class Hierarchies.

Replace Enums with Classes.

Replace Function Pointers with Classes and Interfaces.



6. Methods.

Check Parameters for Validity.

Make Defensive Copies when Needed.

Design Method Signatures Carefully.

Use Overloading Judiciously.

Return Zero-Length Arrays, Not Nulls.

Write Doc Comments for All Exposed API Elements.



7. General Programming.

Minimize the Scope of Local Variables.

Know and Use the Libraries.

Avoid Float and Double if Exact Answers are Required.

Avoid Strings where Other Types are More Appropriate.

Beware the Performance of String Concatenation.

Refer to Objects by their Interfaces.

Prefer Interfaces to Reflection.

Use Native Methods Judiciously.

Optimize Judiciously.

Adhere to Generally Accepted Naming Conventions.



8. Exceptions.

Use Exceptions Only for Exceptional Conditions.

Use Checked Exceptions for Recoverable Conditions, Runtime Exceptions for Programming Errors.

Avoid Unnecessary Use of Checked Exceptions.

Favor the Use of Standard Exceptions.

Throw Exceptions Appropriate to the Abstraction.

Document All Exceptions Thrown by Each Method.

Include Failure-Capture Information in Detail Messages.

Strive for Failure Atomicity.

Don't Ignore Exceptions.



9. Threads.

Synchronize Access to Shared Mutable Data.

Avoid Excessive Synchronization.

Never Invoke Wait Outside a Loop.

Don't Depend on the Thread Scheduler.

Document Thread-Safety.

Avoid Thread Groups.



10. Serialization.

Implement Serializable Judiciously.

Consider Using a Custom Serialized Form.

Write ReadObject Methods Defensively.

Provide a ReadResolve Method when Necessary.



References.


Index.

Preface

In 1996 I pulled up stakes and headed west to work for JavaSoft, as it was then known, because it was clear that was where the action was. In the intervening five years I've served as Java Platform Libraries Architect. I've designed, implemented and maintained many of the libraries, and served as a consultant for many others. Presiding over these libraries as the Java platform matured was a once-in-a-lifetime opportunity. It is no exaggeration to say that I had the privilege to work with some of the great software engineers of our generation. In the process, I learned a lot about the Java programming language--what works, what doesn't, and how to use the language and its libraries to best effect.

This book is my attempt to share my experience with you, so that you can imitate my successes while avoiding my failures. I borrowed the format from Scott Meyers's Effective C++ Meyers98, which consists of fifty items, each conveying one specific rule for improving your programs and designs. I found the format to be singularly effective and I hope you do too.

In many cases, I took the liberty of illustrating the items with real-world examples from the Java platform libraries. When describing something that could have been done better, I tried to pick on code that I wrote myself, but occasionally I pick on something written by a colleague. I sincerely apologize if, despite my best efforts, I've offended anyone. Negative examples are cited not to cast blame but in the spirit of cooperation, so that all of us can benefit from the experience of those who've gone before.

While this book is not targeted solely at developers of reusable components, it is inevitably colored by my experience writing such components over the past two decades. I naturally think in terms of exported APIs (Application Programming Interfaces) and I encourage you to do likewise. Even if you aren't developing reusable components, thinking in these terms tends to improve the quality of the software you write. Furthermore, it's not uncommon to write a reusable component without knowing it: you write something useful, share it with your buddy across the hall, and before long you have half a dozen users. At this point, you no longer have the flexibility to change the API at will, and are thankful for all the effort that you put into designing the API when you first wrote the software.

My focus on API design may seem a bit unnatural to devotees of the new lightweight software development methodologies, such as Extreme Programming Explained Beck99. These methodologies emphasize writing the simplest program that could possibly work. If you're using one of these methodologies you'll find that a focus on API design serves you well in the refactoring process. The fundamental goals of refactoring are the improvement of system structure and the avoidance of code duplication. These goals are impossible to achieve in the absence of well-designed APIs for the components of the system.

No language is perfect, but some of them are excellent. I have found the Java programming language and its libraries to be immensely conducive to quality and productivity, and a joy to work with. I hope this book captures my enthusiasm and helps make your use of the language more effective and enjoyable.

Josh Bloch
Cupertino, California
April, 2001


0201310058P04232001

Downloadable Sample Chapter

Click below for Sample Chapter related to this title:
blochch6.pdf

blochch7.pdf

ch7generalp.pdf

steeleforewordbloch.pdf

Index

A

abstract classes
adding an aspect to, 31
as replacement for discriminated union, 101
designing for inheritance, 82
evolution of, vs. interfaces, 88
examples
adding behaviors to typesafe enum, 108
replacement for discriminated union, 101
skeletal implementation, 87
static member class, 94
for adding behaviors to typesafe enum, 108
for service provider framework, 8
for skeletal implementations, 82, 85
noninstantiability and, 12
vs. interfaces, 84-88
access control, 60
access levels, 3
method overriding and, 61
of classes and interfaces, 60
of constants, 61
of members, 60
of static member classes, 91
readResolve and, 232
accessor methods, 98
defensive copies and, 63, 124
examples
defensive copies, 124
immutability, 64
for failure-capture information, 173, 184
for information returned by toString, 44
for lower-level exception, 179
immutability and, 63
naming conventions for, 167
vs. public fields, 98-99, 103
alien methods, 196
deadlock and, 196-199
example, 197
safety failures and, 199
anonymous classes, 91, 93-94
as concrete strategy classes, 116
as function objects, 127
examples
finalizer guardian, 23
in adapters, 86

Errata

Click below for Errata related to this title:
Errata

 
Purchase Reward: One Month Free Subscription
By completing any purchase on InformIT, you become eligible for an unlimited access one-month subscription to Safari Books Online.

Get access to thousands of books and training videos about technology, professional development and digital media from more than 40 leading publishers, including Addison-Wesley, Prentice Hall, Cisco Press, IBM Press, O'Reilly Media, Wrox, Apress, and many more. If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months. That's a total savings of $199.