Effective-Java-3rd-edition-Chinese-English-bilingual
This is a Chinese and English learning reference for each chapter of Effective Java (3rd Edition). I hope it will be helpful to improve Java technology. Suggestions and modifications are welcome through issue or PR.
Contents
- Chapter 2. Creating and Destroying Objects
- Chapter 2 Introduction
- Item 1: Consider static factory methods instead of constructors (Consider static factory methods instead of constructors)
- Item 2: Consider a builder when faced with many constructor parameters
- Item 3: Enforce the singleton property with a private constructor or an enum type (use a private constructor or an enum type to implement a singleton property)
- Item 4: Enforce noninstantiability with a private constructor (use a private constructor to implement non-instantiability)
- Item 5: Prefer dependency injection to hardwiring resources (Dependency injection is better than hardwiring resources)
- Item 6: Avoid creating unnecessary objects
- Item 7: Eliminate obsolete object references (exclude obsolete object references)
- Item 8: Avoid finalizers and cleaners (avoid using finalizers and cleaners)
- Item 9: Prefer try with resources to try finally (using try-with-resources is better than try-finally)
- Chapter 3. Methods Common to All Objects (common methods of objects)
- Chapter 3 Introduction
- Item 10: Obey the general contract when overriding equals (the convention that should be followed when overriding the equals method)
- Item 11: Always override hashCode when you override equals (when overriding the equals method, always override the hashCode method)
- Item 12: Always override toString (always override the toString method)
- Item 13: Override clone judiciously (override clone method wisely)
- Item 14: Consider implementing Comparable (Consider implementing the Comparable interface)
- Chapter 4. Classes and Interfaces
- Chapter 4 Introduction
- Item 15: Minimize the accessibility of classes and members (minimize the accessibility of classes and members)
- Item 16: In public classes use accessor methods not public fields (in public classes, use accessor methods, not public fields)
- Item 17: Minimize mutability (reduce variability)
- Item 18: Favor composition over inheritance
- Item 19: Design and document for inheritance or else prohibit it (inheritance must be well designed and documented, otherwise its use is prohibited)
- Item 20: Prefer interfaces to abstract classes (Interfaces are better than abstract classes)
- Item 21: Design interfaces for posterity
- Item 22: Use interfaces only to define types (interfaces are only used to define types)
- Item 23: Prefer class hierarchies to tagged classes (Class hierarchies are better than tagged classes)
- Item 24: Favor static member classes over nonstatic (static member classes are better than non-static member classes)
- Item 25: Limit source files to a single top level class (source files are limited to a single top level class)
- Chapter 5. Generics
- Chapter 5 Introduction
- Item 26: Do not use raw types (Do not use raw types)
- Item 27: Eliminate unchecked warnings (eliminate unchecked warnings)
- Item 28: Prefer lists to arrays (list is better than array)
- Item 29: Favor generic types (prefer using generic types)
- Item 30: Favor generic methods (prefer using generic methods)
- Item 31: Use bounded wildcards to increase API flexibility (use bounded wildcards to increase API flexibility)
- Item 32: Combine generics and varargs judiciously
- Item 33: Consider typesafe heterogeneous containers (Consider typesafe heterogeneous containers)
- Chapter 6. Enums and Annotations (enumerations and annotations)
- Chapter 6 Introduction
- Item 34: Use enums instead of int constants (use enumeration types instead of int constants)
- Item 35: Use instance fields instead of ordinals
- Item 36: Use EnumSet instead of bit fields (use EnumSet instead of bit fields)
- Item 37: Use EnumMap instead of ordinal indexing (use EnumMap to replace ordinal indexing)
- Item 38: Emulate extensible enums with interfaces (use interfaces to simulate extensible enumerations)
- Item 39: Prefer annotations to naming patterns (annotations are better than naming patterns)
- Item 40: Consistently use the Override annotation (insist on using the @Override annotation)
- Item 41: Use marker interfaces to define types
- Chapter 7. Lambdas and Streams (λ expressions and streams)
- Chapter 7 Introduction
- Item 42: Prefer lambdas to anonymous classes (λ expressions are better than anonymous classes)
- Item 43: Prefer method references to lambdas (method references are better than lambda expressions)
- Item 44: Favor the use of standard functional interfaces
- Item 45: Use streams judiciously
- Item 46: Prefer side effect free functions in streams (use side effect free functions in streams)
- Item 47: Prefer Collection to Stream as a return type (Prefer Collection instead of stream as the return type)
- Item 48: Use caution when making streams parallel
- Chapter 8. Methods
- Chapter 8 Introduction
- Item 49: Check parameters for validity
- Item 50: Make defensive copies when needed
- Item 51: Design method signatures carefully (carefully design method signatures)
- Item 52: Use overloading judiciously
- Item 53: Use varargs judiciously
- Item 54: Return empty collections or arrays, not nulls (return empty collections or arrays, not null)
- Item 55: Return optionals judiciously
- Item 56: Write doc comments for all exposed API elements
- Chapter 9. General Programming
- Chapter 9 Introduction
- Item 57: Minimize the scope of local variables (minimize the scope of local variables)
- Item 58: Prefer for-each loops to traditional for loops (for-each loop is better than traditional for loop)
- Item 59: Know and use the libraries
- Item 60: Avoid float and double if exact answers are required (float and double types should be avoided if exact answers are required)
- Item 61: Prefer primitive types to boxed primitives (Basic data types are better than wrapper classes)
- Item 62: Avoid strings where other types are more appropriate (avoid using strings when other types are more appropriate)
- Item 63: Beware the performance of string concatenation (beware of performance problems caused by string concatenation)
- Item 64: Refer to objects by their interfaces
- Item 65: Prefer interfaces to reflection (Interface is better than reflection)
- Item 66: Use native methods judiciously
- Item 67: Optimize judiciously
- Item 68: Adhere to generally accepted naming conventions
- Chapter 10. Exceptions
- Chapter 10 Introduction
- Item 69: Use exceptions only for exceptional conditions
- Item 70: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors (use checked exceptions for recoverable conditions and runtime exceptions for programming errors)
- Item 71: Avoid unnecessary use of checked exceptions (Avoid unnecessary use of checked exceptions)
- Item 72: Favor the use of standard exceptions (encourage reuse of standard exceptions)
- Item 73: Throw exceptions appropriate to the abstraction (throw exceptions that can be explained by abstraction)
- Item 74: Document all exceptions thrown by each method (record all exceptions thrown by each method)
- Item 75: Include failure capture information in detail messages (Exception detail messages should include capture failure information)
- Item 76: Strive for failure atomicity (try your best to ensure failure atomicity)
- Item 77: Don't ignore exceptions
- Chapter 11. Concurrency
- Chapter 11 Introduction
- Item 78: Synchronize access to shared mutable data
- Item 79: Avoid excessive synchronization
- Item 80: Prefer executors, tasks, and streams to threads (Executors, tasks, and streams are better than using threads directly)
- Item 81: Prefer concurrency utilities to wait and notify (Concurrency utilities are better than wait and notify)
- Item 82: Document thread safety (Document should contain thread safety attributes)
- Item 83: Use lazy initialization judiciously
- Item 84: Don't depend on the thread scheduler
- Chapter 12. Serialization
- Chapter 12 Introduction
- Item 85: Prefer alternatives to Java serialization (prefer alternatives to Java serialization)
- Item 86: Implement Serializable with great caution
- Item 87: Consider using a custom serialized form (Consider using a custom serialized form)
- Item 88: Write readObject methods defensively (write readObject methods defensively)
- Item 89: For instance control, prefer enum types to readResolve (For instance control, enum types are better than readResolve)
- Item 90: Consider serialization proxies instead of serialized instances (Consider serialization proxies instead of serialized instances)