Do we have pointers in Java?
What is the difference between a pointer and reference variable?
Doubt regarding Pointers in Java
@ankitbajaj01010,
No we don’t have pointers in Java, instead we have references.
Reference: A reference is a variable that refers to something else and can be used as an alias for that something else.
Pointer: A pointer is a variable that stores a memory address, for the purpose of acting as an alias to what is stored at that address.
Every pointer is a reference, but every reference is not necessarily a pointer.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
A reference is sort of like a pointer that you can’t do arithmetic on… although it’s more opaque. While the underlying bits may be an address in virtual memory, they don’t have to be. They’re just a way of getting to an object (or representing the null value). So while they’re not exactly the same, if you’re used to thinking of a pointer as “a way of identifying an object or navigating to it” (in some sense) then yes, those thoughts apply to references too.
Java doesn’t have pointers as such (unlike, say, C# which has references and pointers - the latter being used in “unsafe” code).