1. Sets does n't allow duplicate elements, but if you were to let set take duplicate elements how do you go about it, without creating your own set implementation of Set ?
    The question clears that no separate implementation is needed for letting it to store duplicate elements, so the answer lies in how set identifies duplicate elements. It is the equals method  and the hashCode of the element, which lets the Set to identify duplicate elements. Now If the equals method provided wrong or equals method is not overridden then Set has no way to identify if the elements are duplicate. Remember Set does n't have a magic wand to identify duplicates unless one has overridden the equals method  and the hashCode of the object we meant to store.
  2. What is the benefit of using @override annotation ?
    With the newer version of Java ( above 1.5 ) , this annotation will help you identifying common mistakes in case if the overriden method is actually being overriden. For example , the equals method should return boolean and take object as argument. If the class that tries to override this method but accidentally writes a code like
    public boolean equals ( MyClass s ) { //and some code } would compile fine with the buggy code, since it is not an override ( notice the MyClass ) would lead a call to Objects equals method ,and the evaluation would go wrong. With the @override annotation the compiler would complain of such occurrence.
  3. Can you add heterogeneous objects to a typed collection  ? For example can you add String and integer and double to an ArrayList,with Generics type applied to ArrayList ?
    At first you might thing, if we follow and tell ArrayList of a particular type then how can we add All kinds like String,Integer and Double ? Well it is possible All you have to do is ArrayList<Object> al = new ArrayList<Object>.
  4. What is natural ordering in Java ? And how do you achieve it ?
  5. Why can't you use ListIterator in Set ?
  6. With Generics you can restrict your collection to add only a specific type of object.However , if you want to add any kind of object in a collection you can defeniely do it ,for example by ArrayList<Object> al=new ArrayList<Object>(); al.add("str");al.add(new Animal()); , continue adding any kind of objects,into the collection ( arraylist). What is the downside or problem with this kind of code  ?
    There is a big problem with this kind of code,especially if you have Object as type , in the collection, this does allow you to add anykind of object you wish , but it has two problems
    1. When you actually retrive the you can cast the object to its original object , for example Animal a =( Animal)al.get(1) , But you need to know which one (object) is residing at which index in the ArrayList.Well this gets you into trouble when you do a small mistake and end up in ClassCastException.
    2. Knowing the above , you decided to keep it like Object ob=al.get(1); will return you the Animal object , but refered by Object , which slashes the possibility of calling animal method. like ob.eat() ; would give you compilation error.
      See article explaing more details
  7. Write a line of code which will declare an ArrayList var arrList , and also make the ArrayList to contain an element in it , without using the arryList variable ?