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…
Use generic types to replace the object declaration Add one or more type parameters to its declaration. Replace all the uses of the type Object with the appropriate type parameter. Handle the new E[] errorwith two ways : Use the explicit type casting…
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…
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…
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…
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,…
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…
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…