Lesson Overview
Revisit Java program structure and strengthen naming, packaging, cohesion and readable control flow.
Portfolio focus: Review one older program.
Starter: think before typing
Before running this building blocks 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 `Portfolio review has 3 evidence items.`; predict how the focus line helps produce that evidence.
Learning Objectives
- Explain the role of classes, methods, packages and entry points.
- Improve naming and layout for readability.
- Identify low-cohesion code.
- Prepare a Programming 1 artefact for extension.
Learning Outcomes
- By the end of the lesson, you can explain the role of classes, methods, packages and entry points.
- By the end of the lesson, you can improve naming and layout for readability.
- By the end of the lesson, you can identify low-cohesion code.
- By the end of the lesson, you can prepare a Programming 1 artefact for extension.
Why this idea exists
Program structure is the architecture of small code. Packages, classes, methods and entry points help programmers locate responsibility and limit the amount of code they must understand at once.
As languages evolved, structure became more explicit because unstructured code was hard to change safely. Java's class and package system encourages programmers to name boundaries rather than leave everything in one file.
At degree level, structure should support reading, testing and extension. If a future change would require editing unrelated parts of the program, the structure is probably giving weak guidance.
Deep dive
Mechanism in this example
The important mechanism is visible around `Report report = new Report("Portfolio review", 3);`. 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
At degree level, structure should support reading, testing and extension. If a future change would require editing unrelated parts of the program, the structure is probably giving weak guidance.
Failure mode to watch
For Program Structure Review, deliberately disturb the assumption behind `Report report = new Report("Portfolio review", 3);`: 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 building blocks design.
Extension step
Extend the example by doing this: Rename unclear variables. 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: move one responsibility into a better method or class.
Lesson visual

Type this and run it
Create ProgramStructureReviewDemo.java, type the program, and run it before changing anything. This section is about reproducing the checked baseline.
public class ProgramStructureReviewDemo {
public static void main(String[] args) {
Report report = new Report("Portfolio review", 3);
System.out.println(report.summary());
}
}
class Report {
private final String title;
private final int evidenceItems;
Report(String title, int evidenceItems) {
this.title = title;
this.evidenceItems = evidenceItems;
}
String summary() {
return title + " has " + evidenceItems + " evidence items.";
}
}Build and run it with:
javac ProgramStructureReviewDemo.java && java ProgramStructureReviewDemoExpected baseline: Portfolio review has 3 evidence items.
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 building blocks and compare the new behaviour with the reference output.
Portfolio review has 3 evidence items.Line-by-line explanation
Read the code as a sequence of responsibilities. The focus line for this lesson is Report report = new Report("Portfolio review", 3);; the surrounding lines prepare it, use its result or make the behaviour observable.
public class ProgramStructureReviewDemo {This names the runnable class for the Program Structure Review example, giving the compiler and JVM one clear unit to build.
public static void main(String[] args) {This is the program entry point. In Program Structure Review, it keeps the demonstration of building blocks in one traceable starting script.
Report report = new Report("Portfolio review", 3);This introduces report as named state for Program Structure Review. Later lines can read, update, pass or print that specific value as evidence.
System.out.println(report.summary());This prints report.summary() as the observable evidence for Program Structure Review. The output lets the learner check whether the building blocks idea behaved as predicted.
}This closes the innermost Program Structure Review block, so the immediately preceding method, branch or loop has finished.
}This closes the outer Program Structure Review structure, returning the reader to the surrounding class or file.
class Report {This starts a supporting class so Program Structure Review can separate the lesson idea into its own named responsibility.
private final String title;This declares title as object state for the Program Structure Review design without exposing it directly. Later constructors or methods should give it a controlled value.
private final int evidenceItems;This declares evidenceItems as object state for the Program Structure Review design without exposing it directly. Later constructors or methods should give it a controlled value.
Report(String title, int evidenceItems) {This constructor prepares a new object so the Program Structure Review example can use it in a valid state.
this.title = title;This assignment changes title in Program Structure Review to title. Trace where that new value is used next.
this.evidenceItems = evidenceItems;This assignment changes evidenceItems in Program Structure Review to evidenceItems. Trace where that new value is used next.
}This closing brace number 3 completes another layer of the Program Structure Review source structure Java has been checking.
String summary() {This starts summary, a named Program Structure Review operation. Its parameters describe what information comes in; its body decides what work is done.
return title + " has " + evidenceItems + " evidence items.";This sends a Program Structure Review result back to the caller, so the surrounding code can use the answer.
}This closing brace number 4 completes another layer of the Program Structure Review source structure Java has been checking.
Worked example
From code to explanation
Problem: Use Program Structure Review to complete a small portfolio-quality step: Review one older program.
Method: Locate the line `Report report = new Report("Portfolio review", 3);`, 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 `Portfolio review has 3 evidence items.`. A strong answer links the result back to building blocks: 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 building blocks concept depends on.
During: Trace `Report report = new Report("Portfolio review", 3);` as the Program Structure Review 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: `Portfolio review has 3 evidence items.`.
Change: Now rename unclear variables, run again, and explain the smallest reason the behaviour changed.
Common misconception
A common mistake in program structure review is treating the example as a finished answer. For building blocks, 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 Program Structure Review example, what is the best reason to focus on `Report report = new Report("Portfolio review", 3);`?
2. Which evidence is strongest after you edit and rerun this example?
How to study this lesson
For Program Structure Review, predict how building blocks changes the run before you press Run.
Use the first portfolio task as your main edit: Review one older program.
Use the second task as your variation: Rename unclear variables.
Finish with evidence, not a diary entry: Move one responsibility into a better method or class.
Portfolio Practice
- Review one older program.
- Rename unclear variables.
- Move one responsibility into a better method or class.
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 Portfolio review has 3 evidence items. 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 building blocks.
Study route
Practise building blocks by predicting the Java example, typing it, running it in the browser, tracing the result and saving portfolio evidence.
Next, move into Scope and Lifetime and carry forward one improvement from this lesson into the next program.
