synchronized - Only a single thread can execute a method or block at one time. Not only does synchronization prevent a thread from observing an object in an inconsistent state, but it ensures that each thread entering a synchronized method or block s…
Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st language I have chosen for this migration. It's a nice chance to read some great books like "Effective Java 2nd Edition" and share the note for what I…
Java写了很多年,很惭愧,直到最近才读了这本经典之作<Effective Java>,按自己的理解总结下,有些可能还不够深刻 一.Creating and Destroying Objects Consider static factory methods instead of constructors (factory方法可以拥有名称,可以避免重复创建,比如单例模式) Consider a builder when faced with many constructor parameter…
<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 s…
Principle To avoid liveness and safety failures, never cede control to the client within a synchronized method or block. Do as little work as possible inside synchronized regions. You should make a mutable class thread-safe (Item 70) if it is intende…
Use immutable classes as much as possible instead of mutable classes. Advantage Easy to design, implement and use than mutable classes. Less prone to error and more secure. Immutable objects are simple. Immutable objects are inherently thread-safe; t…
MInimize the accessibility of classes and members 这个叫做所谓的 information hiding ,这么做在于让程序耦合度更低,增加程序的健壮性等等,反正就是很有必要和有用. 四个修饰等级 private :只能当前class中调用 package-praivate 声明class,没有修饰的时候是默认 package-praivate,表示在一个 package里面使用 protect subclass里面调用 public 任意地方…
本文参考 本篇文章参考自<Effective Java>第三版第九条"Prefer try-with-resources to try-finally" The code in both the try block and the finally block is capable of throwing exceptions.The second exception(in finally block) can completely obliterate the first…
<Effective Java>阅读笔记,用适合自己理解的方式提炼该书内容.<Effective Java>是一本很实用的书,阅读方法应该是快速的领会,总结,然后应用.而非,一个字一个字去推敲,研究.所以,书呆子们一般都很xx,在我眼里. 2016.07.24作 1,用静态方法替代构造器,下面是很好的例子: public static final Boolean TRUE = new Boolean(true); public static final Boolean FALSE…