The Artima Developer Community
Sponsored Link

Java Answers Forum
diff between hash map & hash table

6 replies on 1 page. Most recent reply: Nov 5, 2004 9:50 AM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
suma

Posts: 8
Nickname: suma2k4
Registered: Oct, 2004

diff between hash map & hash table Posted: Oct 31, 2004 6:33 AM
Reply to this message Reply
Advertisement
Hi,

Pl explain the difference between Hash map & Hash table.

thanks in advance

suma


Simon Springall

Posts: 2
Nickname: simon97062
Registered: Oct, 2004

Re: diff between hash map & hash table Posted: Nov 2, 2004 5:41 PM
Reply to this message Reply
Hashtable is a synchronized collection, which means it's protected from concurrent modifications from multiple threads. It also means it's a LOT slower than HashSet which is not designed to work in multiple threads. Normally you don't need the synchronizatation, or it's better to provide your own at a higher level if you do.
Similarly with Vector and ArrayList - Vector is synchronized and slow, ArrayList is not synchronized, and fast.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: diff between hash map & hash table Posted: Nov 2, 2004 6:55 PM
Reply to this message Reply
Do you have any impirical data to define what "a lot slower" means? I think you may be overstating it. Usually in CS, "a lot" would mean orders of magnitude, whereas I would guess that a synchronized collection is not orders of magnitude slower than an unsynchronized one.

If it is say 20% slower, I wouldn't call that "a lot."

Anybody have any hard numbers on this?

prakie

Posts: 2
Nickname: prakie
Registered: Nov, 2004

Re: diff between hash map & hash table Posted: Nov 4, 2004 4:26 AM
Reply to this message Reply
HashTable HashMap

1. Both are classes comes under the util package and both are used to store keyvalue pair values

2. Hashtable is synchronized and called as legacy classes Hashmap is Non -synchronized & called as Non Legacy classes

(Serializable: it store the object state in ur machine ok. it similar to the network layer process. while sending ur data to the other system through network for avoiding pocket loss we use serialization. this process maintain the state of the data. synchronized classes are serializable )

if specify your class as synchronized. ur program is thread safe. that's in multithreading, only one process can access the synchronised class at a time. one advantage is it's really fast compare with hashmap in intranet.

we can convert the hashmap to synchronized through synchronizedMap() method in HashMap class

3. HashTable uses Enumerator interface for data extraction from hashtable. HashMap uses Iterator interface .

4. Performance wise HashMap is better than HashTable

suma

Posts: 8
Nickname: suma2k4
Registered: Oct, 2004

Re: diff between hash map & hash table Posted: Nov 5, 2004 6:35 AM
Reply to this message Reply
thank you all

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: diff between hash map & hash table Posted: Nov 5, 2004 9:47 AM
Reply to this message Reply
I think you mixed up the idea that thread synchronization causes multiple threads to serially access the synchronized portions of code, with the cencept of serialization, which is simply about persisting (or marshalling) object states. These are two entirely separate meanings of "serialization" and using the synchronized keyword will in no way imply or automatically trigger implementation of the Serializable interface, as far as I know.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: diff between hash map & hash table Posted: Nov 5, 2004 9:50 AM
Reply to this message Reply
> 4. Performance wise HashMap is better than HashTable

Once again, we have a vague, undefined and unsubstantiated judgement. How much better? Where's your evidence? If it is just a few percentage points better, then it doesn't matter. Additionally, if it is slightly faster, but much worse in memory usage, then that's an important consideration (I'm not saying this is the case -- and I think it isn't -- but just trying to question this oversimplification that implies you should use one implementation simply because "it is faster").

Flat View: This topic has 6 replies on 1 page
Topic: How to access JSpinner's JTextField? Previous Topic   Next Topic Topic: Ignore this

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use