I was just seeing the difference between a HashMap and HashTable. Other than the obvious synchronized and unsynchronized difference, I noticed that HashTable
extends the Dictionary
class while HashMap implements Map
. Both of them store <Key, Value>
pair, so what's the difference. I tried Googling for it and I found few questions on SO (1, 2 and 3). I didn't find anything satisfactory other than the fact that Dictionary
class is obsolete. Is there any difference between thee two classes? If no, why is the dictionary class obsolete now?
Asked
Active
Viewed 2,815 times
2

Community
- 1
- 1

Pervy Sage
- 841
- 1
- 10
- 22
-
possible duplicate of [Differences between HashMap and Hashtable?](http://stackoverflow.com/questions/40471/differences-between-hashmap-and-hashtable) – Bobulous Sep 17 '14 at 21:00
-
1Don't think it is a duplicate, no. This is querying the difference between Dictionary and Map, which is a somewhat different question. Some of the answers there touch on the fact that there is a difference, but none go into the important question of why Dictionary is obsolete. – Jules Sep 17 '14 at 21:02
-
It's not clear how your question differs from those existing questions. – Bobulous Sep 17 '14 at 21:02
-
@Jules HashMap implements Map, HashTable extends Dictionary. It's fundamentally the same question. – Roddy of the Frozen Peas Sep 17 '14 at 21:02
-
1possible duplicate of [Java What's difference between Hashtable and Dictionary?](http://stackoverflow.com/questions/9769797/java-whats-difference-between-hashtable-and-dictionary) – ericbn Sep 17 '14 at 21:02
-
2@RoddyoftheFrozenPeas Not really, no. The answers to the question of differences between HashMap and Hashtable predominantly relate to the *implementation* of those classes. This question, by focussing on the abstract ancestors, is asking more about the difference in the *interface*. – Jules Sep 17 '14 at 21:06
-
1It's worth noting that Java has lots of redundant classes and interfaces, for historical reasons. When an older class/interface seems to duplicate a newer one don't spend too much time wondering why, as usually the newer stuff was created to fit together better in some grand scheme. Functionally there's usually very little difference. – Hot Licks Sep 18 '14 at 01:20
4 Answers
13
Dictionary
is an abstract class that contains no non-abstract methods. Modern practice strongly recommends using an interface rather than a class in such a case. Map
is such an interface.
It also uses Enumeration
which is also considered obsolete; Map
uses Iterator
which is not.

Jules
- 14,841
- 9
- 83
- 130
2
Dictionary
is an abstract class whereasMap
is an interface, hence it is more Java-idiomatic.Dictionary
was deprecated early in Java 1.2 and replaced by its better interface counterpart,Map
. This leads to believed thatDictionary
was just a bad design choice and the Java folks kept theDictionary
class for backward compatibility.

jlr
- 1,362
- 10
- 17
1
The main difference is that Dictionary is an abstract class and Map is a interface. Collections API uses interfaces like Map, List, Set.

Ezequiel
- 3,477
- 1
- 20
- 28
0
Dictionary is an abstract base class of Hashtable. Both are still in JDK for backwards compatibility with old code. We are expected to use HashMap and other implementations of Map interface introduced in Java 1.2.

Moni
- 433
- 3
- 9