String s = new String("stringette"); // Don't do this. This will create an object each time Vs String s = "stringette"; class Person { private final Date birthDate; // Other fields, methods, and constructor omitted /** * The starting a…
String s = new String("stringette"); // DON'T DO THIS! The improved version is simply the following: String s = "stringette"; 根据生日来判断是否是婴儿潮时期出生的,isBabyBoomer()是一个糟糕的设计,每次调用这个方法都会创建Calendar,TimeZone以及2个Date对象实例,当此方法被频繁调用时将会非常地影响性能. publ…
The burden is justified if the exceptional condition cannot be prevented by proper use of the API and the programmer using the API can take some useful action once confronted with the exception. ask yourself how the programmer will handle the excepti…
Obey the general contract when overriding equals 先了解equals 和 == 的区别,如果不重写equals, equals比较的仅仅只是是否引用同一个对象,==更多的是比较基本数值.当我们创建一些对象的时候. 当对象是单例模式不需要进行 equals 重写. Reflexive: For any non-null reference values x,x.equals(x) must return true. Symmetric:For any…
NOTE Never do anything time-critical in a finalizer. Never depend on a finalizer to update critical persistent state. There is a severe performance penalty for using. "Finalizer chaining" is not performed automatically. The subclass finalizer mu…
Principle Strings are poor substitutes for other value types. Such as int, float or BigInteger. Strings are poor substitutes for enum types. As discussed in Item 30. Strings are poor substitutes for aggregate types. A better approach is simply to wri…
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…
Thread groups were originally envisioned as a mechanism for isolating applets for security purposes. They never really fulfilled this promise, and their security importance has waned to the extent that they aren't even mentioned in the standard work…
Reason The float and double types are particularly ill-suited for monetary calculations because it is impossible to represent 0.1 (or any other negative power of ten) as a float or double exactly. // This will print 0.6100000000000001 System.out.prin…
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…