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…
Generic types advantage Parameterized type can provide erroneous check in compile time. // Parameterized collection type - typesafe private final Collection<Stamp>stamps = ... ; You no longer have to cast manually when removing elements from collect…
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…
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…
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…
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…
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…
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…
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…
Chapter 8 General Programming Item 45: Minimize the scope of local variables local variables应该在他们要被用的地方声明,而不应该,比如,全部声明在方法开头.而且在声明的时候,记得要初始化.有个例外,比如你的IQueryable<T> localv需要在接下来的if else中分别初始化成不同的值,那么你可以在if之前先声明(我自己瞎举的例子). 如果某个local variable只是这个循环需要的,那…