Re: programming concepts > specific languages



"vishnuvyas" <vishnuvyas@xxxxxxxxx> wrote in message
news:1130969976.887665.187530@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Take for example C, where you have pointers, that gives
> you immense control over the code you are writing and thats a concept
> you have to learn (things like indirection), however thats again C
> specific. You probably would never have to actually learn about
> pointers if you are just doing java all along.

Java has consistent, but non-intuitive, rules involving passing by
value/passing by reference. A lot of beginning Java programmers don't
understand why when they pass primitive types (int, float, char, etc.) they
seem to be passed by values, and yet when they pass objects, they seem to be
passed by reference.

Actually, everything is being passed by value; it's just that when
you're "passing an object", you're actually passing a reference to that
object (and you're passing that reference by value).

I find that it helps a lot to understand the underlying memory model of
a typical RAM machine to "get" Java's passing rules. You don't need to know
much, but you do need a concept of something like a giant array representing
RAM (i.e. each slot has an address), and that some locations in RAM don't
actually contain the desired value, but instead contain the address of the
desired value. An introductory course to machine architectures and "high
level" assembly would probably help a lot.

So I think it may actually be very helpful to learn about pointers if
you're a Java programmer.

- Oliver


.



Relevant Pages

  • Re: pointer syntax
    ... > really passing a reference (which is like an old-school pointer, ... > a copy of the primitive's value and passing that. ... build them yourself with pointers. ... mean a var parameter, write a var parameter. ...
    (comp.lang.pascal.delphi.misc)
  • Re: no pointer in Java => my problem
    ... >> the value you are passing is an adress and you can't change the ... When passing a reference, you don't get ... > code anyway, where there are no pointers or references, just bit ... can design applications using objects and still implement them in C. ...
    (comp.lang.java.programmer)
  • Re: pointers and array of pointers
    ... I often think of pointers as a VARIABLE that contains a reference ... Want you want to do in myswap is pass the ... You do this by passing ...
    (comp.lang.c)
  • Re: dont understand looping problem
    ... > passing pointers is still pass by value. ... by reference" -- that is, you pass an object by reference by passing a ... My goal in these books is not to clutter them up with overly precise ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Real World Flunks (Re: Why is Object Oriented so successful)
    ... AndyW wrote: ... "modeling the real world". ... CADD screen closely matches the object pointers in a typical real- ... I think the fact one has a reference to it ...
    (comp.object)