aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is dereference? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "what is dereference?" Watch "what is dereference?" New topic
Author

what is dereference?

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383

This example is from Whizlabs. This code wont compile. The reason they have given is at line 1 we are attempting to dereference the primitive type float. I even heard "deference" word first time. Can anyone please help me?


SCJP-1.5<br />SCWCD-1.4
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3327

I know one such term 'dereferencing' with respect to 'C'/'C++' Pointers, which actually means 'taking out the value stored in a particular memory address being pointed to by this pointer value'.

If, p is a pointer to an integer and it can be used as follows.



Here, they would have meant to say the same 'unboxing' i think. As, boxing and unboxing are the means to convert your primitive to wrappers and vice versa.

does that help dolly shah?
[ October 08, 2007: Message edited by: Raghavan Muthu ]

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Variables do not hold objects. Instead, variables hold references to objects.

So myVariable is just a reference -- not the object itself. But in order to call a method, we need the actual object. The dot operator "dereferences" the variable and "gets" the object.

However, a primitive variable holds the actual value. It does not just reference it. Therefore, primitive variables cannot be dereferenced. So if you try to use the dot operator on a primitive variable, you will get the "cannot be dereferenced" error.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Thanks marc. I did not know this before.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: what is dereference?
 
Similar Threads
Having doubt to understand the given answer/explanation
Autoboxing- dereference a primitive
float error
float doubt
Float argument