Is it possible that we can access memory location in Java directly or indirectly?
If we tries to print a object, it will print hashcode. Does hashcode signify indire
No, hashcode, in general, has nothing to do with memory location. The memory location of your object is the object's reference itself.
However, it may not be quite impossible to squeeze out the actual location. Java Object
's hashcode is, according to its javadoc, typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java programming language. And there's System#identityHashCode(Object)
method, which will return the same hash code for the given object as would be returned by the default method hashCode() (that is, Object
's hashCode()). So this way you may indeed be able to get the actual memory location. But whether this works is, as said above, implementation dependent. And since you definitely won't be able to directly read/write in the memory even though you knew the location, what would you do with that information?