Recently, I was reading the book Effective Java, and here I briefly recorded 78 suggestions in the book. Because of some programming experience, most of the rules and regulations in the book are in practice, and some are used but I don’t know why. , of course, such as enumeration, concurrency, etc., still need more practice.
- Consider using static factory methods instead of constructors
- Consider using a builder when multiple builder arguments are encountered
- Enhancing Singleton properties with private constructors or enum types
- Enhancing non-instantiable capabilities with private constructors
- Avoid creating unnecessary objects
- Eliminate expired object references
- Avoid using finalizers
- Follow general conventions when overriding equals
- Always override hashCode when overriding equals
- Always override toString
- Override clone carefully
- Consider implementing the Comparable interface
- Minimize the accessibility of classes and members
- Use access methods in public classes instead of public fields
- minimize variability
- Composition is greater than inheritance
- Either design for inheritance and document it, or disallow inheritance
- Interfaces are better than abstract classes
- Interfaces are only used to define types
- Class hierarchy takes precedence over label classes
- Representing policies with function objects
- Prefer static member classes
- Please don't use primitive types in new code
- Eliminate unchecked warnings
- Lists take precedence over arrays
- Generics are preferred
- Prefer generic methods
- Use restricted wildcards to increase API flexibility
- Prefer type-safe heterogeneous containers
- Use enum instead of int constant
- Replacing ordinal numbers with instance fields
- Replacing Bitfields with EnumSets
- Use EnumMap instead of ordinal index
- Mock scalable enums with interfaces
- Annotations take precedence over naming patterns
- Stick with the Override annotation
- Defining Types with Marker Interfaces
- Check the validity of parameters
- Protective copying if necessary
- Carefully design method signatures
- Use overloading with caution
- Use variadic parameters sparingly
- Returns a zero-length array or collection instead of null
- Write documentation comments for all exported API elements
- Minimize the scope of local variables
- for-each loop takes precedence over traditional for loop
- Understanding and Using Class Libraries
- Avoid float and double if you need an exact answer
- Primitive types take precedence over boxed primitive types
- Try to avoid strings if other types are more suitable
- Beware of String Concatenation Performance
- Referencing an object through an interface
- Interfaces take precedence over reflection mechanisms
- Use native methods sparingly
- Optimize carefully
- Follow generally accepted naming conventions
- Use exceptions only for exceptional cases
- Use checked exceptions for recoverable cases and runtime exceptions for compilation errors
- Avoid unnecessary use of checked exceptions
- Prefer standard exceptions
- Throws the exception corresponding to the abstract
- Exceptions thrown by each method must be documented
- Include a message that catches the failure in the detail message
- Strive to keep failure atomic
- Don't ignore exceptions
- Synchronized access to shared mutable data
- Avoid over-synchronization
- executors and tasks take precedence over threads
- Concurrency tools take precedence over wait and notify
- Documentation of thread safety
- Use lazy initialization with caution
- Don't rely on the thread scheduler
- Avoid using thread groups
- Implement Serializable Interface Carefully
- Consider using a custom serialization method
- Write the readObject method protectively
- For instance control, enum types take precedence over readResolve
- Consider using serializing proxies instead of serializing instances