bhylu.com

Advertisements

Java Study Plan and Project Review

Choose a study pace around results you can demonstrate. A fixed number of days is less useful than being able to explain, change and test a working program.

Your brief

Stage one: compile a program and trace values, decisions and loops without guessing. Stage two: split a booking calculation into methods and test invalid input. Stage three: model a session with valid state, then choose collections for unique references and ordered reports. Stage four: read a disposable file with a stated encoding and close resources on failure. Stage five: compare a loop with a stream and protect shared state in a small concurrent task. Stage six: finish the ledger and report projects, documenting their limits. At each stage keep a short note of a failed prediction and the rule that corrected it. The course map does not store your completion status.

Run it locally

Use a local JDK 21 or newer. Save the complete example as Main.java in a separate lab folder, then compile and run it with the commands below. Java examples do not run in Bhylu’s browser playground. The -ea option enables assertion checks used by some lessons.

JDK and terminal setup

javac --release 21 -encoding UTF-8 -d out Main.java
java -ea -cp out Main

Worked solution

Show the worked solution
Java 21+ · Main.java

public class Main {
    static int total(int[] requests) {
        int sum = 0;
        for (int seats : requests) {
            if (seats <= 0) throw new IllegalArgumentException("Positive seats required");
            sum = Math.addExact(sum, seats);
        }
        return sum;
    }

    public static void main(String[] args) {
        int[] requests = {2, 1, 3};
        int seats = total(requests);
        if (seats != 6) throw new AssertionError("Expected six seats");
        if (total(new int[]{}) != 0) throw new AssertionError("Empty total");
        System.out.println("Two contract checks passed");
    }
}

Expected output

Two contract checks passed

These two checks demonstrate a normal result and the empty-input identity. They are a starting point, not comprehensive coverage. Add an invalid value and an overflow case, then explain whether the exception belongs at this boundary. In a larger project move these contracts into an automated test framework and run them through the build tool so failures cannot be missed in manual console output.

Extend and test

Review a project with a partner or your own written checklist: inputs, invariants, failure behaviour, resource ownership, tests and limitations. Explain one trade-off before changing the design.

Check the official Java documentation for detailed contracts and supported options.

Advertisements