This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

What is meant by dereferencing?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there,
while compiling a program, i got this error:
" byte cannot be dereferenced"
please let me know what actually dereferencing is?
prabal.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dereferensing means setting the reference to NULL. This way
you are no longer referencing any obj. This is one way.
Could you post your code.....
regds.

- satya
 
prabal saha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Madhav,
i got the point that was causing this eror.As for the code my approach was wrong.
 
Sheriff
Posts: 6920
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't agree with the explanation here. "dereferencing" actually refers to the process of getting or setting the value referred to by a reference.
For example, If I say
String s = "hello"
then s is a reference to the actual characters. In this case I can dereference s to get the characters, but if I say, for example
String s = null;
then I can't dereference s, because it does not refer to any characters - it is null!
In the case of the initial question, I would imagine that the code was trying to call a method on a byte, and as byte is a primitive type which contains its own value, and not a reference to an Object, it could not be dereferenced. For example:
byte b = 45;
System.out.println(b.toString());
will not work (if you need to call a method, you should have used the object wrapper class Byte, instead), and neither will
byte b;
b[7] = 23;
where the [] have inadvertently omitted from an array declaration.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general, Reference is an address to some object/variable, While getting or setting value for that variable you need to de-reference that (means you need to get to that location where it is actually laying in the memory).
Dereference is a common operation done by C++ programers.
Hope this will clear Dereferencing.
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heya Frank -
Thanks for your post. I don't use this particular term myself except by accident, partly because I've heard it used both ways with equal vigor and confidence.
Judging only by the way I've most often seen it used, deferencing meaning "setting to null" seems the popular meaning for Java.
Dereferencing meaning "get the value of" sounds suspiciously like C/C++ semantics.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
[This message has been edited by Michael Ernest (edited February 20, 2001).]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Believe me, using "dereference" to mean "set to null" is a misconception. You won't find it anywhere in any official Java documents. If you have encountered it a lot, that just means it is a popular misconception
 
Ranch Hand
Posts: 113
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just for the record.
dereferencing (in java) = Action of accessing an object's features through a reference.
so in java:
String s = new String("");
s.toString(); // dereferences s

 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, dereferencing is the action of retrieving the value pointed to by a reference. Have a look at the
Online Dictionary of Computing
[This message has been edited by Graeme Brown (edited February 22, 2001).]
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

From Frank:
Believe me, using "dereference" to mean "set to null" is a misconception. You won't find it anywhere in any official Java documents. If you have encountered it a lot, that just means it is a popular misconception


Agreed!!!
Java does not allow dereferencing does not redefine the term "dereferencing".
Roseanne
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a Program Languages theory term, Program Languages theory does not redefine since there is a language called Java.
Roseanne
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is in C++ language:
Object* pObj = new Object();
// equivalent to java: Object obj = new Object();
// you can see obj in Java actually is a pointer
// that is why there is a NullPointerException in Java
Object** ppObj = &pObj;
// dereferencing the Object address
// or find out where you store the Object address
// pointer of pointer in C++
// There is no Java equivalence to it.
Java is a lot safer than C++ because of it, but less powerful to certain extent.
Thanks!
Roseanne
Join our SCJD Study Group when certified

[This message has been edited by Roseanne Zhang (edited February 22, 2001).]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic