In java, varables don't hold the actual object, but a reference to the object. they're like a piece of paper saying "the car is in the garage at THIS address". the paper tells you where the car is, but it is not the actual car.
so, studentname holds where the String object is in memory. by 'dereferencing', they basically mean it goes to the garage to see what kind of car is really in there... or what the actual string is.
In C, you could actually have a variable that was a pointer to somewhere else in memory. you had to do the de-referencing yourself (with the dereference operator). Java does all this automatically. [ May 24, 2005: Message edited by: fred rosenberger ]
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Feb 08, 2004
thanks for your answer, fred
i did get what you said, the problem seems to be in what it literally sounds to me
in some google i made, i found out that making something like
Originally posted by miguel lisboa: [QB] just sounds weird - in my mind dereference would be like making obj = null; [QB]
That is what dereferencing does, garbage collection couldn't function if every object created was referenced until the program exited. Think of the memory leakage. In C++ you must explicitly dereference objects but in Java once an object has finished performing its tasks it is automatically dereferenced and available for garbage collection. This is one of the reasons Java has become so popular because it simplifies object creation and destruction
Joined: Feb 08, 2004
after all author does gives a definition:
dereference to navigate to a memory location based on the memory address stored in a reference
That is what dereferencing does, garbage collection couldn't function if every object created was referenced until the program exited.
Not to be particular (Ok, I am being particular) but this is not dereferencing as explained above. This is more releasing the reference; dereferencing is as has been previously described: following the reference to get the actual object.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.