9 Feb 2012

Explain Java class loaders? If you have a class in a pakage , What do you need to run it?

Class loaders are hierarchical and use a delegation model when loading a class. Class loaders request their parent to load the class first before attempting to load it themselves. When a class loader loads a class, the child class loaders in the hierarchy will never reload the class again. Hence Uniqueness  is is maintained. Classes loaded by a child class loader have visibility into classes loaded by its parents up the hierarchy but the reverse is not true as explained in the above diagram.


remember pie which, stands for Polymorphism, Inheritance and Encapsulation are the 3 pillars of OOPL



Q. Which one to favor, composition or inheritance? The guide is that inheritance should be only used when
subclass ‘is a’ superclass.
  •  Don’t use inheritance just to get code reuse. If there is no ‘is a’ relationship then use composition for code reuse. Overuse of implementation inheritance (uses the “extends” key word) can break all the subclasses, if the superclass is modified.
Do not use inheritance just to get polymorphism. If there is no ‘is a’ relationship and all you want is 
polymorphism then use interface inheritance with composition, which gives you code reuse (Refer Q10 in Java section for interface inheritance).

Q16:
Set (HashSet , TreeSet)
List (ArrayList, LinkedList, Vector etc)
Map(HashMap, TreeMap and Hashtable)