Array as Reference Types
You'll learn that arrays in Java are not simple containers like variables, but objects stored in a special memory area and accessed through references.
Arrays Are Objects, Not Primitives
When you declare an array in Java, you're not creating a simple variable like int x = 5. Instead, you're creating an object that lives in a part of memory called the heap. The variable you declare doesn't hold the array itself—it holds a reference (think: address or pointer) to where the array actually lives.
int[] numbers; // This declares a reference variable
numbers = new int[5]; // This creates the array object on the heap
The Reference vs The Object
Think of it like this: your array variable is like a TV remote control. The remote isn't the TV itself—it just points to and controls the TV. Similarly, your array variable isn't the array—it just "points to" where the array lives in memory.
int[] first = new int[3];
int[] second = first; // second now points to the SAME array object
first[0] = 42;
System.out.println(second[0]); // Prints 42! They share the same array.
Both first and second are references pointing to the same array object on the heap. Changing the array through one reference affects what you see through the other, because there's only one array.
Why This Matters
This reference behavior is fundamentally different from primitive types. With int x = 5; int y = x;, you get two independent values. With arrays, multiple variables can reference the same underlying data.
Key Takeaway: Arrays are objects stored on the heap and accessed via reference variables—changing an array through one reference affects all references pointing to that same array.