Capstone — Building a Small Project
Sixteen chapters, two courses — this capstone builds one small, real inventory and ordering system that touches almost all of it: records and sealed types for the data model, a custom checked exception, a generic repository, interfaces, and a streams-based reporting pipeline.
Designing the Data Model
Product is a java2-7 record — immutable, with equality and formatting generated for free. OrderStatus is a java2-7 sealed interface with exactly three permitted shapes, each carrying its own relevant data — data-carrying variants, genuinely comparable to rust1-6's own enum design covered right back in the Rust track.
A Custom Checked Exception
Extending Exception rather than RuntimeException makes this a java1-7 checked exception — every caller is compiler-forced to either catch it or declare it, exactly right for a genuinely expected, recoverable business condition like running out of stock.
A Generic Repository
One Repository<T> class, reused for both Repository<Product> and Repository<Order> — java2-1's type erasure means this is genuinely one shared implementation underneath both, not two separately compiled copies.
Interfaces & Polymorphism in the Model
Product implements Priced — its record-generated price() accessor satisfies the interface automatically, and priceLabel() comes free from the interface's own default method, no override required.
Streams for Reporting
Both reports read as a description of the result, not a manual loop — the exact style java2-4 introduced, built directly on java2-2's Comparator and java2-3's method references.
Putting It Together — A Small Run
Chapter Attribution
| Capstone piece | Chapter |
|---|---|
| Product / OrderStatus records & sealed interface | java2-7 |
| InsufficientStockException (checked) | java1-7 |
| Repository<T> generics | java2-1 |
| Map/List storage | java1-8, java2-2 |
| Priced interface & default method | java1-6 |
| Streams reporting | java2-4 |
| Exhaustive switch over OrderStatus | java1-3, java2-7 |
What's Still Out of Scope
Honestly: no concurrency or thread-safety anywhere in this capstone, despite java2-5 covering it in full — a single-threaded demo has no genuine need for it. No persistence to a real file or database — Repository<T> is entirely in-memory. No automated tests. No build tooling. This capstone proves the pieces fit together, not that the result is production-ready.
java2-5's own race-condition material), input validation, and tests — treat this as proof the language features fit together, not as production-ready code to copy.
Coding Challenges
Add a fourth OrderStatus variant, Returned(String reason), update the permits clause, and update the exhaustive switch. Show what happens if you forget to add a case for it.
📄 View solutionWrite a stream pipeline over a List<Product> that groups products by whether their stock is above or below 10, using Collectors.partitioningBy(), and print both groups.
📄 View solutionWrite a short paragraph (as a comment) explaining specifically what would need to change in this capstone's Repository<T> class to make it safe for concurrent access from multiple threads, referencing java2-5's own material directly.
📄 View solutionChapter 8 Quick Reference — Java Track Complete
- Records + sealed interfaces model the domain with compiler-enforced closed sets (java2-7)
- A checked custom exception forces callers to handle a genuinely expected failure (java1-7)
- One generic Repository<T> serves every entity type, thanks to type erasure (java2-1)
- Interfaces and default methods keep behavior decoupled from any one class (java1-6)
- Streams describe reports declaratively rather than via manual loops (java2-2, java2-3, java2-4)
- Concurrency, persistence, and testing are honestly named as still out of scope
- Both Java courses are now complete — 16 chapters total, framed against Kotlin, C++, and Rust throughout.