Re: Trouble with Java concepts

From: Gary Labowitz (glabowitz_at_comcast.net)
Date: 07/04/04


Date: Sun, 4 Jul 2004 02:41:17 -0400


"Steve Horsley" <shoot@the.moon> wrote in message
news:cbuv8i$tpu$1@news.freedom2surf.net...
> Roedy Green wrote:
> > On Tue, 29 Jun 2004 16:19:07 -0700, "P.Hill"
> > <goodhill.REMOVE@xmissionREMOVE.com> wrote or quoted :
<snip>
> I would try to explain to an incoming C/C++ programmer that passing
objects
> is functionally identical to passing pointers in C.

And at that point you would be wrong. Virtually everything you say beyond
that point is also wrong. You are starting with a nonsense concept of
"passing objects" in Java and go astray from there.
Unlike C++, Java does not pass objects. It passes variables. Period. This is
a change in mindset which causes some C++ programmers to think of Java as
"flawed" in some way. Perhaps some Java programmers think of C++ as "flawed"
in the opposite direction. The actually state of affairs is that they are
two different languages (just as C and C++ are) and cannot be thought of in
the same mindset.
I am amused/bemused/frustrated at one time or another trying to teach these
concepts in class and grow weary of arguing with some VB-student about
passing conventions in Java. The only saving grace is to be precise in the
programming language you are using and apply consistent terminology
regardless of which language one is using.

For example, you say
"I would try to explain to an incoming C/C++ programmer that passing objects
is functionally identical to passing pointers in C. Except that since the
use of pointers is implicit (you cannot have an Object, only a reference)
there is no need for the java syntax to constantly mention the fact that the
reference is being used. Thus, you could pretty-much convert java to C by
replacing "." with "->" and putting a "*" before all object (i.e. non-
primitive) variable definitions.

All java objects are on the heap."

This is a hodge-podge of terminology that will lead to a partial
understanding of what is going on, mixes up what a pointer is and isn't,
uses the term "object" in various ways, and drags in operators that don't
exist in one language and have multiple (context sensitive) meanings in the
other. The end result is a statement like
"All java objects are on the heap." which isn't strictly true either (unless
you consider the literal pool as part of the heap, another misnomer).

I prefer the straighter path of defining the terms and using them
consistently. Unfortunately, this takes more space than we are willing to
use in usenet postings, although there have been many and eventually they
all come to the same conclusion; namely, it ain't easy.

-- 
Gary


Relevant Pages

  • Re: A newbie question on out parameter
    ... >> language where a parameter is passed by value. ... >> the action of passing by value will make mistakes. ... But consider that in Java "references to objects" are ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Java
    ... >>semantics from passing references by value in Java. ... parameter passing in Java started to ... Java doesn't have pointers in the sense that it doesn't have something ...
    (comp.programming)
  • Re: Trouble with Java concepts
    ... >>is functionally identical to passing pointers in C. ... I should have said that passing object in java is functionally equivalent ... For a newcomer from C/C++, I think it helps to be able to compare what ...
    (comp.lang.java.programmer)
  • Re: pass by reference
    ... newsgroup that includes people who are trying to learn how Java ... Let me add two quotations to this thread: ... value of that pointer is passed by value, to be call by reference. ... that Java is passing everything by value, ...
    (comp.lang.java.programmer)
  • Re: no pointer in Java => my problem
    ... or passing the address of an object as a parameter. ... Java just offers passing the address of an object as a parameter. ... Java folk were trying to design a simplified language for a TV set top ... Call by reference is an Algol-60ish sort of notion. ...
    (comp.lang.java.programmer)