• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is java object in memory?

 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I am thinking what is java object in memory?

We created new object and how it is represented in memory. It is some address or it is part of memory.

How hash-code of java object is calculated from memory . How object is stored in memory.

Finally what is memory in java?

Thank you very much!
 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is rather broad:


Finally what is memory in java?



Anyway, are you familiar with the notion of stack and heap?

How Java manages the objects internally, how their implemention/layout etc. look like, is hidden by design from the user and is not really interesting from the point of the view of an end user. (If you want to implement a JVM from scratch, then you have to ponder about this, but this might not be the case now.)


 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for reply!

You think I do not need to care about memory in java.

But why do people say that all java objects in my program are stored in HashTable where key is hash-code of java object.
Is this true?

Please tell me in short what is heap and stack and do they affect performance of my program...

Thank you!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Volodymyr Levytskyi wrote:I am thinking what is java object in memory?


An object in memory is just a block of bytes that contains the values of the member variables of that object. What exactly is stored in there, and in what format, is not specified - that's left up to the specific Java implementation that you are using.

Volodymyr Levytskyi wrote:We created new object and how it is represented in memory. It is some address or it is part of memory.


Variables in Java (of non-primitive types) are references to objects in memory. What exactly the reference consists of, is not specified - just like how exactly an object is stored, how that works exactly can be different for different Java implementations. As a Java programmer, you don't need to know those details. It will, in some way, directly or indirectly contain the address of the block of memory in which the data of the object is stored.

Volodymyr Levytskyi wrote:How hash-code of java object is calculated from memory .


That depends on the implementation of the hashCode() method of the class of the object.

Volodymyr Levytskyi wrote:How object is stored in memory.


As I already wrote above, how exactly the data of an object is stored is not specified, and you don't need to worry about that as a Java programmer.

Volodymyr Levytskyi wrote:Finally what is memory in java?


The memory of a computer is a basic part, together with the CPU and other parts, of how a Von Neumann architecture computer works (almost all computers are based on this architecture). There's nothing special about memory in the context of Java.
 
Ivan Jozsef Balazs
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You think I do not need to care about memory in java.



No. I did not really understood your questoin but made a guess and replied accordingly.

You should not take much care of the details how an Object is laid out in memory, how much space it takes, what is the bit pattern etc.

But you you should know about stack and heap, hashCode and its role when using an object as a key in a, well, hashcode-based data structure like a HashTable.

Their detailed discussion of these topics is however beyond my scope now. Fortunately there are tutorials and search engines.

I found this.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Volodymyr Levytskyi wrote:But why do people say that all java objects in my program are stored in HashTable where key is hash-code of java object.
Is this true?


It is not true in general that all Java objects are stored in a HashTable. There's a class java.util.Hashtable and a class java.util.HashMap; those are collection classes in which you can store objects by key, and the key is not always the hash code of the object. The key is whatever you want. It sounds like you are mixing up things. Also, storing objects in a Hashtable or HashMap has little to do with how the objects are stored in memory at a low level.

Volodymyr Levytskyi wrote:Please tell me in short what is heap and stack and do they affect performance of my program...


The heap and the stack are basic concepts of how modern CPUs and operating systems deal with memory.
 
Ivan Jozsef Balazs
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


how exactly the data of an object is stored is not specified



It is not specified, and you do not have access to it from Java, so it is moot to ask.

You can not even tell how much memory an Object needs internally.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic