Reputation: 1073
I am looking for how arrays are implemented in java with respect to JVM.
In other words if I do int[] i = new int[5];
how jvm will store 5 integers?
is that code accessible? if yes where?
Thank You in advance.
Upvotes: 0
Views: 226
Reputation: 2326
Here is how arrays are stored in JAVA.
Quoting from the article about how arrays are stored:
"Arrays are also objects in Java, so how an object looks like in memory applies to an array.
As we know that JVM runtime data areas include heap, JVM stack, and others."
You can only access any particular array element by the way of the index and not by some internal memory representation in memory or code (JAVA doesn't allow pointer arithmetic like C)
Upvotes: 0
Reputation: 10666
OpenJDK has it's source code available for example here
But to find how an array is actually stored, you'd need to look up how an array is implemented in Java ByteCode and then find the corresponding implementations in the source.
Also keep in mind that different JVM's might have different implementations of how to store arrays.
Upvotes: 1