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

Map Memory Representation

Shahid Pathan
Greenhorn

Joined: Dec 28, 2010
Posts: 23
Can anybody explain how the java represent Map in memory? Or Internal memory representation of Map?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

No.

That's because java.util.Map is an interface. It can be implemented by all kinds of maps -- HashMap, TreeMap, and many others. It's up to the implementors how they store the map's data. It would even be possible to write a map which used a database table as its backing data.

All we know about any implementation of Map is what the API documentation for java.util.Map says. And you'll notice it says nothing about storing data in memory.

In fact almost none of the API documentation mentions how its classes store data in memory. That's because you don't really have much of a choice. You can store data in primitives, or arrays, or in Java objects which in turn are built from primitives, arrays, or other Java objects. There isn't even much in the way of Java specifications which say how a Java implementation should store a primitive value.

And that's because it's a low-level implementation detail which the user of the language isn't supposed to be concerned with. So, you shouldn't be concerned with how a Map stores data in memory. It's much more important to concern yourself with how a Map deals with the data which it contains.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Paul Clapham wrote:All we know about any implementation of Map is what the API documentation for java.util.Map says.

I must be reading this differently than you intended it, but I would say there are many implementations of Map for which we know much more than is specified in the API. We do have access to source code for numerous implementations, after all. If we want to understand more about a particular implementation, that's generally quite possible - just look at the source.

I would agree that almost nothing learned this way is true for all Map implementations. And even things that are specified in the API are not always true for some implementations (TreeMap comes to mind).

And I would agree that, especially in "Beginning Java", programmers don't generally need to worry about this stuff.

However I do think it can be both fun and educational to study the source to learn more about such things. If one is so inclined. And after learning more important and basic stuff like how to use a map, and when to use it, and how to choose which map to use, and when to use something else entirely.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Map Memory Representation