File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Does java have pointers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does java have pointers?" Watch "Does java have pointers?" New topic

Does java have pointers?

Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
Does java have pointers like C++?
How does java handle pointer concept?
[ June 30, 2004: Message edited by: Santosh Ram ]

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

it doesn't. at least, not like you're probably thinking.

references to objects are probably implemented using pointers, but you don't have access to the pointer value, you can't do pointer arithmatic, you can't replace array names with pointers...

primitive variables store the value in question.

any object variable does store a reference to the heap where the object is actually created, but for all intents and purposes, you can't do anything with the pointer yourself - except use it to get to the actual object.

at least, that's my understanding.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Nitin Shivaram
Ranch Hand

Joined: Jan 17, 2001
Posts: 71
No it doesn't. That's one of the main selling points of Java. When you get a reference to an object, you are actually getting a symbolic reference and not a direct one. So I am not sure if you can really access the memory like you can in C/C++.

Nitin S<br />Sun Certified Java Programmer for the Java 2 platform.<br />Tekmetrics Certified Java Programmer For the Java 2 Platform.
Jared Sprague

Joined: Jun 16, 2004
Posts: 16
The other nice thing about Java not having pointers is that you dont have to explicitly allocate and deallocate memory on the heap. You can let the garbage collector free memory used by objects with no refrence to them.
sever oon
Ranch Hand

Joined: Feb 08, 2004
Posts: 268
If you accept the idea that a "pointer" is a variable type that refers to a memory location that can be dereferenced to refer to the actual object in memory at that location, then no, Java does not have pointers.

Java has references. The difference being--a reference refers directly to the object in memory. A pointer refers indirectly to that object, and instead directly refers to that object's location.

I'm not sure what your second question asks, exactly. What would you want to do in Java that having pointers would afford you?

I agree. Here's the link:
subject: Does java have pointers?
It's not a secret anymore!