How packtpublishing/learn-java-with-projects works
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: ReadFileExample.java Ch 11 · DateAPI.java Ch 12 · Pipeline.java Ch 15 · ExampleDeadLock.java Ch 17
Components 21
Foundations
Chapters 1-7: core language basics and small console projects.
- Ch 1 · Hello world and first exercises; introduces runnable examples.
ch1/HelloWorld.java - Ch 2 · Primitive types, variables, and a profile-generator project.
ch2/VariablesAndPrimitiveDataTypes.java - Ch 3 · Casting, operators, and meal-planner style practice.
ch3/Casting.java - Ch 4 · Conditionals, scope, and task-allocation exercise code.
ch4/ConditionLogic.java - Ch 5 · Looping and repeated-processing patterns.
ch5/Iteration.java - Ch 6 · Project-style tracking application for chapter concepts.
ch6/project/DinoTracker.java - Ch 7 · Methods and the Mesozoic Eden assistant project.
ch7/Methods.java
OOP
Chapters 8-10: encapsulation, records, inheritance, interfaces, and sealed types.
Exceptions & I/O
Chapters 11-13: exception handling, file I/O, core APIs, and generics.
Functional
Chapters 14-16: lambdas, streams, optionals, and parallel processing.
Concurrency
Chapter 17: threads, races, synchronization, and coordination.
- Ch 17 · Threading, races, deadlock, livelock, starvation, and synchronization.
ch17/ExampleDeadLock.java
Local Data
Small text files used by file and stream examples.
- ages.txt · Text input for file and scanner examples.
ch12/ages.txt - cats.txt · Text input for stream/file processing examples.
ch15/cats.txt - input.txt · Standalone file used by I/O exercises.
input.txt - output.txt · Standalone file used by write examples.
output.txt
Connections 21
- 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.