Course contentsShow
← Java
Lesson 243 of 2,8706. ArraysFree lesson

Array Declaration vs Instantiation

Distinguish between declaring an array variable and actually creating the array object in memory.

Array Declaration vs Instantiation

What you'll learn: You'll understand the two distinct steps of creating an array—declaring the variable and actually allocating memory for it.

The Two-Step Process

When working with arrays, beginners often confuse declaring an array variable with creating the actual array object. These are two separate operations that can happen at different times in your code.

Declaration means you're announcing that a variable exists and what type of data it will hold. You're essentially reserving a name:

int[] numbers;  // Declaration only - no array exists yet!

At this point, numbers is just a reference variable. It doesn't point to any actual array in memory—it holds null. Think of it like having a remote control with no TV connected.

Instantiation means you're actually creating the array object in memory using the new keyword:

numbers = new int[5];  // Now the array exists with 5 slots

Now memory has been allocated for 5 integers, and numbers points to that memory location.

Combined vs Separate

You can do both steps in one line:

int[] scores = new int[10];  // Declare AND instantiate

Or keep them separate:

String[] names;      // Declare first
// ... other code ...
names = new String[3];  // Instantiate later

Separating them is useful when you don't know the array size at declaration time, or when you want to create the array conditionally.

Key Takeaway: Declaration creates a reference variable; instantiation creates the actual array object in memory. Both are required before you can use an array.