# packtpublishing/learn-java-with-projects architecture

> Architecture diagram of the GitHub repository packtpublishing/learn-java-with-projects, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/packtpublishing/learn-java-with-projects
- Repository: https://github.com/packtpublishing/learn-java-with-projects

## Overview

1. **Overall shape**
   This repository is not a single application; it is a chapter-by-chapter code companion for a Java book. Each `.java` file is a small, runnable example, and most folders correspond directly to a chapter topic or an exercise/project from that chapter.

2. **Primary architectural boundary: chapter isolation**
   The main organizing unit is the chapter directory (`ch1` through `ch17`). Chapters are intentionally decoupled from one another: code in one chapter generally does not form a shared library consumed by another. That means the architecture is closer to a learning lab than a production system, with many independent entry points rather than one central service.

3. **Foundations layer: chapters 1–7**
   The early chapters focus on language basics: Hello World, variables, casting, operators, conditionals, loops, methods, and simple project-style exercises. The “project” subfolders in these chapters contain small mini-applications such as `ProfileGenerator`, `DinoMealPlanner`, `TaskAllocationSystem`, `DinoTracker`, and `MesozoicEdenAssistant`. These are still self-contained command-line programs, but they introduce the idea of combining multiple classes and input/output flows.

4. **Object-oriented modeling layer: chapters 8–10**
   Chapters 8–10 move into encapsulation, enums, records, inheritance, polymorphism, and interfaces. You can see this in supporting model classes such as `Person`, `Dog`, `Pig`, `Book`, `FictionBook`, `Vehicle`, `Employee`, `Ticket`, and `Dinosaur`. Chapter 10 specifically explores interface features like default, private, static, and sealed interfaces, showing how type hierarchies are structured and constrained.

5. **Exceptions and resource handling: chapter 11**
   Chapter 11 centers on exception handling and file cleanup. Files like `InvalidAgeException`, `ReadFileExample`, `WriteFileExample`, and `FileResourceCleanup` indicate the boundary between normal program flow and failure handling. This chapter is where the repository starts interacting with the filesystem in a more explicit way.

6. **Core library usage: chapter 12**
   Chapter 12 covers common Java APIs such as dates, collections, scanners, strings, and immutability. It also includes a small data file, `ages.txt`, which is used as input for file-reading examples. Architecturally, this chapter is about moving from syntax into standard-library-driven data processing.

7. **Generics and type-safe abstractions: chapter 13**
   Chapter 13 appears to focus on generics and reusable domain models, again using `Dinosaur`, `DinosaurFood`, and `Vehicle` examples. The exercises here suggest an emphasis on parameterized types and compile-time safety rather than new runtime components.

8. **Functional programming layer: chapters 14–16**
   Chapters 14–16 introduce lambdas, method references, streams, optional values, primitive streams, and parallel streams. These chapters shift the architecture from imperative step-by-step code to pipeline-based processing. The main boundary here is between source data and stream pipelines that transform, filter, map, and collect results. Files such as `cats.txt` and the stream-processing classes support that dataflow.

9. **Concurrency layer: chapter 17**
   Chapter 17 is the concurrency section, with examples of threads, runnable tasks, atomicity, deadlock, livelock, starvation, and race conditions. The `dataraceandlock`, `dataraceandsynchronized`, `examplethreadclass`, and `examplerunnableinterface` subfolders show different concurrency models and synchronization strategies. The main architectural concern here is shared mutable state and how access to it is coordinated.

10. **Data and runtime model**
   The repo uses a few standalone text files (`input.txt`, `output.txt`, `ages.txt`, `cats.txt`) as local data sources for I/O and stream exercises. There is no database, web server, message broker, or external API integration. Everything runs locally on Java 21+, typically as console applications with chapter-specific `main` methods.

11. **Exercises as parallel tracks**
   Nearly every chapter has an `exercises` folder. These are not separate subsystems so much as alternate implementations or practice variations of the chapter’s concepts. They reinforce the same architectural boundaries as the main examples: small, isolated, command-line programs.

12. **Repository-level tooling and conventions**
   The repository is intentionally lightweight: no build framework or application container is central to the architecture. The presence of `.gitkeep`, `.empty`, and an IntelliJ `.iml` file suggests the repo is organized primarily for IDE-based exploration and direct compilation/run of individual source files.

Main entry points: [`ch11/ReadFileExample.java`](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch11/ReadFileExample.java) (Ch 11), [`ch12/DateAPI.java`](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch12/DateAPI.java) (Ch 12), [`ch15/Pipeline.java`](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch15/Pipeline.java) (Ch 15), [`ch17/ExampleDeadLock.java`](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch17/ExampleDeadLock.java) (Ch 17)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_foundations["Foundations"]
  node_ch1["Ch 1<br/>chapter basics<br/>[HelloWorld.java]"]
  node_ch2["Ch 2<br/>variables"]
  node_ch3["Ch 3<br/>expressions<br/>[Casting.java]"]
  node_ch4["Ch 4<br/>control flow"]
  node_ch5["Ch 5<br/>iteration<br/>[Iteration.java]"]
  node_ch6["Ch 6<br/>practice project<br/>[DinoTracker.java]"]
  node_ch7["Ch 7<br/>methods<br/>[Methods.java]"]
