0

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.

Nikhil Joshi
  • 1,053
  • 7
  • 8
  • 1
    No you can't check how objects are stored internally in memory. While you can read JVM specs to know about it. But not with Java code – brb tea Nov 17 '14 at 14:41
  • You can check out the implementation for some of the most used JVMs as the source code is open: http://stackoverflow.com/a/2026360/831507 – Vlad Nov 17 '14 at 14:43

2 Answers2

1

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.

Daniel Figueroa
  • 10,348
  • 5
  • 44
  • 66
0

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)

Anirudh
  • 2,286
  • 4
  • 38
  • 64