"In learning you will teach, and in teaching you will learn." β Phil Collins
This is an advanced academic project designed to help Java developers deeply practice and master key features introduced and enhanced in Java 21, including:
- β Streams
- β Lambdas
- β Method References
- β Records
Unlike the many beginner-level examples that can be found online, this repository is built with seasoned professionals in mind.
The exercises were originally created for a corporate training program delivered to a top-tier international tech company, where the participants were highly experienced software engineers preparing for the official Oracle Java 21 certification.
Each of the 15 exercises includes:
- A progressively increasing level of complexity.
- A real-world inspired domain (Spotify-style music streaming logic).
- Clean, idiomatic use of modern Java 21 features β using only the standard JDK, no external libraries.
- Detailed JUnit 5 test cases with clear documentation of the desired functionality.
This repository is made public to support other professionals who:
- Are preparing for the Java 21 certification.
- Want to sharpen their skills with realistic, professionally relevant exercises.
- Are looking for examples that go beyond the basics, using functional programming patterns in Java at a senior engineering level.
- Senior backend developers
- Java educators and trainers
- Certification candidates
- Teams preparing for interviews or internal upskilling in modern Java
The project contains 15 increasingly complex exercises in the MusicAnalyticsService class:
- Average Genre Popularity: Calculate average popularity ratings for each music genre
- Popular Songs by Genre: Find the most popular song in each music genre
- Playlist Duration: Calculate the total playing time of all songs in a user's playlists
- User Genre Overlaps: Find users who share musical taste based on genre preferences
- Top Songs Ranking: Generate a ranked list of the most played songs across the platform
- Complex Album Filtering: Find albums matching multiple complex criteria for content curation
- Album Summary Generation: Generate rich album summaries for the platform's user interface
- User Statistics: Generate detailed user profile statistics for personalization
- Premium vs. Free Analysis: Generate listening statistics comparing premium and free user behavior
- Personalized Recommendations: Generate personalized song recommendations based on user preferences
- Catalog Analysis: Analyze music catalog distribution by decade and genre
- Artist Collaborations: Discover artist collaboration networks within the music catalog
- Genre Affinity Scoring: Calculate users' affinity scores for different music genres
- Dynamic Playlist Generation: Generate smart playlists tailored to specific activities and moods
- Track Transitions: Analyze track transition patterns to improve shuffle and radio algorithms
-
Prerequisites
- Java 21 JDK installed on your machine
- Maven installed
-
Clone the repository
git clone https://github.com/yourusername/java21-streams-lambdas.git cd java21-streams-lambdas -
Build with Maven
mvn clean install
-
Run the tests
mvn test -
Study the code
- Start by examining the model classes in
com.streamexercises.model - Review each exercise in
MusicAnalyticsService.java - Understand the test cases in
MusicAnalyticsServiceTest.java
- Start by examining the model classes in
src/
βββ main/java/com/streamexercises/
β βββ model/
β β βββ Album.java # Music album representation
β β βββ Genre.java # Music genre enum
β β βββ Playlist.java # User playlist implementation
β β βββ Song.java # Song with metadata
β β βββ User.java # User profile with preferences
β βββ service/
β βββ MusicAnalyticsService.java # Contains all 15 exercises
βββ test/java/com/streamexercises/
βββ service/
βββ MusicAnalyticsServiceTest.java # Comprehensive tests
- Java 21 (standard JDK only)
- JUnit 5
- Maven
- Start with the simplest exercises (1-5)
- Move to intermediate complexity (6-10)
- Challenge yourself with advanced exercises (11-15)
- Try implementing variations of each solution
MIT License
This project was designed as part of a high-level corporate training initiative for senior software engineers preparing for Java 21 certification.
"The function of good software is to make the complex appear to be simple." β Grady Booch