Effective Java[TM], second edition 9780321356680, 0321356683

Are you looking for a deeper understanding of the Java(TM) programming language so that you can write code that is clear

431 75 3MB

English Pages 346 [374] Year 2008

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Cover......Page 1
Contents......Page 10
Foreword......Page 14
Preface......Page 16
Acknowledgments......Page 20
1 Introduction......Page 24
Item 1: Consider static factory methods instead of constructors......Page 28
Item 2: Consider a builder when faced with many constructor parameters......Page 34
Item 3: Enforce the singleton property with a private constructor or an enum type......Page 40
Item 4: Enforce noninstantiability with a private constructor......Page 42
Item 5: Avoid creating unnecessary objects......Page 43
Item 6: Eliminate obsolete object references......Page 47
Item 7: Avoid finalizers......Page 50
Item 8: Obey the general contract when overriding equals......Page 56
Item 9: Always override hashCode when you override equals......Page 68
Item 10: Always override toString......Page 74
Item 11: Override clone judiciously......Page 77
Item 12: Consider implementing Comparable......Page 85
Item 13: Minimize the accessibility of classes and members......Page 90
Item 14: In public classes, use accessor methods, not public fields......Page 94
Item 15: Minimize mutability......Page 96
Item 16: Favor composition over inheritance......Page 104
Item 17: Design and document for inheritance or else prohibit it......Page 110
Item 18: Prefer interfaces to abstract classes......Page 116
Item 19: Use interfaces only to define types......Page 121
Item 20: Prefer class hierarchies to tagged classes......Page 123
Item 21: Use function objects to represent strategies......Page 126
Item 22: Favor static member classes over nonstatic......Page 129
Item 23: Don’t use raw types in new code......Page 132
Item 24: Eliminate unchecked warnings......Page 139
Item 25: Prefer lists to arrays......Page 142
Item 26: Favor generic types......Page 147
Item 27: Favor generic methods......Page 152
Item 28: Use bounded wildcards to increase API flexibility......Page 157
Item 29: Consider typesafe heterogeneous containers......Page 165
Item 30: Use enums instead of int constants......Page 170
Item 31: Use instance fields instead of ordinals......Page 181
Item 32: Use EnumSet instead of bit fields......Page 182
Item 33: Use EnumMap instead of ordinal indexing......Page 184
Item 34: Emulate extensible enums with interfaces......Page 188
Item 35: Prefer annotations to naming patterns......Page 192
Item 36: Consistently use the Override annotation......Page 199
Item 37: Use marker interfaces to define types......Page 202
Item 38: Check parameters for validity......Page 204
Item 39: Make defensive copies when needed......Page 207
Item 40: Design method signatures carefully......Page 212
Item 41: Use overloading judiciously......Page 214
Item 42: Use varargs judiciously......Page 220
Item 43: Return empty arrays or collections, not nulls......Page 224
Item 44: Write doc comments for all exposed API elements......Page 226
Item 45: Minimize the scope of local variables......Page 232
Item 46: Prefer for-each loops to traditional for loops......Page 235
Item 47: Know and use the libraries......Page 238
Item 48: Avoid float and double if exact answers are required......Page 241
Item 49: Prefer primitive types to boxed primitives......Page 244
Item 50: Avoid strings where other types are more appropriate......Page 247
Item 51: Beware the performance of string concatenation......Page 250
Item 52: Refer to objects by their interfaces......Page 251
Item 53: Prefer interfaces to reflection......Page 253
Item 54: Use native methods judiciously......Page 256
Item 55: Optimize judiciously......Page 257
Item 56: Adhere to generally accepted naming conventions......Page 260
Item 57: Use exceptions only for exceptional conditions......Page 264
Item 58: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors......Page 267
Item 59: Avoid unnecessary use of checked exceptions......Page 269
Item 60: Favor the use of standard exceptions......Page 271
Item 61: Throw exceptions appropriate to the abstraction......Page 273
Item 62: Document all exceptions thrown by each method......Page 275
Item 63: Include failure-capture information in detail messages......Page 277
Item 64: Strive for failure atomicity......Page 279
Item 65: Don’t ignore exceptions......Page 281
Item 66: Synchronize access to shared mutable data......Page 282
Item 67: Avoid excessive synchronization......Page 288
Item 68: Prefer executors and tasks to threads......Page 294
Item 69: Prefer concurrency utilities to wait and notify......Page 296
Item 70: Document thread safety......Page 301
Item 71: Use lazy initialization judiciously......Page 305
Item 72: Don’t depend on the thread scheduler......Page 309
Item 73: Avoid thread groups......Page 311
Item 74: Implement Serializable judiciously......Page 312
Item 75: Consider using a custom serialized form......Page 318
Item 76: Write readObject methods defensively......Page 325
Item 77: For instance control, prefer enum types to readResolve......Page 331
Item 78: Consider serialization proxies instead of serialized instances......Page 335
Appendix: Items Corresponding to First Edition......Page 340
References......Page 344
A......Page 350
B......Page 351
C......Page 352
E......Page 355
F......Page 358
I......Page 359
L......Page 361
N......Page 362
P......Page 363
R......Page 364
S......Page 365
T......Page 367
U......Page 368
W......Page 369

Effective Java[TM], second edition
 9780321356680, 0321356683

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers