Faraz Alig wrote:
Do we have a similar such things here as well in Java?
As already mentioned, pointer arithmetic doesn't exist in Java. However, an array dereference is incredibly fast, so there is nothing wrong with your standard index arithmetic for arrays.
I'd ask why you *want* to know the memory address of an array. Are you trying to do something with JNI?
Faraz Alig
Greenhorn
Joined: Mar 14, 2010
Posts: 24
posted
0
David Newton wrote:I'd ask why you *want* to know the memory address of an array. Are you trying to do something with JNI?
Hi David,
I am new to Java and just learning Arrays right now.
Suppose list1 and list2 are the reference to two different arrays
For the expression list2 = list1;
then both point to the same array.
Just to clarify this i want to know the memory address as this will be a solid evidence to prove this point.
Thanks,
Faraz
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
posted
0
Faraz Alig wrote:
Suppose list1 and list2 are the reference to two different arrays
For the expression list2 = list1;
then both point to the same array.
For any reference variable, setting ref1 = ref2 will mean that they refer to the same object. To see if this is true, simply check if ref1 == ref2.
Md Ibrahim
Greenhorn
Joined: Mar 24, 2010
Posts: 14
posted
0
hi faraz,
I dont know if you are using any IDE like eclipse, If you do then its very easy to debug and find at runtime
the unique ID's created at runtime for variables and objects.
For eg:
Test aTest1 = new Test();
Test aTest2= new Test();
here aTest1 will have an ID say 34322 and aTest2 something different 34644
but if you execute below statement
aTest2 = aTest1;
after this line if you see both test1 and test2 will point to same reference id 34322
same applies for all other attributes in java.
By,
Ibrahim
Faraz Alig
Greenhorn
Joined: Mar 14, 2010
Posts: 24
posted
0
Hi Ibrahim,
This point of yours is indeed useful for the verification of such things.
In Java, you don't need to know the memory address of an object. Java does not have pointers like you have in C, and you never need to deal with things such as the addresses of objects in memory. So forget about things like memory addresses when you're programming in Java - it doesn't apply and will confuse you if you try to apply those ideas from C to Java.
As Pete says, you can use the == operator to check if two variables refer to the same object in memory.