Disadvantage of tagged classes 1. Verbose (each instance has unnecessary irrelevant fields). 2. Error-prone (Program will fail by initializing wrong fields). 3. Inefficient (Memory footprint is increased for not used field). /** * Tagged class - vast…
Principle Use the higher-level concurrency utilities instead of wait and notify for easiness. Use ConcurrentHashMap in preference to Collections.synchronizedMap or Hashtable. Use concurrent collections in preference to externally synchronized collect…
Disadvantages of naming patterns Typographical errors may result in silent failures. There is no way to ensure that they are used only on appropriate program elements. They provide no good way to associate parameter values with program elements. Nami…
Disadvantage of reflection You lose all the benefits of compile-time type checking, including exception checking. The code required to perfrom reflective access is clumsy and verbose. Peformance suffers. When to use reflecition Design time - Componen…
Principle The general mechanism for executing tasks is the executor service. If you think in terms of tasks and let an executor service execute them for you, you gain great flexibility in terms of selecting appropriate execution policies. In essence,…
Feature Interface Abstract class Defining a type that permits multiple implementations Y Y Permitted to contain implementations. N Y The implemented class must reside the class hierarchy. N Y Single inheritance N Y Easy to evolve N Y Advantages of In…
Difference Arrays Lists 1 Covariant Invariant 2 Reified at runtime Erased at run time 3 Runtime type safety Compile time type safety non-reifiable types E, List<E> and List<String> whose runtime representation contains less information than it…
Prior to release 1.5, this was the preferred idiom for iterating over a collection: // No longer the preferred idiom to iterate over a collection! for (Iterator i = c.iterator(); i.hasNext(); ) { doSomething((Element) i.next()); // (No generics befor…
No. Primitives Boxed Primitives 1 Have their own values Have identities distinct from their values 2 Have only fully functional values Have one nonfunctional value which is null 3 Time and space efficient Time and space inefficient Note Applying the…
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…