Effective Java¶
Author: Joshua Bloch
Edition: 3rd Edition (2018)
Priority: #1 Must-Read
Overview¶
The definitive guide to Java programming best practices, written by one of the language's key designers. This book should be read multiple times throughout your Java journey, with different items becoming relevant at different stages.
Book Structure¶
| Chapter | Items | Related Notes |
|---|---|---|
| Creating and Destroying Objects | 1-9 | OOP & Class Design |
| Methods Common to All Objects | 10-14 | OOP & Class Design |
| Classes and Interfaces | 15-25 | OOP & Class Design |
| Generics | 26-33 | Abstraction, Interfaces & Generics |
| Enums and Annotations | 34-41 | Arrays, Lists & Autoboxing |
| Lambdas and Streams | 42-48 | Lambdas & Streams |
| Methods | 49-56 | Syntax & Control Flow |
| General Programming | 57-68 | Syntax & Control Flow |
| Exceptions | 69-77 | Phase 1 Advanced |
| Concurrency | 78-84 | Phase 2 - Advanced Java |
| Serialization | 85-90 | Phase 2 - Advanced Java |
Phase 1 Items to Focus On¶
Creating and Destroying Objects (Items 1-9)¶
- Item 1: Consider static factory methods
- Item 2: Consider a builder for many parameters
- Item 3: Enforce singleton with private constructor or enum
- Item 7: Eliminate obsolete object references
Classes and Interfaces (Items 15-25)¶
- Item 15: Minimize accessibility
- Item 17: Minimize mutability
- Item 18: Favor composition over inheritance
- Item 20: Prefer interfaces to abstract classes
Generics (Items 26-33)¶
- Item 26: Don't use raw types
- Item 28: Prefer lists to arrays
- Item 31: Use bounded wildcards (PECS)
Enums and Annotations (Items 34-39)¶
- Item 34: Use enums instead of int constants
- Item 35: Use instance fields instead of ordinals
- Item 36: Use EnumSet instead of bit fields
- Item 37: Use EnumMap instead of ordinal indexing
Lambdas and Streams (Items 42-48)¶
- Item 42: Prefer lambdas to anonymous classes
- Item 43: Prefer method references to lambdas
- Item 45: Use streams judiciously
- Item 46: Prefer side-effect-free functions
General Programming (Items 57-68)¶
- Item 57: Minimize scope of local variables
- Item 58: Prefer for-each loops
- Item 61: Prefer primitives to boxed primitives
Reading Strategy¶
- First Pass (During Phase 1): Read items related to fundamentals
- Second Pass (During Phase 2): Read concurrency and advanced items
- Third Pass (During Projects): Reference specific items as needed
- Ongoing: Keep the book handy as a reference