end

subgraph group_oop["OOP"]
  node_ch8["Ch 8<br/>encapsulation"]
  node_ch9["Ch 9<br/>inheritance"]
  node_ch10["Ch 10<br/>interfaces"]
end

subgraph group_exceptions["Exceptions & I/O"]
  node_ch11["Ch 11<br/>exceptions"]
  node_ch12["Ch 12<br/>stdlib APIs<br/>[DateAPI.java]"]
  node_ch13["Ch 13<br/>generics<br/>[Dinosaur.java]"]
end

subgraph group_functional["Functional"]
  node_ch14["Ch 14<br/>lambdas<br/>[BasicLambdas.java]"]
  node_ch15["Ch 15<br/>streams<br/>[Pipeline.java]"]
  node_ch16["Ch 16<br/>advanced streams<br/>[Optionals.java]"]
end

subgraph group_concurrency["Concurrency"]
  node_ch17["Ch 17<br/>concurrency"]
end

subgraph group_data["Local Data"]
  node_ages["ages.txt<br/>input data<br/>[ages.txt]"]
  node_cats["cats.txt<br/>input data<br/>[cats.txt]"]
  node_input["input.txt<br/>local input<br/>[input.txt]"]
  node_output["output.txt<br/>local output<br/>[output.txt]"]
end

node_ch1 -->|"next"| node_ch2
node_ch2 -->|"next"| node_ch3
node_ch3 -->|"next"| node_ch4
node_ch4 -->|"next"| node_ch5
node_ch5 -->|"next"| node_ch6
node_ch6 -->|"next"| node_ch7
node_ch7 -->|"next"| node_ch8
node_ch8 -->|"next"| node_ch9
node_ch9 -->|"next"| node_ch10
node_ch10 -->|"next"| node_ch11
node_ch11 -->|"next"| node_ch12
node_ch12 -->|"next"| node_ch13
node_ch13 -->|"next"| node_ch14
node_ch14 -->|"next"| node_ch15
node_ch15 -->|"next"| node_ch16
node_ch16 -->|"next"| node_ch17
node_ages -.->|"used by"| node_ch12
node_cats -.->|"used by"| node_ch15
node_input -.->|"used by"| node_ch11
node_output -.->|"written by"| node_ch11
node_ch17 -.->|"variants"| node_ch17

