Step 1 of 4

Phase 1: Creation & Access

How 1D primitive arrays are allocated and accessed.

What's Happening?

Execution starts. The JVM creates a thread stack and pushes a Stack Frame for main().

The Stack

Local variables live here. They are destroyed when the method returns.

The Heap

Objects and Arrays live here. They persist until garbage collected.
Main.java
1
public class Main {
2
public static void main(String[] args) {
3
int[] numbers = new int[5];
4
System.out.println(numbers[2]);
5
numbers[2] = 50;
6
}
7
}

Thread Stack

main()
No local variables

Memory Heap

Heap is empty.