aspose file tools*
The moose likes Beginning Java and the fly likes HashMapDefinition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashMapDefinition" Watch "HashMapDefinition" New topic
Author

HashMapDefinition

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
I am not a mathematician. I'm looking at OOP 2 on the cattle drive, and I don't know what a hash map is. Found some references to hash maps in C++ but no real explanation. Can any enlighten me?
manish paliwal
Greenhorn

Joined: May 18, 2001
Posts: 16
You can assume Hashmap is just like bucket where you dropped some objects and its reference .Their is no order of items in the Bucket .
Hope you understand .If not go for extra help to www.freejavahelp.com
ok byee
------------------
manish paliwal(or just mann )


manish paliwal(or just mann )
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You may find more information on HashMap by looking up info on it's more common name 'Hashtable'... when Java came out with the Collections API the name was changed to 'HashMap'... Now, some general info on these... A HashMap is not ordered, so there is no way to access data by index like in an array ( i.e. you can't say, HashMap[ 1 ], or HashMap.getIndex( 1 ) or anything like that... ). You access data in a HashMap by a reference... say, for example, that you have developed a class called Person. Person can hold age, height, weight, whatever... Now, you want to hold a group of people... you make a HashMap called group, and add people to it by their name... There is no order in the group, so the only way that you can refer to a person is by their name... The code below is fake, but will hopefully illustrate this concept...



HTH,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Marcellus Tryk
Ranch Hand

Joined: May 31, 2001
Posts: 64
Just a clarification: HashMap and Hashtable are two different classes. Hashtable is synchronized.
- Tod
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
Nathan, thank you for the excellent post! I've been meaning to ask this for some time but since I haven't needed a hashMap yet I hadn't gotten around to it (so thanks to Carol as well!)
Tod, can you explain 'synchronized' and how it relates to hashXxx?
------------------
I'm a soldier in the NetScape Wars...
Joel


Wait a minute, I'm trying to think of something clever to say...<p>Joel
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
Nate-
Thanks for the info. I haven't been able to find any information anywhere else on hashmaps/hashtables. This helps a lot!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

The 'synchronized' keyword is added to methods to make them thread-safe. Basically, what this means is that the method will only let one thread into the method at a time, 'cause if you have two threads trying to write data into the same element of a Hashtable at the same time, you have a problem... old data could end up overwriting newer data, or you could get a mix of old and new data.... When Hashtable was originally made, Sun thought that it was a good idea to build this thread-safe behavior into the Hashtable. However, this slowed down access to the data inside the Hashtable and people complained, so when the new Collections API came out, they decided to let users add synchronized behavior to the HashMap themselves if they needed it. This is good because it speeds up accessing the HashMap somewhat, and there is no trouble with messing up the data if you only have one thread in your program.

-Nate
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
Since I don't really understand threading I'm still a little confused. Does threading equal object sharing?
As always
------------------
I'm a soldier in the NetScape Wars...
Joel
Jackie Wang
Ranch Hand

Joined: Apr 18, 2002
Posts: 315
After I look @ Java API, I got 2 question:
1) I still a bit confused about the Map and HashMap.
2) the only difference b/n HashMap and Hashtable is Hashtable is synchronized which will be more expensive? Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashMapDefinition