Java

Topic: Collection Framework

Why doesn't Collection extend Cloneable and Serializable?

From Sun FAQ Page: Many Collection implementations (including all of the ones provided by the JDK) will have a public clone method, but it would be mistake to require it of all Collections. For example, what does it mean to clone a Collection that's backed by a terabyte SQL database? Should the method call cause the company to requisition a new disk farm? Similar arguments hold for serializable. If the client doesn't know the actual type of a Collection, it's much more flexible and less error prone to have the client decide what type of Collection is desired, create an empty Collection of this type, and use the addAll method to copy the elements of the original collection into the new one. Note on Some Important Terms    Synchronized means only one thread can modify a hash table at one point of time. Basically, it means that any thread before performing an update on a hashtable will have to acquire a lock on the object while others will wait for lock to be released.    Fail-fast is relevant from the context of iterators. If an iterator has been created on a collection object and some other thread tries to modify the collection object "structurally”, a concurrent modification exception will be thrown. It is possible for other threads though to invoke "set" method since it doesn’t modify the collection "structurally”. However, if prior to calling "set", the collection has been modified structurally, "IllegalArgumentException" will be thrown.

Browse random answers:

What are the goals of collections framework?
Explain the contents of collection framework? 
Explain interfaces of collectonframework?
Explain the collection classes?
Explain algorithms in collection framework?
How to use an Iterator ?
How to use an Comparator ?
What is the difference between java.util.Iterator and java.util.ListIterator?
What is HashMap and Map? 
Difference between HashMap and HashTable? Compare Hashtable vs HashMap?
What does synchronized means in Hashtable context?
What is fail-fast property?
Why doesn't Collection extend Cloneable and Serializable?
How can we make Hashmap synchronized?
Where will you use Hashtable and where will you use HashMap?
Difference between Vector and ArrayList? What is the Vector class? 
What is the Difference between Enumeration and Iterator interface?
Why Java Vector class is considered obsolete or unofficially deprecated? or Why should I always use ArrayList over Vector?
What is an enumeration?
What is the difference between Enumeration and Iterator?
Where will you use Vector and where will you use ArrayList?
What is the importance of hashCode() and equals() methods? How they are used in Java?
What is the difference between Sorting performance of Arrays.sort() vs Collections.sort() ? Which one is faster? Which one to use and when?
What is java.util.concurrent BlockingQueue? How it can be used?
Set & List interface extend Collection, so Why doesn't Map interface extend Collection?
Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list? 
What is the difference between ArrayList and LinkedList? (ArrayList vs LinkedList.) 
Where will you use ArrayList and Where will you use LinkedList? Or Which one to use when (ArrayList / LinkedList).
What is performance of Map interface implementations
What is Performance of Set interface implementations
What is Performance of List interface implementations