click node_ch1 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch1/HelloWorld.java"
click node_ch2 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch2/VariablesAndPrimitiveDataTypes.java"
click node_ch3 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch3/Casting.java"
click node_ch4 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch4/ConditionLogic.java"
click node_ch5 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch5/Iteration.java"
click node_ch6 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch6/project/DinoTracker.java"
click node_ch7 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch7/Methods.java"
click node_ch8 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch8/BasicEncapsulation.java"
click node_ch9 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch9/OverridingTest.java"
click node_ch10 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch10/InterfaceInheritance.java"
click node_ch11 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch11/ReadFileExample.java"
click node_ch12 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch12/DateAPI.java"
click node_ch13 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch13/exercises/Dinosaur.java"
click node_ch14 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch14/BasicLambdas.java"
click node_ch15 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch15/Pipeline.java"
click node_ch16 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch16/Optionals.java"
click node_ch17 "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch17/ExampleDeadLock.java"
click node_ages "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch12/ages.txt"
click node_cats "https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch15/cats.txt"
click node_input "https://github.com/packtpublishing/learn-java-with-projects/blob/main/input.txt"
click node_output "https://github.com/packtpublishing/learn-java-with-projects/blob/main/output.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ch1,node_ch2,node_ch3,node_ch4,node_ch5,node_ch6,node_ch7 toneBlue
class node_ch8,node_ch9,node_ch10 toneAmber
class node_ch11,node_ch12,node_ch13 toneMint
class node_ch14,node_ch15,node_ch16 toneRose
class node_ch17 toneIndigo
class node_ages,node_cats,node_input,node_output toneTeal
```

## Components

### Foundations

Chapters 1-7: core language basics and small console projects.

- [Ch 1](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch1/HelloWorld.java): chapter basics · Hello world and first exercises; introduces runnable examples. · `ch1/HelloWorld.java`
- [Ch 2](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch2/VariablesAndPrimitiveDataTypes.java): variables · Primitive types, variables, and a profile-generator project. · `ch2/VariablesAndPrimitiveDataTypes.java`
- [Ch 3](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch3/Casting.java): expressions · Casting, operators, and meal-planner style practice. · `ch3/Casting.java`
- [Ch 4](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch4/ConditionLogic.java): control flow · Conditionals, scope, and task-allocation exercise code. · `ch4/ConditionLogic.java`
- [Ch 5](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch5/Iteration.java): iteration · Looping and repeated-processing patterns. · `ch5/Iteration.java`
- [Ch 6](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch6/project/DinoTracker.java): practice project · Project-style tracking application for chapter concepts. · `ch6/project/DinoTracker.java`
- [Ch 7](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch7/Methods.java): methods · Methods and the Mesozoic Eden assistant project. · `ch7/Methods.java`

### OOP

Chapters 8-10: encapsulation, records, inheritance, interfaces, and sealed types.

- [Ch 8](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch8/BasicEncapsulation.java): encapsulation · Classes, enums, records, and object state modeling. · `ch8/BasicEncapsulation.java`
- [Ch 9](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch9/OverridingTest.java): inheritance · Final, overriding, polymorphism, and package-bound examples. · `ch9/OverridingTest.java`
- [Ch 10](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch10/InterfaceInheritance.java): interfaces · Default, private, static, and sealed interface patterns. · `ch10/InterfaceInheritance.java`

### Exceptions & I/O

Chapters 11-13: exception handling, file I/O, core APIs, and generics.

- [Ch 11](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch11/ReadFileExample.java): exceptions · Custom exceptions, file reading, writing, and cleanup. · `ch11/ReadFileExample.java`
- [Ch 12](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch12/DateAPI.java): stdlib APIs · Dates, lists, strings, scanners, and immutable values. · `ch12/DateAPI.java`
- [Ch 13](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch13/exercises/Dinosaur.java): generics · Parameterized models and type-safe abstractions. · `ch13/exercises/Dinosaur.java`

### Functional

Chapters 14-16: lambdas, streams, optionals, and parallel processing.

- [Ch 14](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch14/BasicLambdas.java): lambdas · Functional interfaces, method references, and lambda usage. · `ch14/BasicLambdas.java`
- [Ch 15](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch15/Pipeline.java): streams · Stream creation, pipelines, collectors, and file-backed processing. · `ch15/Pipeline.java`
- [Ch 16](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch16/Optionals.java): advanced streams · Intermediate operations, optionals, primitive and parallel streams. · `ch16/Optionals.java`

### Concurrency

Chapter 17: threads, races, synchronization, and coordination.

- [Ch 17](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch17/ExampleDeadLock.java): concurrency · Threading, races, deadlock, livelock, starvation, and synchronization. · `ch17/ExampleDeadLock.java`

### Local Data

Small text files used by file and stream examples.

- [ages.txt](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch12/ages.txt): input data · Text input for file and scanner examples. · `ch12/ages.txt`
- [cats.txt](https://github.com/packtpublishing/learn-java-with-projects/blob/main/ch15/cats.txt): input data · Text input for stream/file processing examples. · `ch15/cats.txt`
- [input.txt](https://github.com/packtpublishing/learn-java-with-projects/blob/main/input.txt): local input · Standalone file used by I/O exercises. · `input.txt`
- [output.txt](https://github.com/packtpublishing/learn-java-with-projects/blob/main/output.txt): local output · Standalone file used by write examples. · `output.txt`

## Connections

- Ch 1 → Ch 2: next · Chapter progression from basics to variables.
- Ch 2 → Ch 3: next · Builds on primitives with casting and operators.
- Ch 3 → Ch 4: next · Moves into branching and scope.
- Ch 4 → Ch 5: next · Extends control flow into iteration.
- Ch 5 → Ch 6: next · Applies loops to a small project.
- Ch 6 → Ch 7: next · Adds reusable methods and a larger assistant project.
- Ch 7 → Ch 8: next · Transitions from procedural code to objects.
- Ch 8 → Ch 9: next · Advances into inheritance and polymorphism.
- Ch 9 → Ch 10: next · Continues with interface-based type design.
- Ch 10 → Ch 11: next · Moves from type systems into failures and cleanup.
- Ch 11 → Ch 12: next · Expands into standard library data handling.
- Ch 12 → Ch 13: next · Introduces generics and reusable abstractions.
- Ch 13 → Ch 14: next · Shifts from type parameters to functional style.
- Ch 14 → Ch 15: next · Uses lambdas as stream pipeline building blocks.
- Ch 15 → Ch 16: next · Adds optional values and more advanced stream forms.
- Ch 16 → Ch 17: next · Ends with shared-state and thread coordination issues.
- ages.txt → Ch 12: used by · Input file for file and scanner examples.
- cats.txt → Ch 15: used by · Data source for stream-processing examples.
- input.txt → Ch 11: used by · Standalone I/O input for read examples.
- output.txt → Ch 11: written by · Standalone output target for write examples.
- Ch 17 → Ch 17: variants · Subpackages show alternate concurrency strategies.
