Modern Java: From 8 to 25 and Beyond
Comprehensive examples and demonstrations of Java features from Java 8 through Java 25, showcasing the evolution of the Java language and platform.
๐ What's Included
- Practical Code Examples - Real-world demonstrations of modern Java features
- Comprehensive Test Suite - 160+ tests covering all major functionality
- Workshop Presentation - Complete slide deck covering Java evolution (
slides.md) - Java Tier List Presentation - Feature ranking and discussion format (
slides-java-tier-list.md) - Workshop Exercises - Hands-on labs with complete solutions (
workshop-exercises.md) - Data-Oriented Programming - Examples of records, sealed classes, and pattern matching working together
๐ฏ Key Features Covered
Java 8 - The Functional Revolution
- Lambda expressions and method references
- Stream API with advanced collectors
- Optional for null safety
- Default and static methods in interfaces
- CompletableFuture for async programming
Java 9-11 - Platform Maturity
- JShell (Java REPL)
- Collection factory methods (
List.of(),Map.of()) - Local variable type inference (
var) - HTTP Client API
- String enhancements (
isBlank(),strip(),repeat())
Java 12-17 - Language Evolution
- Text blocks for multi-line strings
- Records for immutable data classes
- Pattern matching for
instanceof - Switch expressions with
yield - Sealed classes for controlled inheritance
Java 18-21 - Modern Features
- Simple web server (
jwebserver) - Virtual threads for scalable concurrency
- Sequenced collections
- Pattern matching in switch
- Enhanced pattern matching with guards
Java 22-25 - Latest LTS
- Unnamed variables with
_(Java 22) - Stream Gatherers (Java 24)
- Scoped Values (finalized in Java 25 LTS)
- Module Import Declarations (Java 25)
- Flexible Constructor Bodies (Java 25)
- Primitive types in patterns (3rd preview in Java 25)
- Structured Concurrency (5th preview in Java 25)
๐ ๏ธ Build Requirements
- Java 25 LTS - Latest Long-Term Support release with preview features enabled
- Gradle 9.1.0+ - Modern build tooling with Java 25 support
- JUnit 5.13.3 - Modern testing framework
- SonarCloud - Code quality analysis configured for educational code standards
๐โโ๏ธ Quick Start
# Clone the repository git clone https://github.com/kousen/java_latest.git cd java_latest # Run all tests ./gradlew test # Run a specific example ./gradlew run # Generate code coverage report ./gradlew jacocoTestReport
๐ Running the Presentation
The repository includes a comprehensive Slidev presentation:
# Install dependencies for PDF export npm install # Start the presentation npx slidev slides.md # Export to PDF npx slidev export slides.md --format pdf
๐ Learning Path
For Self-Study
- Start with Java 8 -
ProcessDictionaryV2.javashowcases functional programming - Explore Records - See
Person.java,Customer.javafor data classes - Pattern Matching - Check
UseShapes.javafor modern control flow - Virtual Threads -
VirtualThreadsDemo.javafor scalable concurrency - Data-Oriented Programming - Combine records, sealed classes, and pattern matching
For Workshops
- Review the slides -
slides.mdprovides comprehensive coverage - Work through exercises -
workshop-exercises.mdcontains hands-on labs - Check solutions - Complete implementations in
exercises.solutionspackage - Practice with examples - Explore the main codebase for real-world patterns
๐ Key Examples
ProcessDictionaryV2- Comprehensive Stream API showcaseastropackage - HTTP Client with Result pattern (sealed interfaces)shapespackage - Sealed classes with pattern matchingVirtualThreadsDemo- Modern concurrency patterns
๐งช Testing
# Run all tests ./gradlew test # Run tests for a specific package ./gradlew test --tests "*interfaces*" # Run workshop solution tests ./gradlew test --tests "exercises.solutions.*" # Run with coverage ./gradlew test jacocoTestReport
๐ Code Coverage
JaCoCo reports are generated in build/reports/jacoco/test/html/index.html
๐ Additional Resources
- Modern Java Recipes by Kenneth Kousen
- Java Enhancement Proposals (JEPs)
- Java Almanac
๐จโ๐ป Author
Kenneth Kousen
- Website: kousenit.com
- Newsletter: Tales from the jar side
- Social: @kenkousen
This repository is actively maintained and updated with the latest Java features as they become available.