Unit 16 · lesson

Grow Into Packages and Multi-File Java Deliberately

Java 25 compact source files let beginners start with behavior before class/file ceremony. They are an on-ramp, not the final architecture for every program.

As a program grows, explicit files and packages provide names, boundaries, and organization.

Full JDK lane: authentic multi-file/package execution belongs in a normal Java 25 project environment. The browser core studies the structure and can keep equivalent types in one source when needed.

One class, one clear file identity

A conventional project might contain:

src/
  org/
    robotnix/
      scores/
        ScoreClassifier.java
        ScoreReport.java
        App.java

Files can declare:

package org.robotnix.scores;

The package provides a namespace and participates in access boundaries.

Do not create packages merely to produce deep folders. Group classes that belong to a coherent part of the application.

Explicit application entry point

A conventional entry class can use the classic form:

package org.robotnix.scores;

public class App {
    public static void main(String[] args) {
        System.out.println("starting score app");
    }
}

Now the earlier ceremony has context:

  • public because launcher/callers need access;
  • static because this classic entry method belongs to the class rather than an existing object;
  • String[] args for command-line arguments.

The course delayed those concepts until they had a reason to exist.

Imports connect namespaces

A class can import a type from another package:

import java.util.ArrayList;

or your own project type when package boundaries require it.

Imports do not copy code into your file. They let source refer to types without writing the fully qualified name every time.

Package-private can be useful

Java's default/package access lets closely related implementation classes collaborate without exposing every type publicly.

Do not make every class and method public by habit. Visibility is part of the design contract.

Project structure is not architecture by itself

A beautiful folder tree can still contain confused responsibilities.

Start with the component model:

input adapter
   |
domain/service
   |
output adapter

Then choose packages/files that make those responsibilities navigable.

Migration exercise

Take one compact/single-source program from earlier units.

Plan a multi-file version containing at least:

  • entry point;
  • domain type;
  • service/policy class;
  • interface or output adapter when justified;
  • test class in the full-JDK lane.

Write the proposed package/file tree and arrows showing dependencies.

If you have the full JDK environment, create and run it. If not, keep the structural plan and demonstrate equivalent behavior in one browser source.

Evidence

State explicitly which environment you executed.

A full-JDK artifact should show successful compile/test/run from the project structure.

A browser artifact should show the architecture diagram and equivalent behavior while marking multi-file/package execution as untested.

Again: accurate evidence is stronger than pretending the environment did something it did not.