Re: why java does not support pointers



The Java Language Specification defines a reference as:

"An object is a class instance or an array.

The reference values (often just references) are pointers to these
objects, and a special null reference, which refers to no object."

From
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#106237

Java supports pointers.

However, Java doesn't support pointer arithmetic (well, it does, as of
Java 1.5, but I'm not interested in telling you how). It doesn't
support converting an int to a pointer either.

This is much better, because we can now write code that won't cause
segfaults or General Protection Faults. Instead we get a nasty old
NullPointerException, for different reasons.

Recent Usenet addicts will note that I haven't taken this delightful
opportunity to post a link to a certain article..

Cheers.

.



Relevant Pages

  • Re: The Java no pointer big fat lie!
    ... > reference types, it wouldn't be a good comparison. ... and what you can't - and there is a big difference in Java to C and C++. ... You cannot change it in the language itself, ... Thus I would distinguish pointers from ...
    (comp.lang.java.programmer)
  • Re: Java Generic programming using subclassing
    ... Java nowhere guarantees that the elements of an array ... Now chances are that any Java ... > reference will be visible through the other. ... > eligible for garbage collection, and will in fact be collected before ...
    (comp.lang.java.programmer)
  • Re: How long to learn C++ if fluent in Java?
    ... I know this "Java has no pointers" mantra. ... The point is, however, that Java reference behave much more like C++ ... unlike with democracy, for some purposes there is indeed a better tool to ...
    (comp.lang.cpp)
  • Re: Opinions on the Law Of Demeter
    ... all that line of code is doing is declaring a reference of type A ... There are only references in Java, no pointers in the C/C++ sense. ... of allowing others to instantiate an object of type A and set it via the ...
    (comp.object)
  • Re: Trouble with Java concepts
    ... >>references when you see a variable which names an object in Java think of it as ... I would try to explain to an incoming C/C++ programmer that passing objects ... is functionally identical to passing pointers in C. ... use of pointers is implicit (you cannot have an Object, only a reference) ...
    (comp.lang.java.programmer)