Straying from topic but I think the comparisons are interesting.
> > <snip> In most contexts, a pointer acts just
> > as though you had used the target directly. Another way of describing
> > this is that pointers are automatically dereferenced. You don't do
> > anything like the c "^" to dereference the pointer; just using the
> > pointer name as is already implies dereferencing.
>
> You mean *. (I haven't done Pascal for a while, it might be ^ there.)
>
Yes; C is prefix * and Pascal is postfix ^ . C subscripting a[i] is
actually defined in terms of pointer arithmetic as *(a+i), so postfix
[0] functions as an extra-clumsy dereference operator.
<snip>
> > I am told (if I recall correctly) that Fortran pointers are somewhat
> > like Java reference variables, but I haven't used Java at all and I
> > could easily have that confused (or have been told inaccurately).
>
> Java has object reference variables instead of pointers, but there
> is no dereference operator. If you assign one, it copies the reference.
> Arrays (which are Objects) you dereference with []. Multidimensional
> arrays are arrays of arrays, and dereferenced with multiple [].
Yes. You can also read .length of an array, but it's not clear to me
if that's actually with the array body/elements or not.
> Otherwise, an Object has more similarity to a structure, and is
> dereferenced by the . operation. Any other operation, such as the
> previously mentioned deep copy, is done by a method invocation.
>
Mostly. A class reference is actually dereferenced only by fetching or
storing a field. Often this is done by obj.fieldname, but for 'this'
references within a non-static method or ctor or init-block you can
use just fieldname. Conversely obj.method(...) calls pass the objref
to the method if non-static, but don't dereference it. And you can
access both static fields and static methods using
obj.name, but the
actual object is ignored and only the declared reference type is used.
(Eclipse normallly warns for this like 'should use static access'.)
> All variables are passed by value, either the value of a primitive
> (char, short, int, long, etc.) or the value of an Object reference.
> If you don't change the value of the (I forget what Java calls
> dummy variables) then it looks like call by reference, but you can
> change the local Object reference.
>
Java like C (and C++) and PL/I uses actual 'argument' and formal
'parameter'. Pascal and Ada use actual and formal 'parameter'. COBOL I
don't have the standard and IME implementations aren't consistent,
although the syntax overhead plus convenience of PERFORM as a cheap
quasi-call with no explicit data encouraged large procedures and few
real calls. Fortran (of course) uses actual and dummy 'argument'.
> The == operator will compare the Object reference, not the Object.
Yes. Or more exactly not the objects, which can be any nonprimitive
type not necessarily java.lang.Object. A reference to any object can
be converted to reference to Object, but the object itself retains its
specific type like String or HashSet<T> or FileInputStream etc., and
the reference to Object can be cast back to reference to the actual
type or any other superclass or interface of it, but not an unrelated
reference type. And != equivalently of course.
> The equalTo() and compareTo() methods allow comparison of objects.
>
Somewhat.
.equals(Object) (not equalTo) is declared in Object and so exists for
all objects; but the default implementation in Object just compares
the references, like ==. Classes where a different equality relation
makes sense must override; for example java.lang.String implements
.equals to check if the two String's contain the same sequence of
characters. Arrays inherit only from Object and use the default
reference-equals, but java.util.Arrays provides (overloaded) static
.equals(a,b) methods that compare the contents.
<T>.compareTo(T) is declared by interface java.lang.Comparable, which
is used for some standard classes but not all. It is not implemented
for arrays directly nor in java.util.Arrays, nor anywhere else in the
standard JRE that I have found. User classes can of course implement
it if and as chosen.