Joshua Maurice said:
I feel the exact same way about the word "pointer". Oh how much I
loathe talking about Java "references". They should rightfully be
called pointers. I've had several fun conversations about how all Java
functions pass by value, and people will say "nu uh!" because it's "a
reference". The object is not copied, but the reference is copied.
Modifying a parameter reference will not modify the callers reference,
but modifying the pointed-to object in the function will modify the
caller's object. This sounds a whole lot like pointers to me.
AFAIK (I'm not a Java programmer) there are significant differences
between C/C++ pointers and Java references.
C++ pointers are more tied to low-level memory addresses. You can
perform pointer arithmetic to them (eg. "pointer+1" to get a pointer
to the next element in an array pointed by 'pointer') and you can
unambiguously and consistently compare pointers (in standard C++ at
least with std::less and the other comparison templates). ("Consistently"
in this case means that if you compare two pointers now and the same
pointers one minute from now, you will get the same result.) Because C++
pointers are basically memory addresses, this allows casting a pointer
of one type to a different type (if you are doing a reinterpret-cast,
then the memory address doesn't change).
There are both advantages and disadvantages to equating pointers with
memory addresses in C/C++. It allows more low-level flexibility when
dealing with raw memory and performing other tricks (such as xor-lists),
but on the other hand it makes it more rigid with respect to the memory
allocator (making it more difficult to implement things like garbage
collectors and memory compactors in a fool-proof way).
Java references are much more abstract. They are not tied to a specific
memory address, you can't compare them (other than for equality, I think),
you cannot cast them to incompatible types and obviously you cannot perform
pointer arithmetic.
AFAIK it's possible for a reference to be "pointing" to one memory
location at one moment, and a minute later the memory management system
having changed it to "point" to a completely different location (completely
transparently from the program's point of view). This allows things like
memory compaction (which is good for cache optimization and other things).
This is not possible in C++ because of the raw wild memory pointers.