• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hashmap vs hashtable ....

 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey ranchers.. just wanna make sure I know pretty much all (or the main) differences between hashmap and hastables.
1o.) according to RHE book:
Hashtable does not allow the null value to be stored, although it makes some efforts to support multithreaded use...
2o.) reading a post at javaranch
hashtable are synchronized, hashmaps are not.
any others??
thanks
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HashMap extends AbstractMap
HashTable Extends Dictionary
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may also want to have a look at the following article from the August '02 Javaranch newsletter:
Storing Objects in Java Part 3 - The Map Interface by Thomas Paul
See also the following discussion in the Performance forum:
Hashtable vs Hashmap by Max Habibi
And this too:
Utilizing the Map Interface from the Collections Framework
[ October 21, 2002: Message edited by: Valentin Crettaz ]
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more article that appeared in the July 02 edition of Java Pro:
Using Hashtables in Java
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another important difference is that Hashtable is synchronized and Hashmap is not. This is critical in knowing, because of Thread access issues. A Thread can obtain a monitor on a Hashtable without any extra coding. Any code utilizing a Hashmap that is needed to be Thread safe must provide synchronized code block when accessing Hashmap. Same thing applies when talking about Vector versus an ArrayList. The newer implementations such as Hashmap and ArrayList do not burden the programmer with the overhead of synchronization. With Vector and Hashtable you have no choice.
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy -
I'm too lazy to follow all the links, so although I'm sure this is mentioned in the other references, I just wanted to summarize what's important for the exam:
* Hashtable methods are synchronized, HashMap are not.
* Hashtable does not accept null anything (so, you can't have a null key and you can't have any null values)
* HashMap allows both a null key (obviously, just one) and null values
And... bonus reply here
Don't forget LinkedHashMap -- big difference between it and the other two (as far as the exam is concerned) is that there's no guaranteed iteration order for Hashtable and HashMap (and remember, you're not iterating over the actual Hashtable or HashMap, you're iterating over just the *values*) --
but with LinkedHashMap you get a choice of two different orderings: by insertion order, or by access order.
Cheers,
Kathy "too lazy to link" Sierra :roll:
 
"To do good, you actually have to do something." -- Yvon Chouinard
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic