This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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
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
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
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.
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).]
Originally posted by vicky bawge: Of course JAVA HAS POINTERS. but they are very very restricted.
Could you explain?
------------------ Happy Coding, Gregg Bolinger
Joined: Sep 04, 2001
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
Joined: Sep 04, 2001
Everything is a pointer (reference) in java including the basic data types. e.g even you can call getClass() for int. Any objections. -Vivek