Cover image for Effective Java : programming language guide
Title:
Effective Java : programming language guide
Author:
Bloch, Joshua.
Personal Author:
Publication Information:
Boston : Addison-Wesley, [2001]

©2001
Physical Description:
xvi, 252 pages ; 24 cm.
Language:
English
Contents:
1. Introduction -- 2. Creating and Destroying Objects -- 3. Methods Common to All Objects -- 4. Classes and Interfaces -- 5. Substitutes for C Constructs -- 6. Methods -- 7. General Programming -- 8. Exceptions -- 9. Threads -- 10. Serialization.
ISBN:
9780201310054
Format :
Book

Available:*

Library
Call Number
Material Type
Home Location
Status
Central Library QA76.73.J38 B57 2001 Adult Non-Fiction Central Closed Stacks
Searching...

On Order

Summary

Summary

--Gilad Bracha, Computational Theologist, Sun Microsystems, Inc., and co-author of The Java Language Specification, Second Edition I sure wish I had this book ten years ago. Some might think that I dont need any Java books, but I need this one. --James Gosling, Fellow and Vice President, Sun Microsystems, Inc., and inventor of the Java programming language Are you looking for a concise book packed with insight and wisdom not found elsewhere? Need to really understand the Java programming language; that is, really understand it? Do you want to write code that is clear, correct, robust, and reusable? Look no further The book you are holding will provide you with this and many other benefits you may not even know you were looking for. Become a more effective programmer. Featuring fifty-seven valuable rules of thumb, Effective Java Programming Language Guide contains working solutions to the programming challenges most developers encounter every day. Offering comprehensive descriptions of techniques used by the experts who developed the Java platform, the book reveals what to do--and what not to do--in order to produce clear, robust, and efficient code. Each rule appears in the form


Author Notes

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.




Excerpts

Excerpts

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 Excerpted from Effective Java Programming Language by Joshua Bloch All rights reserved by the original copyright owners. Excerpts are provided for display purposes only and may not be reproduced, reprinted or distributed without the written permission of the publisher.

Table of Contents

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

Google Preview