Effective Java 目录

《Effective Java》目录摘抄。
我知道这看起来很糟糕。当下,自己缺少实际操作,只能暂时摘抄下目录。随着,实践的增多,慢慢填充更多的示例。

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 general contract when overriding equals
  • Always override hashCode when 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, not public fields
  • Minimize mutability
  • Favor composition over inheritance
  • Design and document for inheritance or else prohibit it
  • Prefer interfaces to abstract classes
  • Use interfaces only to 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 are required
  • Prefer primitive types to boxed primitives
  • Avoid strings where other types are 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 standard 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 10 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 11 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

原文地址:https://www.cnblogs.com/linkworld/p/9535760.html

时间: 2024-12-23 21:30:01

Effective Java 目录的相关文章

【电子书】Effective Java中文版下载

下载地址: 点击打开链接 (需要资源0分的联系我~) <Effective Java中文版(第2版)>主要内容:在Java编程中78条极具实用价值的经验规则,这些经验规则涵盖了大多数开发人员每天所面临的问题的解决方案.通过对Java平台设计专家所使用的技术的全面描述,揭示了应该做什么,不应该做什么才能产生清晰.健壮和高效的代码.第2版反映了Java 5中最重要的变化,并删去了过时的内容. <Effective Java中文版(第2版)>中的每条规则都以简短.独立的小文章形式出现,并

Effective java经验之谈,创建和销毁对象

关于Effective java 这本书,自己的一些总结性的思考.篇幅可能不按照目录来,因为自己喜欢先看哪一章就直接阅读了.不过能确定的是,每一章都会有总结.欢迎大家拍砖与补充. 1.      考虑用静态工厂的方法代替构造器.优点:有名字,不必每次创建对象,返回任何子类型对象,简洁的代码.缺点:该类将不能被子类化(复合大于继承,也是优点),不方便doc工具输出文档,一般约定的命名规则: valueOf  转换类型 getInstance 获得对象实例 newInstance 创建新的对象实例

effective java —— 终结方法守卫者

目录: effective java —— 终结方法守卫者 effective java 第2章:创建和销毁对象.第7条 : 避免使用终结方法.最后的“终结方法守卫者 (finalizer guardian)”的例子,以加深理解. 1 /** 2 * chapter 2——终结守卫者 3 * @ClassName: Parent 4 * TODO 5 * @author xingle 6 * @date 2015-3-11 下午3:49:47 7 */ 8 public class Parent

《Effective Java(中文第二版)》【PDF】下载

<Effective Java(中文第二版)>[PDF]下载链接: https://u253469.pipipan.com/fs/253469-230382186 Java(中文第二版)>[PDF]"  TITLE="<Effective Java(中文第二版)>[PDF]" /> 编辑推荐 <Sun 公司核心技术丛书:EffectiveJava中文版(第2版)>内容全面,结构清晰,讲解详细.可作为技术人员的参考用书.编码平添乐

Effective Java之内部类

Effective Java中对类的权限,接口等的要求,总结起来就是够用就行,不要赋予过多的访问权限,类的定义也是,如果某个类只会在类的内部使用,那就将该类定义为内部类吧. 内部类分为四种: 1.静态内部类:静态内部类就是在class前面多了static关键词的内部类,这种类和类的静态方法和静态变量一样,针对类本省进行操作,在静态内部类中可以随意访问其所在类的静态方法和静态变量. 2.非静态内部类:和静态内部类相对于,其实在类内部定义的所有东西只是受到访问修饰符的限制,所以非静态内部类和类的非静

【总结】Effective java经验之谈,类与接口

转载请注明出处:http://blog.csdn.NET/supera_li/article/details/44940563 Effective Java系列 1.Effective java经验之谈,创建和销毁对象 2.Effective java经验之谈,泛型 3.Effective java经验之谈,类与接口 4.Effective java经验之谈,通用方法 5.Effective java经验之谈,枚举,注解,方法,通用设计,异常 6.Effective java经验之谈,并发编程

EFFECTIVE JAVA 第十章 并发

EFFECTIVE  JAVA  第十章  并发 66.同步访问共享的可变数据 *java语言规范保证读或写一个变量是原子的(可以保证返回的值是某个线程保存在该变量中的),除非这个变量的类型为long或double.(但并不保证一个线程写入的值对于另一个线程是可见) *synchronized修饰方法.synchronized代码块可以实现同步 *volatile修饰的变量只保证读取的是主存里最新的值而不是内存中该值的拷贝,使用volatile变量必须遵循(即变量真正独立于其他变量和自己以前的值

1. effective java overview

ref: from book "effective java" This book is designed to help you be familiar with fundamental libs like java.lang, java.util. and to a lesser extent, java.util.concurrent and java.io. The book discusses other lib from time to time, but it does

[Effective Java]考虑用静态工厂方法代替构造器

本文主要介绍如何使用静态工厂方法已经在那种场合来使用这种方式代替构造方法. 众所周知,对于类而言,我们为了获得一个类的实例对象,通常情况下会提供一个公有的(public) 的构造器.当然除了这种方法以外,我们还可以通过给类提供一个public的静态工厂方法(static factory method)的方式来完成,让它返回一个类的实例. 先看一个简单的Boolean的示例,这个示例将boolean基本类型值转换成一个Boolean对象的引用. public static Boolean valu