{Effective Java} Quick Guide

1 Introduction

2 Creating and Destroying Objects:

   Item 1: Consider static factory methods instead of constructors

   Item2:    Consider a builder when faced with many constructor parameters

   Item3:  Enforce the singleton property with a private constructor or an enum type

   Item4:  Enforce noninstantiability with a private constructor

   Item5:  Avoid creating unnecessary objects

   Item6:  Eliminate obsolete object references

   Item7:    Avoid finalizers


3 Methods Common to All Objects

   Item8:  Obey the general contract when overriding equals 

 Item9:  Always override hashCode when you override equals

   Item10:  Always override toString

   Item11:  Override clone judiciously

   Item12:  Consider implementing Comparable

 

4 Classes and Interfaces

   Item13:   Minimize the accessibility of classes and members

   Item14:    In public classes, use accessor methods, not public fields

   Item15:    Minimize mutability

   Item16:    Favor composition over inherience

   Item17:    Design and document for inherirance or else prohibit it

   Item18:    Prefer interfaces to abstract classes

   Item19:    Use interfaces only to define types

   Item20:    Prefer class hierarchies to represent strategies

   Item21:    Use function objects to represent strategies

   Item22:    Favor static member classes over nonstatic


5 Generics 

   Item23:    Don't use raw types in new code

   Item24:    Eliminate unchecked warnings 

   Item25:    Prefer lists to arrays

   Item26:    Favor generic types 

   Item27:    Favor generic methods

   Item28:    Use bounded wildcards to increase API flexibility

   Item29:    Consider typesafe heterogeneous containers

 

6 Enums and Annotations 

   Item30:    Use enums instead of int constants 

   Item31:    Use instance fields instead of ordinals

   Item32:    Use EnumSet instead of bit fields

   Item33:    Use EnumMap instead of ordinal indexing

   Item34:    Emulate extensible enums with interfaces

   Item35:    Prefer annotations to naming patterns

   Item36:    Consistently use the Override annotation

   Item37:    Use marker interfaces to define types


7 Methods

   Item38:    Check parameters for validity

   Item39:    Make defensive copies when needed

   Item40:    Design method signatures carefully

   Item41:    Use overloading judiciously

   Item42:   Use varargs judiciously

   Item43:    Return empty arrays or collections, not nulls

   Item44:    Write doc comments for all exported API elements


8 General Programming

   Item45:    Minimize the scope of local variables

   Item46:    Prefer for-each loops to traditional for loops

   Item47:    Know and use the libraries

   Item48:    Avoid float and double if exact answers are required

   Item49:    Prefer primitive types to boxed primitives

   Item50:    Avoid strings where other types are more appropriate

   Item51:    Beware the performance of string concatenation

   Item52:   Refer to objects by their interfaces

   Item53:    Prefer interfaces to reflection

   Item54:   Use native methods judiciously

   Item55:    Optimize judiciously

   Item56:    Adhere to generally accepted naming conventions


9 Exceptions 

   Item57:    Use exceptions only for exceptional conditions

   Item58:    Use checked exceptions for recoverable conditions and runtime exceptions for programming errors

   Item59:    Avoid unnecessary use of checked exceptions

   Item60:    Favor the use of standard exceptions

   Item61:     Throw exceptions appropriate to the abstraction

   Item62:     Document all exceptions thrown by each method

   Item63:    Include failure-capture information in detail messages

   Item64:    Strive for failure atomicity

   Item65:    Don't ignore exceptions


10 Concurrency

   Item66:    Synchronize access to shared mutable data

   Item67:    Avoid excessive synchronization

   Item68:    Prefer executors and tasks to threads

   Item69:    Prefer concurrency utilities to wait and notify

   Item70:    Document thread safety

   Item71:    Use lazy initialization judiciously

   Item72:    Don't depend on the thread scheduler

   Item73:    Avoid thread groups

 

11 Serialization

   Item74:   Implement Serializable judiciously

   Item75:   Consider using a custom serialized form

   Item76:   Write readObject methods defensively

   Item77:    For instance control, prefer enum types to readResolve

   Item78:    Consider serialization proxies instead of serialized instances

      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Anyanyamy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值