Lesson Overview
Understand arrays as fixed-size indexed storage and compare them with higher-level collection classes.
Portfolio focus: Draw the indexes for a five-element array.
Starter: think before typing
Before running this data structure foundations example, find the line where the main idea becomes active. Write a prediction: what must already be true for that line to work, and what should be different after it runs? The checked run ends with `Before: 65 After: 70`; predict how the focus line helps produce that evidence.
Learning Objectives
- Create and index a Java array.
- Explain fixed length and zero-based indexing.
- Trace an array update.
- Choose between an array and a collection for a simple task.
Learning Outcomes
- By the end of the lesson, you can create and index a Java array.
- By the end of the lesson, you can explain fixed length and zero-based indexing.
- By the end of the lesson, you can trace an array update.
- By the end of the lesson, you can choose between an array and a collection for a simple task.
Why this idea exists
Arrays exist because many programs need compact, ordered storage for a fixed number of related values. They expose the important idea that position matters: each element has an index and the program must use that index correctly.
Historically, arrays are close to how memory is addressed in lower-level languages, which is why they remain a foundational data structure even when higher-level collections are more convenient.
This lesson fits the arc by connecting simple variables to structured data. Understanding arrays makes later work with collections, algorithms, searching, sorting and performance far easier to reason about.
Deep dive
Mechanism in this example
The important mechanism is visible around `int[] marks = {72, 65, 81};`. Read it as a concrete move in the program, not as decorative syntax: identify what value, object, branch, call or boundary is being created at that point.
Design pressure
This lesson fits the arc by connecting simple variables to structured data. Understanding arrays makes later work with collections, algorithms, searching, sorting and performance far easier to reason about.
Failure mode to watch
For The Array, deliberately disturb the assumption behind `int[] marks = {72, 65, 81};`: use an awkward value, missing input, wrong order of calls or boundary case. The useful question is how that disturbance exposes a weakness in the data structure foundations design.
Extension step
Extend the example by doing this: Change one value and trace the before/after state. The point is to make one small change that forces you to revisit the concept, rather than adding unrelated features.
Portfolio standard
The portfolio note should not repeat the lesson wording. It should show the edited code, the run result, and your own explanation of this evidence: explain when an arraylist would be easier to maintain.
Lesson visual

Type this and run it
Create ArraysDeepDiveDemo.java, type the program, and run it before changing anything. This section is about reproducing the checked baseline.
public class ArraysDeepDiveDemo {
public static void main(String[] args) {
int[] marks = {72, 65, 81};
System.out.println("Before: " + marks[1]);
marks[1] = 70;
System.out.println("After: " + marks[1]);
}
}Build and run it with:
javac ArraysDeepDiveDemo.java && java ArraysDeepDiveDemoExpected baseline: Before: 65
After: 70
Run the code in your browser
Use the editor as an experiment surface. First run the checked version, then make one small change to the part of the program that demonstrates data structure foundations and compare the new behaviour with the reference output.
Before: 65
After: 70Line-by-line explanation
Read the code as a sequence of responsibilities. The focus line for this lesson is int[] marks = {72, 65, 81};; the surrounding lines prepare it, use its result or make the behaviour observable.
public class ArraysDeepDiveDemo {This names the runnable class for the The Array example, giving the compiler and JVM one clear unit to build.
public static void main(String[] args) {This is the program entry point. In The Array, it keeps the demonstration of data structure foundations in one traceable starting script.
int[] marks = {72, 65, 81};This introduces marks as named state for The Array. Later lines can read, update, pass or print that specific value as evidence.
System.out.println("Before: " + marks[1]);This prints "Before: " + marks[1] as the observable evidence for The Array. The output lets the learner check whether the data structure foundations idea behaved as predicted.
marks[1] = 70;This updates one array element by index. The rest of the array remains the same, so trace the selected position carefully.
System.out.println("After: " + marks[1]);This prints "After: " + marks[1] as the observable evidence for The Array. The output lets the learner check whether the data structure foundations idea behaved as predicted.
}This closes the innermost The Array block, so the immediately preceding method, branch or loop has finished.
}This closes the outer The Array structure, returning the reader to the surrounding class or file.
Worked example
From code to explanation
Problem: Use The Array to complete a small portfolio-quality step: Draw the indexes for a five-element array.
Method: Locate the line `int[] marks = {72, 65, 81};`, explain the exact role it plays, then decide what you would change to extend the example without changing the whole program.
Reveal worked answer
The checked run should produce `Before: 65 After: 70`. A strong answer links the result back to data structure foundations: what was created, selected, stored, called or protected, and why that matters for the portfolio task.
Trace the program
Before: Before the key operation, identify the relevant value, object, branch or resource that the data structure foundations concept depends on.
During: Trace `int[] marks = {72, 65, 81};` as the The Array example executes. Say whether that operation creates data, checks a condition, calls behaviour, stores information or crosses a boundary.
After: Compare the run with the expected evidence: `Before: 65 After: 70`.
Change: Now change one value and trace the before/after state, run again, and explain the smallest reason the behaviour changed.
Common misconception
A common mistake in the array is treating the example as a finished answer. For data structure foundations, the important question is narrower: which operation carries the idea, what does it make possible, and what would break if you changed it carelessly?
Quick checks
1. In this The Array example, what is the best reason to focus on `int[] marks = {72, 65, 81};`?
2. Which evidence is strongest after you edit and rerun this example?
How to study this lesson
For The Array, predict how data structure foundations changes the run before you press Run.
Use the first portfolio task as your main edit: Draw the indexes for a five-element array.
Use the second task as your variation: Change one value and trace the before/after state.
Finish with evidence, not a diary entry: Explain when an ArrayList would be easier to maintain.
Portfolio Practice
- Draw the indexes for a five-element array.
- Change one value and trace the before/after state.
- Explain when an ArrayList would be easier to maintain.
Final self-check
Can you explain the key operation?
Explain the line identified in the quick check in one or two sentences. Your answer should say what it does before the output Before: 65
After: 70 appears.
Can you justify the portfolio evidence?
Your evidence should include the original run, one edited run, and a short note explaining how the edit affected data structure foundations.
Study route
Practise data structure foundations by predicting the Java example, typing it, running it in the browser, tracing the result and saving portfolio evidence.
Next, move into Objects, Encapsulation and Abstraction and carry forward one improvement from this lesson into the next program.
