Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does java have pointers?

 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does java have pointers like C++?
How does java handle pointer concept?
[ June 30, 2004: Message edited by: Santosh Ram ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nitin Shivaram
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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++.
 
Jared Sprague
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

sev
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic