• Post Reply Bookmark Topic Watch Topic
  • New Topic

Equivalent of C++ Pointers  RSS feed

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

If C++ had the concept of pointers to access the address..and values of

variables and objects...how does java offer the same functionality..

Thnx in adv...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't. Java doesn't give you access to raw memory. Java objects are accessed via references, which behave like pointers in that they can point to an object or be "null"; but they're not interconvertible with integers; you can't do "pointer arithmetic" in Java, and you can't convert an int into a reference, not a reference into an int.
 
Mark Wuest
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by A Kumar:
If C++ had the concept of pointers to access the address..and values of

variables and objects...how does java offer the same functionality..

If you give an example of what it is you want to do, someone might offer a Java solution for you.

Mark
 
Siddhartha Ghosh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look, basically JAVA doesn't allow you to access raw memory directly as in C++ because in the words of the legendary co-founder of JAVA, Bill Joy,JAVA is C++ --. So certain redundant features like Operator overloading and pointers are -- (not available in JAVA) while JAVA has it's own list of special features (Automatic Garbage collection).
However there is an exceptional case where in JAVA you can access memory more directly in case of Video Memory Access. But that's advance level....;-)
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by A Kumar:
Hi all,

If C++ had the concept of pointers to access the address..and values of

variables and objects...how does java offer the same functionality..

Thnx in adv...



Java uses references similar to C++ references. Java prohibits direct memory addressing while C++ pointers allow it. Pointer use is optional and required only for compatibility with C language. You can write complete C++ programs with no pointers at all and you can do that easily and naturally.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!