What is the difference between a pointer and a reference variable in Java?

后端 未结 9 1589
南笙
南笙 2020-11-28 15:42

My Java book explains that to use objects, we can assign them to reference variables. How is that different from a pointer to an object? Does Java have pointers?

T

相关标签:
9条回答
  • 2020-11-28 16:22

    pointer only contain the address but Reference does not contains address if we say frankly then address of the object is assigned to the index or we say can hash code and case code is given to the reference variable if we will see the content of the reference variable it starts with class Name @ and after it some Hexadecimal Code. These nos are not address it is a index value or hash code.

    second point we can not perform any Arithmetic operations on values the Content of reference value

    0 讨论(0)
  • 2020-11-28 16:25

    The terms "reference" and "pointer" are basically equivalent. Much of the literature I've seen about the basics of Java claims that Java has no pointers. But if you try to use a null reference you get a NullPointerException. So it's all semantics.

    (The real difference is, in C or C++ the term "pointer" strictly means an integer that happens to be the memory address of some data. Whereas in Java the term "reference" more closely matches the C++ "reference" concept. You can't work with the memory address directly even if you want to, but you use it the same way.)

    0 讨论(0)
  • 2020-11-28 16:25

    No, Java does not have pointers. The fundamental concepts in Java are "values" vs "references".

    0 讨论(0)
提交回复
热议问题