• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

HashMap or HashTable

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ques from JQplus Sample exam:
Your application needs to load a set of key value pairs from a database table which never changes. Multiple threads need to access this information but none of them changes it.
Which class would you use to store such data?
The options are Hashtable,HashMap,TreeMap,Set,List
and 2 choices
I think the option should be HashMap and HashTable but can we just use HashMap as we do not need to synchronize this so we don't need HashTable.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you asking?
I thought the question stated that you should choose two answers. If that's the case, then HashMap and Hashtable are the correct answers. The only reason HashMap is a correct answer is because there is no need for synchronization.
Corey
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read from API that HashMap is not synchronized. It says only HashTable and Vector are synchronized.(Thread Safe). Then what could be the reason to select HashMap?
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Multiple threads need to access this information but none of them changes it.


Threads don't change information, so you don't need synchronization.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HashMap is quicker than HashTable.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jose Botella:
HashMap is quicker than HashTable.


To elaborate...HashMap is quicker than Hashtable because HashMap isn't synchronized. There is no need for invoking threads to take the extra time to acquire a monitor or to wait for one in the case that it has already been acquired by another thread.
Corey
reply
    Bookmark Topic Watch Topic
  • New Topic