Creating and destroying objects
- Consider replacing constructors with static factory methods
- Consider using the builder when you encounter multiple constructor parameters
- Hardening the Singleton property with a private constructor or enumeration type
- Hardening of non-instancing capabilities through private constructors
- Avoid creating unnecessary objects
- Elimination of expired object references
- Avoid using the finalization method finalizer
Methods that are common to all objects
- Follow common conventions When overriding equals
- Overwrite equals when always overwrite Hashcode
- Always overwrite ToString
- Cover clone with Care
- Consider implementing the comparable interface
Classes and Interfaces
- Minimizing the accessibility of classes and members
- Using access methods instead of public domains in public classes
- Minimization of variability
- Conforms to precedence over inheritance
- Either design for inheritance, provide documentation, or disallow inheritance
- Interface is better than abstract class
- Interface is only used to define types
- Class hierarchy is better than label class
- To represent a policy with a function object
- Prioritize static member classes
Generic type
- Do not use the original ecological type (Object, collection, etc.) in the new code, typically using generics instead.
- Eliminate non-inspected warnings
- List is better than array
- Prioritize generics
- Prioritize generic methods
- Leverage the flexibility of the Fraiti API with restricted wildcard
- Preference for type-safe, easy-to-buy containers
Enumerations and annotations
- Use enum instead of int constant
- Replace ordinal with instance field
- Replacing bit fields with Enumset
- Replace ordinal index with Enummap
- Simulating a scalable enumeration with an interface
- Annotations take precedence over named patterns
- Stick with override annotations
- Defining types with Tag interfaces
Method
- Checking the validity of parameters
- A protective copy if necessary
- Careful design method signature
- Use heavy loads with caution
- Use variable parameters with caution
- Returns a 0-length array or collection instead of NULL
- Write a document comment for all exported APIs
General programming
- Minimizing the scope of local variables
- The For-each cycle takes precedence over the traditional for loop (if there is a remove without for-each)
- Understanding and using class libraries
- If you need a precise answer, avoid using float and double
- The base type takes precedence over the boxed base type
- If other types are more appropriate, try to avoid using strings
- Beware of String link performance
- referencing objects through interfaces
- The interface takes precedence over the reflection mechanism
- Use local methods with caution
- Be careful with optimization
- Adherence to universally accepted naming conventions
Abnormal
- Use exceptions only for exception cases
- Use a run-time exception for a programmatic error with a inspected exception for recoverable cases
- Avoid unnecessary use of inspected exceptions
- Preferential use of standard exceptions
- throws a corresponding exception to the abstract
- Each method throws an exception that must have a document
- Include information in the detail message that could be failed to replenish
- Try to keep the failure atomic
- Do not ignore exceptions
Concurrent
- Synchronizing access to shared mutable data
- Avoid over-synchronization
- Executor and tasks take precedence over threads
- Concurrency tools take precedence over wait and notify
- Documentation of thread Safety
- Use deferred initialization with caution
- Do not rely on the thread scheduler
- Avoid using thread groups
Serialization of
- Implement serializable interfaces with caution
- Consider using a custom serialization format
- Writing readobject methods in a protective manner
- For instance control, the enumeration type takes precedence over Readresolve
- Consider serializing an instance with a serialization agent
Effective Java Directory