You are previewing Effective Java™: Programming Language Guide.
O'Reilly logo
Effective Java™: Programming Language Guide

Book Description

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

Table of Contents

  1. Copyright
    1. Dedication
  2. Foreword
  3. Preface
  4. Acknowledgments
  5. 1. Introduction
  6. 2. Creating and Destroying Objects
    1. Item 1: Consider providing static factory methods instead of constructors
    2. Item 2: Enforce the singleton property with a private constructor
    3. Item 3: Enforce noninstantiability with a private constructor
    4. Item 4: Avoid creating duplicate objects
    5. Item 5: Eliminate obsolete object references
    6. Item 6: Avoid finalizers
  7. 3. Methods Common to All Objects
    1. Item 7: Obey the general contract when overriding equals
    2. Item 8: Always override hashCode when you override equals
    3. Item 9: Always override toString
    4. Item 10: Override clone judiciously
    5. Item 11: Consider implementing Comparable
  8. 4. Classes and Interfaces
    1. Item 12: Minimize the accessibility of classes and members
    2. Item 13: Favor immutability
    3. Item 14: Favor composition over inheritance
    4. Item 15: Design and document for inheritance or else prohibit it
    5. Item 16: Prefer interfaces to abstract classes
    6. Item 17: Use interfaces only to define types
    7. Item 18: Favor static member classes over nonstatic
  9. 5. Substitutes for C Constructs
    1. Item 19: Replace structures with classes
    2. Item 20: Replace unions with class hierarchies
    3. Item 21: Replace enum constructs with classes
    4. Item 22: Replace function pointers with classes and interfaces
  10. 6. Methods
    1. Item 23: Check parameters for validity
    2. Item 24: Make defensive copies when needed
    3. Item 25: Design method signatures carefully
    4. Item 26: Use overloading judiciously
    5. Item 27: Return zero-length arrays, not nulls
    6. Item 28: Write doc comments for all exposed API elements
  11. 7. General Programming
    1. Item 29: Minimize the scope of local variables
    2. Item 30: Know and use the libraries
    3. Item 31: Avoid float and double if exact answers are required
    4. Item 32: Avoid strings where other types are more appropriate
    5. Item 33: Beware the performance of string concatenation
    6. Item 34: Refer to objects by their interfaces
    7. Item 35: Prefer interfaces to reflection
    8. Item 36: Use native methods judiciously
    9. Item 37: Optimize judiciously
    10. Item 38: Adhere to generally accepted naming conventions
  12. 8. Exceptions
    1. Item 39:Use exceptions only for exceptional conditions
    2. Item 40:Use checked exceptions for recoverable conditions and run-time exceptions for programming errors
    3. Item 41:Avoid unnecessary use of checked exceptions
    4. Item 42:Favor the use of standard exceptions
    5. Item 43: Throw exceptions appropriate to the abstraction
    6. Item 44:Document all exceptions thrown by each method
    7. Item 45:Include failure-capture information in detail messages
    8. Item 46:Strive for failure atomicity
    9. Item 47:Don't ignore exceptions
  13. 9. Threads
    1. Item 48: Synchronize access to shared mutable data
    2. Item 49: Avoid excessive synchronization
    3. Item 50: Never invoke wait outside a loop
    4. Item 51: Don't depend on the thread scheduler
    5. Item 52: Document thread safety
    6. Item 53: Avoid thread groups
  14. 10. Serialization
    1. Item 54: Implement Serializable judiciously
    2. Item 55:Consider using a custom serialized form
    3. Item 56:Write readObject methods defensively
    4. Item 57: Provide a readResolve method when necessary
  15. References