How Can We Help?

Effective Java (Book)

You are here:
< Back

Effective Java Book Cover

Effective Java

Creating and Destroying Objects

1. Consider states factory methods instead of constructors
2. Consider a builder when faced with many constructor parameters
3. Enforce the singleton property with a private constructor or enum type
4. Enforce nonistantiability with a private constructors
5. Avoid creating unnecessary objects
6. Eliminate obsolete objects references
7. Avoid finalizers

Methods Common to All Objects

8. Obey the general contract when overriding equals
9. Always override hashCode when you override equals
10. Always override toString
11. Overide clone judiciously
12. Consider implementing Comparable
13. Minimise the accessibility of classes and members
14. In public classes, use accessor methods, not public fields
15. Minimize mutability
16. Favour composition over inheritance
17. Design and document for inheritance or else prohibit it
18. Prefer interfaces to abstract classes
19. User interfaces to define types
20. Prefer class hierarchies to tagged classes
21. use function objects to represent strategies
22. Favour static member classes over non static


23. Don;t use raw types in new code
24. Elimiate unchecked warnings
25. Prefer lists to arrays
26. Favuor generic types
27. Favour generic methods
28. Use bounded wildcards to increase API flexibility
29. Consider type safe heteregenous containers

Enums and Annotations

30. Use enums instead of int constants
31. Use instance fields instead of ordinals
32. Use EnumSet instead of bit fields
33. Use EnumMap instead of ordinal indexing
34. Emulate extensible enums with interfaces
35. Prefer annotations to naming patterns
36. Consistently use the Override annotations
37. Use marker interfaces to define types


38. Check parameters for vailidity
39. Make defensive copies when needed
40. Design method signatures carefully
41. Over overloaded judiciously
42. Use varargs judiciously
43. Return empty arrays or collections, not null
44. Write doc comments for all exposed API methods

General Programming

45. Minimise the scope of local variables
46. Prefer for-each loops to traditional for loops
47. Know and use all the libraries
48. Avoid float and double if exact answers are required
49. Prefer primitive types to boxed primitives
50. Avoid strings where other types are more appropriate
51. Beware the performance of string concatenation
52. Refer to objects by their interfaces
53. Prefer interfaces to reflection
54. Use native methods judiciously
55. optimise judiciously
56. Adhere to generally accepted naming conventions


57. Use exceptions only for exceptional conditions
58. use checked exceptions for recoverable conditions and runtime exceptions for programming errors
59. Avoid unecessary use of checked exceptions
60. Favour the use of standard exceptions
61. Throw exceptions appropriate to the abstraction
62. Document all exceptions thrown by each method
63. Include failure-capture information in detail messages
64. Strive for failure atomicity
65. Don’t ignore exceptions


66. Synchronise access to shared mutable data
67. Avoid excessive synchronisation
68. Prefer executors and tasks to threads
69. prefer concurrency utilities to wait and notify
70. Document thread safety
71. Use lazy initialisation judiciously
72. Dont depend on the thread scheduler
73. Avoid thread groups


74. Implement Serializable judiciously
75. Consider using a custom serialized form
76. Write readObject methods defensively
77. For instance control, prefer enum types to readResolve
78. Consider serialization proxies instead of serialized instances


Useful Links

(Visited 175 times, 1 visits today)
Effective Java (Book)
Next Patterns of Enterprise Application Architecture
Table of Contents
InstagramPlease check your feed, the data was entered incorrectly.