-4

Since java does not support pointer(memory address) , then how is the reference exists in memory and how a reference variable use it ??

  • 1
    http://stackoverflow.com/questions/1574009/how-is-reference-to-java-object-is-implemented?rq=1 – Sednus Mar 22 '13 at 02:55
  • 2
    A "reference" in Java is an implementation detail leak - fully endorsed by the JLS, though! - used to describe the semantics of allowing a variable (which is a "storage location") to "refer to" an object - by storing a "reference" to the object. (I say it is an implementation detail leak because the same semantics can be discussed *without* using the term "reference" - consider the JavaScript/ECMAScript specification.) –  Mar 22 '13 at 02:56
  • @pst, I think this should have been an answer ;) – Pradeep Simha Mar 22 '13 at 03:20

1 Answers1

2

Since java does not support pointer

Yes it does. Why do you think there is a NullPointerException? Pointers can either be null or contain a reference to an object.

(memory address),

Exactly. It doesn't support memory addresses, and it doesn't support C/C++ semantics on pointers as memory addresses. All you can do with a Java pointer is assign it or dereference it.

then how is the reference exists in memory and how a reference variable use it ??

See the JLS: "The reference values (often just references) are pointers to these objects, and a special null reference, which refers to no object."

user207421
  • 305,947
  • 44
  • 307
  • 483