• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does java have pointers?

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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++.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic