Effective Java Directory

Source: Internet
Author: User
Tags serialization

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

Effective Java Directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.