Personal tools
User menu

Knowledge Base/Java/Effective Java

From Thalesians

Jump to: navigation, search

This is essentially the table of contents of Joshua Bloch's book Effective Java. The same table of contents is available on, but not on (check out the "Look Inside" feature). In our view, every serious Java programmer should read Joshua's book. Of course, you need to read the entire book. The chapter titles will only make sense if you have read it. If you haven't read it and the titles still make sense, you are still missing a lot. We would read the entire book.


Creating and destroying objects

  1. Consider providing static factory methods instead of constructors
  2. Enforce the singleton property with a private constructor
  3. Enforce noninstantiability with a private constructor
  4. Avoid creating duplicate objects
  5. Eliminate obsolete object references
  6. Avoid finalizers

Methods common to all objects

  1. Obey the general contract when overriding equals
  2. Always override hashCode when you override equals
  3. Always override toString
  4. Override clone judiciously
  5. Consider implementing Comparable

Classes and interfaces

  1. Minimize the accessibility of classes and members
  2. Favour immutability
  3. Favour composition over inheritance
  4. Design and document for inheritance or else prohibit it
  5. Prefer interfaces to abstract classes
  6. Use interfaces only to define types
  7. Favour static member classes over nonstatic

Substitutes for C constructs

  1. Replace structures with classes
  2. Replace unions with class hierarchies
  3. Replace enum constructs with classes
  4. Replace function pointers with classes and interfaces


  1. Check parameters for validity
  2. Make defensive copies when needed
  3. Design method signatures carefully
  4. Use overloading judiciously
  5. Return zero-length arrays, not nulls
  6. Write doc comments for all exposed API elements

General programming

  1. Minimise the scope of local variables
  2. Know and use the libraries
  3. Avoid float and double if exact answers are required
  4. Avoid strings where other types are more appropriate
  5. Beware the performance of string concatenation
  6. Refer to objects by their interfaces
  7. Prefer interfaces to reflection
  8. Use native methods judiciously
  9. Optimise judiciously
  10. Adhere to generally accepted naming conventions


  1. Use exceptions only for exceptional conditions
  2. Use checked exceptions for recoverable conditions and run-time exceptions for programming errors
  3. Avoid unnecessary use of checked exceptions
  4. Favour the use of standard exceptions
  5. Throw exceptions appropriate to the abstraction
  6. Document all exceptions thrown by each method
  7. Include failure-capture information in detail messages
  8. Strive for failure atomicity
  9. Don't ignore exceptions


  1. Synchronize access to shared mutable data
  2. Avoid excessive synchronisation
  3. Never invoke wait outside a loop
  4. Don't depend on the thread scheduler
  5. Document thread safety
  6. Avoid thread groups


  1. Implement Serializable judiciously
  2. Consider using a custom serialised form
  3. Write readObject methods defensively
  4. Provide a readResolve method when necessary
  • This page was last modified on 13 January 2009, at 18:48.
  • This page has been accessed 18,933 times.