Summary of Effective Java 3rd Edition by Joshua Bloch
7 min readJun 9, 2023
“Effective Java” is a well-known book by Joshua Bloch, which covers best practices, patterns, and idioms for writing high-quality Java code. The third edition of the book contains 90 items organised into 11 chapters. I have tried to summarise each item, chapter-wise:
Creating and Destroying Objects
- Consider static factory methods instead of constructors: Static factory methods offer benefits over public constructors, such as meaningful names, easy caching, and control over object creation.
- Consider a builder when faced with many constructor parameters: Builders provide a more readable and flexible way to construct objects with multiple parameters.
- Enforce the singleton property with a private constructor or an enum type: Ensure that only one instance exists by using a private constructor or an enum type singleton.
- Enforce non instantiability with a private constructor: Prevent object instantiation in utility classes by using a private constructor.
- Prefer dependency injection to hardwiring resources: Configure objects with dependencies rather than creating them directly, improving modularity and testability.
- Avoid creating unnecessary objects: Use existing objects or immutables…