Effective Java Directory

Source: Internet
Author: User
Tags serialization

"Effective Java" catalog excerpt.
I know it looks bad. In the present, the lack of actual operation, can only temporarily extract the directory. With the increase in practice, fill in more examples slowly.

Chapter 2 Creating and destroying Objects
    • Consider static factory methods instead of constructors
    • Consider a builder when faced with many constructor parameters
    • Enforce the Singleton property with a private constructor or an enum type
    • Avoid Creating unnecessary objects
    • Eliminate obsolete object references
    • Avoid finalizers
Chapter 3 Methods Common to all Objects
    • Obey the contract when overriding equals
    • Always override hashcode If you override equals
    • Always override toString
    • Override Clone judiciously
    • Consider implementing comparable
Chapter 4 Classes and Interfaces
    • Minimize the accessibility of classes and members
    • In public classes, use accessor methods
    • Minimize mutability
    • Favor composition over inheritance
    • Design and document for inheritance or else prohibit it
    • Prefer interfaces to abstract classes
    • Use interfaces define types
    • Prefer class hierarchies to tagged classes
    • Use function objects to represent strategies
    • Favor static member classes over nonstatic
Chapter 5 Generics
    • Don ' t use raw types in new code
    • Eliminate unchecked warnings
    • Prefer lists to arrays
    • Favor Generic Types
    • Favor generic methods
    • Use bounded wildcards to increase API flexibility
    • Consider typesafe heterogeneous containers
Chapter 6 Enums and Annotations
    • Use enums instead of int costants
    • Use instance fields instead of ordinals
    • Use Enumset instead of bit fields
    • Use enummap instead of ordinal indexing
    • Emulate extensible enums with interfaces
    • Prefer Annotations to naming patterns
    • Consistently use the Override annotation
    • Use marker interfaces to define types
Chapter 7 Methods
    • Check Parameters for validity
    • Make defensive copies when needed
    • Design method Signatures carefully
    • Use overloading judiciously
    • Use VarArgs judiciously
    • Return empty arrays or collections, not nulls
    • Write doc comments for all exposed API elements
Chapter 8 General programming
    • Minimize the scope of local variables
    • Prefer For-each Loops to traditional for loops
    • Know and use the libraries
    • Avoid float and double if exact answers is required
    • Prefer primitive types to boxed primitives
    • Avoid strings where other types is more appropriate
    • Beware the performance of string concatenation
    • Refer to objects by their interfaces
    • Prefer interfaces to Reflection
    • Use native methods judiciously
    • Optimize judiciously
    • Adhere to generally accepted naming conventions
Chapter 9 Exceptions
    • Use exceptions only for exceptional conditions
    • Use checked exceptions for recoverable conditions and runtime exceptions for programming errors
    • Avoid unnecessary use of checked exceptions
    • Favor the use of the exceptions
    • Throw exceptions appropriate to the abstraction
    • Document all exceptions thrown by each method
    • Include failure-capture information in detail messages
    • Strive for failure atomicity
    • Don ' t ignore exceptions
Chapter Concurrency
    • Synchronized access to shared mutable data
    • Avoid Excessive synchronization
    • Prefer executors and tasks to threads
    • Prefer concurrency Utilities to wait and notify
    • Document Thread Safety
    • Use lazy initialization judiciously
    • Don ' t depend on the thread scheduler
    • Avoid thread Groups
Chapter serialization
    • Implement Serializable judiciously
    • Consider using a custom serialized form
    • Write ReadObject methods defensively
    • For instance control, prefer enum types to readresolve
    • Consider serialization proxies instead of serialized instances

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.