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.

2
  • 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 Commented Nov 17, 2014 at 14:41
  • You can check out the implementation for some of the most used JVMs as the source code is open: stackoverflow.com/a/2026360/831507 Commented Nov 17, 2014 at 14:43

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.