Introduction to Effective Java Chinese version 3 PDF
The book contains 90 entries, each discussing a rule in Java programming. These rules reflect some useful practices that the most experienced good programmers use in practice.
These items are organized in a loose manner into 11 chapters, each dealing with a major aspect of software design. Therefore, the book does not necessarily need to be read from beginning to end, as each entry has a degree of independence. These items often cross reference each other, so it’s easy to find what you need in the book.
The goal of this book is to help readers use the Java programming language and its base libraries: java.lang, java.util, and java.io more effectively, as well as sub-packages such as java.util. Concurrent and java.util. Function. Other libraries are discussed from time to time.
Directory:
Chapter 1 Introduction 1 Chapter 2 Create and Destroy Object 4 Clause 1: Replace constructor 4 with static factory method Clause 2: Consider using constructor 8 when multiple constructor parameters are encountered Clause 3: Enforce Singleton property 13 with private constructor or enumerated type Clause 4: Enforce non-instantiation through private constructors 15 Rule 5: Give priority to dependency injection to reference resources 16 Rule 6: Avoid creating unnecessary objects 18 Rule 7: Eliminate expired object references 20 Rule 8: Avoid finalizing and cleaning methods 23 Rule 9: Try-with-resources takes precedence over try-finally 27 Chapter 3 Try-finally 27 Try-finally 27 Chapter 3 Methods common to All Objects 30 Always override toString 44 clause 13: Carefully override Clone 46 Clause 14: Consider implementing Comparable interfaces 53 Chapter 4 Classes and Interfaces 59 Clause 15: Minimize accessibility of classes and members 59 Clause 16: Use access methods on public classes instead of public domains 62 17: Minimize variability 64 18: Composition over Inheritance 70 19: Either design inheritance and document it or disallow inheritance 75 20 interfaces over Abstract classes 79 21 Interfaces for Future generations 83 22: Interfaces are only used to define types 85 Rule 23: Class hierarchies over tag classes 86 Rule 24: Static member classes over non-static member classes 88 Rule 25: Limit source files to a single top-level class 91 Chapter 5 Generics 93 Rule 26: Please do not use native types 93 Rule 27: Eliminate unexamined warnings 97 List over Array 99 29 give preference to generics 102 30 give preference to generic methods 106 31 Use restricted wildcards to increase API flexibility 109 32 Use caution with generics and mutable parameters 114 33: Preference for type safe heterogeneous containers 118 Chapter 6 Enumeration and Annotations 123 Rule 34 replace int constant with enum 123 Rule 35 Replace ordinal 131 with instance field 36 Replace bit field with EnumSet 132 Rule 37: Substitute EnumMap for ordinal indexes 134 Rule 38: Emulate extensible enumerations with interfaces 138 Rule 39: Annotations take precedence over naming patterns 140 Rule 40: Insist on using Override annotation 147 Rule 41: Define types with labeled Interfaces 149 Chapter 7 Lambda and Stream 151 42: Lambdas take precedence over Anonymous Classes 151 43: Method references Take precedence over Lambda 154 44: Stick with standard Function interfaces 156 45: Use Stream 159 with caution 46: Select a Stream with no side effect functions in preference 164 47: Use Stream with Collection as return type 168 48: Use Stream with caution 172 Check the validity of arguments 176 Clause 50: Make protective copies if necessary 179 Clause 51: Design method signatures 182 Clause 52: Be careful with overloading 184 Clause 53: Be careful with variable arguments 189 Clause 54: Return zero-length arrays or sets instead of NULL 190 Clause 55: Caution Return Optinal 192 56: Document all exported API elements 196 Chapter 9 General Programming 202 57: Minimize the scope of local variables 202 58: For-each loop takes precedence over traditional for loops 204 59: Know and use Class Library 207 Rule 60: If exact answers are needed, avoid float and double 209 Rule 61: Base types take precedence over boxing Base types 211 Rule 62: Avoid strings 213 Rule 63 if other types are more appropriate: Understanding the performance of string concatenation 215 Section 64: Referencing objects through interfaces 216 Section 65: Interfaces take precedence over reflection Mechanisms 218 Section 66: Using local methods with caution 220 Section 67: Optimizing with caution 221 Section 68: Observe generally accepted naming conventions 223 Chapter 10 Exceptions 227 Section 69: Use exceptions only for exceptional cases 227 Section 70: Use checked exceptions for recoverable cases, use runtime exceptions for programming errors 229 Section 71: Avoid unnecessary use of checked exceptions 231 Section 72: Give preference to standard exceptions 232 73: Throw exceptions corresponding to abstractions 234 74: All exceptions thrown by each method are documented 235 75: Include failures in detail messages – capture information 237 76: Try to keep failures atomic 238 77: Do not ignore exceptions 239 Chapter 11 Concurrency 241 78: Synchronize access to shared mutable data 241 79: Avoid excessive synchronization 245 80 executor, Task, and Stream precedence over threads 250 81: Concurrency tools take precedence over Wait and Notify 251 82 Documentation of thread safety 256 83 Careful Use of delayed initialization 258 84 Do not Rely on Thread schedulers 261 Chapter 12 Serialization 263 85: Other methods take precedence over Java serialization 263 Article 86: Carefully implement the Serializable interface 266 Article 87: Consider using custom serialization forms 269 Article 88: Protectively write readObject methods 274 Article 89: For instance control, enumeration types take precedence over readResolve 279 clause 90: Consider serializing proxies instead of serialized instances 282 Appendix 286 Correspondence to entries in version 2
Click on the download