Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am not getting K&B page 445

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear sir i am not getting following paragraph of k&B page 445 that is

"In java it wouldn't make any sense to save the actual value of a refrence variable , because the value of java refrence has meaning only within the context of single instance of a jvm. In other words if you tried to restore the object in another instance of jvm, even running on the same computer on which the object was originally serialized, the refrence would be useles."

Hear what does mean by the instance of jvm,running on same or diffrence computer ?

plese clearify me.

with regard

Arun kumar maalik
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An instance of the JVM represets a seperate process of execution. For example if you were to run your program twice simultaneously on the same machine then you are running two instances of the JVM on the same machine. Every instance is a seperate process
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two different instances of jvm means twice you are executing your program by java.

When you run java className, you get one instance of jvm.

What author is trying to say that simply passing the reference of a object which is class@hashCode to a different instance of jvm either running on the same machine or a remote machine will not copy the whole state of the object. If you can do so, then probably serialization will not come into the picture.

reference value is jvm instance specific. It has no meaning to a different jvm running on the same or a remote m/c.

Naseem
 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir i have understood

Arun kumar maalik
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naseem Khan:
...the reference of a object which is class@hashCode...

Not quite. In general, an object reference is a memory location, telling the JVM where to find the object. So obviously, this might be different with each execution.

(Remember, hashCode can be overridden to return any int, including a constant.)
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, an object reference is a memory location, telling the JVM where to find the object


I agree with you. But if you print the reference, it gives class@hashCode. toString() method defined in Object class calls Integer.toHexString(hashCode()) and it converts hashCode value in hexadecimal representation.

It seems that even the reference point to an object on heap but still you can't get the memory address of the object by its reference.


- Naseem
[ August 27, 2006: Message edited by: Naseem Khan ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naseem Khan:
...if you print the reference, it gives class@hashCode. toString() method defined in Object class calls Integer.toHexString(hashCode()) and it converts hashCode value in hexadecimal representation.

It seems that even the reference point to an object on heap but still you can't get the memory address of the object by its reference...

The toString method returns a String representation of the object. I don't know of a way to get at the actual reference value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic