1

Hi,
We no that their no support for Pointer in Java as in C and C++. So how can we print the exact location of a varaiable in java?

Shahab

3
Contributors
5
Replies
7
Views
8 Years
Discussion Span
Last Post by stephen84s
0

I want to create a Table of Variables and their values regarding their Memory location. In simple words I am going to implement Linklist (My Assignment) and wants to know wether my current node holds the memory address of the next node?

Shahab

0

If you are not aware then there is a soft form of pointers in Java only they are called "references".

Whenever you create an object in Java as :-

Alpha var1 = new Alpha();
Alpha var2 = var1;

"var1" and "var2" are actually references to the same object of class "Alpha". Try some small programs you will figure it out.

0

Thanks for reply.
No I am not confused in referencing. As we use

cout<<(&someVar);

in C++ which will print the memory address of the someVar. then how we can do it in Java?

Shahab

1

in C++ which will print the memory address of the someVar. then how we can do it in Java?

Why are you obsessed with printing memory addresses, when you can accomplish your linked list with "references" in Java.
<EDIT>

I willl just put a simple example here of how a simple node of a linked list can be implemented:-

class Node {
  int data;
  Node next;
}

Hopefully this will make it more clear. You can also check out this and this for some more explanation on how "references" are handled in Java.

Votes + Comments
It will sink in eventually :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.