File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes References to Variables in Memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "References to Variables in Memory" Watch "References to Variables in Memory" New topic
Author

References to Variables in Memory

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

When a reference is made to a variable stored in memory and is grabbed for use, does the JVM make a copy of that variable to manipulate, or does it grab the original and manipulate that? And if it does grab the original, how does the JVM keep track of that in memory?

------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
vicky bawge
Ranch Hand

Joined: Sep 04, 2001
Posts: 34
Hi Gregg,
The JVM does manipulate the original and it doesnt care how many other references are pointing to it. once it manipulates the original, all the references, as they are just pointing to the original stuff get updated automatically.
Its like your ten relatives have your house address and you paint your house with different color. Dont you think, If all of them follow the address (reference) and visit your home, should see the new paint on your house.
Does that answer your question,
-Vivek
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

It does for half of my question. But how do the "relatives" know where it is in memory? Is it pointers? And if so, does anyone know why JAVA does not allow the use of pointers in programming?
------------------
Happy Coding,
Gregg Bolinger
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

The ClassLoader manages each class tracks all object references in its space. This tracking is done by way of a hashcode which could arguably represent a memory address.
But an object reference doesn't directly access the process map; the JVM does that. The JVM does not expose that map to its classes.
You really really really want a pointer, don't you?
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

LOL, I just don't like the fact that I can't manager MY memory. I know that JAVA has done a good job with the garbage collector but I still like a little more control.
Thanks for everybodies replies.

------------------
Happy Coding,
Gregg Bolinger
Mark Herschberg
Sheriff

Joined: Dec 04, 2000
Posts: 6037
Originally posted by Gregg Bolinger:
LOL, I just don't like the fact that I can't manager MY memory. I know that JAVA has done a good job with the garbage collector but I still like a little more control.

In a far off kingdom long ago, all the peasants complained about having to drag their trash out to the dump. It was too time consuming. It was labor intensive. It wasted time they should have spent building better houses, and distributed systems (these were very advanced peasants). So the king, a wise man, arranged for community trash removal, paid for by a small increase in taxes. There was much rejoicing.
Then the peasants complained they wanted their trash back. For you see, they were used to realizing they accidentally threw something out, like a child's retainer, or linked list, and could go back to the dump to take it out. But now that someone else remvoed their trash, they didn't know where it was put in the dump, and couldn't find it again.
So the king asked his knights of the hash table for advice, and they created a public relations office for the dump. This would keep track, reference if you will of where the garbage was placed in the dump. Of course, the dump would often recycle the garbage and not let the public relations office know, so it wasn't quite perfect. Some said this system was weak; the kings detractors called him soft on garbage removal. but more people were happy.
The system is pretty complex now. Further improvements in the system won't be easy. If there are to be any, they are likely to come from the king's wizard, Merlin. So you'll have to check Merlin's web site for more info.
The end.

--Mark
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Neat story. And now forgive me for being ignorant, but Merlin is java.sun.com??
And could someone show me a link for the information that Mark suggested? And maybe with a little less drama?
Thanks

------------------
Happy Coding,
Gregg Bolinger
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
LOL - I love it !
Merlin is the jdk1.4 that is now in beta release. http://java.sun.com/features/2001/06/golden.j2se.html


"JavaRanch, where the deer and the Certified play" - David O'Meara
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thank you Cindy.

------------------
Happy Coding,
Gregg Bolinger
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Is there a new API Doc available for download for the 1.4 additions?
Can't seem to find one if there is.
Thanks for any help.
Never Mind, I found it on-line. Thanks though
------------------
Happy Coding,
Gregg Bolinger
[This message has been edited by Gregg Bolinger (edited October 17, 2001).]
Mark Herschberg
Sheriff

Joined: Dec 04, 2000
Posts: 6037
The "Public Relations" office was a veiled reference (maybe I should say, weak reference :-), to the java.lang.ref classes. See the standard API docs for them.
Also read http://developer.java.sun.com/developer/technicalArticles/ALT/RefObj/index.html

--Mark
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Sure you don't mean Phantom reference? <rimshot>
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
vicky bawge
Ranch Hand

Joined: Sep 04, 2001
Posts: 34
Of course JAVA HAS POINTERS.
but they are very very restricted.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by vicky bawge:
Of course JAVA HAS POINTERS.
but they are very very restricted.

Could you explain?

------------------
Happy Coding,
Gregg Bolinger
vicky bawge
Ranch Hand

Joined: Sep 04, 2001
Posts: 34
Hi Gregg,
All you need to know about the ugly pointer is here http://cslibrary.stanford.edu/106/
I am calling it ugly because it somewhat takes us back to the old days of assembly language where the programmer had to deal with the hardware intricacies like memory layout, cpu code instructions etc. I agree its not that bad but its one thing that doesn't allow us to abstract away from the computing machine.
Thanks,
-Vivek
vicky bawge
Ranch Hand

Joined: Sep 04, 2001
Posts: 34
Everything is a pointer (reference) in java including the basic data types.
e.g even you can call getClass() for int.
Any objections.
-Vivek
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: References to Variables in Memory