java collection related questions

I have below  java collection related questions. Please advise
why no concrete classcan  implement collection interface
what is fifference between collection, collections.

why vector, stack ,dictionary,Hashtable(why t small? ), Preoprties etc called called legacy classes''


why heterogeneous objects not allowed in treeset and treemap

Please advise
LVL 7
gudii9Asked:
Who is Participating?
 
dpearsonCommented:
Sounds like 4 unrelated questions?

I'll answer 1 and 3:

why no concrete class can  implement collection interface
A concrete class can implement Collection if it wants.  It's not prevented - just in the Java libraries they defined more specialized interfaces (List, Map etc.) and then implemented those.  That way Lists and Maps have some things in common like "isEmpty()" and "contains".

why vector, stack ,dictionary,Hashtable(why t small? ), Preoprties etc called called legacy classes''
These are legacy classes because Sun wrote new, better versions later, so you should stop using these and switch to the newer better alternatives in most cases.  E.g. HashMap is a better version of Hashtable and ArrayList is a better version of Vector.  They didn't take out the old classes, because that would break existing code that was using the older versions.

It's just a case of time moving on and their engineers figuring out better solutions over time.

Doug
0
 
zzynxSoftware engineerCommented:
what is fifference between collection, collections.
First I have to correct you it is Collection and Collections (with capitals)
1) Collection is an interface.
    It is the root interface in Java's collection hierarchy. A collection represents a group of objects, known as its elements.
    A lot of classes implement the Collection interface. ArrayList, HashSet, LinkedList, TreeSet to name a few.
    (cf. The Collection interface)

2) Collections is a java class that consists exclusively of static handy utility methods that operate on or return collections.
   (cf. The Collections class)

why heterogeneous objects not allowed in TreeSet and TreeMap
Sorted collections (like TreeSet and TreeMap) don't allow addition of heterogeneous elements as they are not comparable. You can't compare apples to oranges.
0
 
gudii9Author Commented:
Hashtable(why t small? )

please advise
0
 
dpearsonCommented:
Hashtable(why t small? )

You'd have to ask the guys at Sun (Oracle now) :)

Naming conventions weren't as well defined when Java first appeared.  I wouldn't read much into this.
0
 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.