Re: The Java no pointer big fat lie!

From: Kevin McMurtrie (mcmurtri_at_dslextreme.com)
Date: 02/27/05

  • Next message: Vijay: "Re: Displaying precise error using struts"
    Date: Sun, 27 Feb 2005 00:35:50 -0800
    
    

    So what's your point?

    Does Java have auto variables that construct and destruct by scope? No.

    Does it have inline/netsted object storage? No.

    Are object references a native memory pointer or an abstracted
    reference? Depends on the JVM.

    It's a different language so comparing the finest details to C++ is
    silly.

    In article <1109198825.659612.130510@l41g2000cwc.googlegroups.com>,
     "axter" <temp@axter.com> wrote:

    > Whenever I read a Java book and it states that Java has no pointers, it
    > makes my teeth grind. It would be more accurate to say Java only uses
    > pointers.
    >
    > That's right. Java only uses pointers.
    > However, that also wouldn't be entirely accurate either, but it would
    > be closer to the truth then to say Java doesn't use pointers.
    >
    > When these books make these claims they're usually explicitly or
    > implicitly comparing the Java memory addressing method to the C/C++
    > memory addressing methods.
    >
    > C++ has three main methods for addressing memory. (concrete, pointer,
    > and reference)
    > Concrete address
    > int x = 10;// x is a concrete variable
    >
    > Pointer address
    > int *px = &x; //px is a pointer variable
    >
    > Reference address
    > int &rx=x; //rx is a reference variable
    >
    > Most Java books would have you believe that Java's memory method is
    > not a pointer method, and that it's memory methods are more like the
    > C/C++ concrete method.
    > However, if the characteristics of all three methods are examine,
    > you'll find that Java's memory method characteristics has more in
    > common with the C++ pointers, and have very little in common with the
    > concrete method.
    >
    > In C++, when a concrete variable is declared, its constructor is always
    > called
    > When a reference variable is declared, a constructor is never called.
    > When a pointer variable is declared a constructor is called only if it
    > is initialized by pointing to a NEW-operator.
    > In this characteristic, Java address modal matches only the pointer
    > modal.
    >
    > In C++, a concrete variable must be initialized to address valid
    > memory.
    > A reference variable must also be initialized to address valid memory.
    > A pointer may be initialized to point to nothing at all, or to point to
    > valid memory.
    > In this characteristic, Java address modal matches only the pointer
    > modal.
    >
    > In C++, a concrete variable (once initialized) can never change the
    > memory it's addressing.
    > A reference variable (once initialized) can never change the memory
    > it's addressing.
    > A pointer can change what it's pointing to at any time.
    > In this characteristic, Java address modal matches only the pointer
    > modal.
    >
    > In C++, you cannot assign a concrete variable to new operator.
    > A reference variable cannot be directly assigned to a new operator.
    > A pointer can be directly assigned to a new operator.
    > In this characteristic, Java address modal matches only the pointer
    > modal.
    >
    > In C++, pointer arithmetic cannot be performed on a concrete type.
    > Pointer arithmetic cannot be performed on a reference type.
    > Pointer arithmetic can of course be performed on a pointer variable.
    > This is where Java memory modal and C++ pointers differ. You cannot
    > perform pointer arithmetic on a Java address method.
    >
    > Other then pointer arithmetic, Java's memory modal is very much a C++
    > pointer memory modal.
    >
    > So if a Java book really wanted to be more accurate, it would say:
    > "Java only uses pointers, and Java pointers lack the ability to
    > perform pointer arithmetic."
    >
    > OK, frag away!


  • Next message: Vijay: "Re: Displaying precise error using struts"

    Relevant Pages

    • Re: How java passes object references?
      ... Which everybody knows, it doesn't in Java. ... The reason I think this is a useful clarification is that when you got to the part about how passing by reference might work, it seems you went off track at least partly because you didn't understand the nature of the above. ... is a pointer pointing at the memory block. ... Assignments to local variables, or even to class members, do not allocate memory. ...
      (comp.lang.java.programmer)
    • Re: How java passes object references?
      ... to think of them as being a specific location in a larger block of memory ... Whether a language passes by reference or by value, ... is a pointer pointing at the memory block. ... So when allocating local memory for o, it would simply allocate a ...
      (comp.lang.java.programmer)
    • Re: How java passes object references?
      ... what I understood is memory allocations could be "visualized" as ... But my understanding is that Java byte-code is compiled "just-in-time" into a platform-efficient representation that is actually executed, and that would mean using platform-supported run-time mechanisms like a stack. ... It's theoretically possible to implement Java with individual heap allocations for each function call, but that would be relatively inefficient and I don't believe any mainstream implementation of Java would do it that way. ... All it knows is that some variable of a specific type was used as a parameter, and it's been passed a reference to that variable. ...
      (comp.lang.java.programmer)
    • Re: The Java no pointer big fat lie!
      ... > Whenever I read a Java book and it states that Java has no pointers, ... can't do pointer arithmetic, ie pointer+20 is impossible in Java. ... of the object they reference but to an intermediate which does that. ... A pointer is a memory address in C, no more, no less. ...
      (comp.lang.java.programmer)
    • Re: The Java no pointer big fat lie!
      ... A pointer is a memory address in C, no more, no less. ... >>not what a reference in Java is. ... reference types, it wouldn't be a good comparison. ... My statement is correct with reference to the C++ language. ...
      (comp.lang.java.programmer)

  • Quantcast