A Maven project for practicing Java 25 and modern Java concepts. Requires JDK 25.
-
Open the project in your IDE (e.g. Cursor/VS Code) or a terminal at the project root:
cd /Users/gad/Documents/gd_playground/Learning_Java -
Compile once (after any code change, run again if you want to check for errors):
mvn compile
-
Run the menu to see all runnable examples:
mvn exec:java
-
Run a specific example by class name. For instance, the sealed shapes example:
mvn exec:java -Dexec.mainClass="com.learningjava.sealed.SealedExample" -
Play with the code: open any
.javafile undersrc/main/java/com/learningjava/, change it (e.g. add a newShape, change numbers, addprintlns), then runmvn compileand the samemvn exec:java -Dexec.mainClass="..."again to see the effect.
From your IDE: use “Run” / “Debug” on a class that has main (e.g. SealedExample.java). The project uses --enable-preview; if your IDE runs Java, ensure it uses JDK 25 and preview flags for that run configuration.
# Compile
mvn compile
# Run default entry (lists all examples)
mvn exec:java
# Run a specific example
mvn exec:java -Dexec.mainClass="com.learningjava.patterns.PrimitiveTypesInPatterns"| Package | Class | Concept |
|---|---|---|
com.learningjava.patterns |
PrimitiveTypesInPatterns |
JEP 507 – Primitive types in instanceof and switch patterns |
com.learningjava.constructors |
FlexibleConstructorBodies |
JEP 513 – Statements before super() / this() (e.g. validation) |
com.learningjava.scopedvalues |
ScopedValueExample |
JEP 506 – ScopedValue (immutable, thread-safe context; works with virtual threads) |
com.learningjava.structuredconcurrency |
StructuredConcurrencyExample |
JEP 505 – StructuredTaskScope (run/cancel related tasks as a unit) |
com.learningjava.crypto |
KeyDerivationExample |
JEP 510 – Key Derivation (PBKDF2, etc.) |
com.learningjava.compact |
InstanceMainExample |
JEP 512 – Instance main methods / compact source files |
com.learningjava.records |
RecordExample |
Records, compact constructors |
com.learningjava.sealed |
SealedExample |
Sealed classes + exhaustive switch |
com.learningjava.virtualthreads |
VirtualThreadsExample |
Virtual threads (Java 21) |
com.learningjava.switchlang |
SwitchExpressionsExample |
Switch expressions and pattern matching |
mvn exec:java -Dexec.mainClass="com.learningjava.<package>.<ClassName>"Examples:
mvn exec:java -Dexec.mainClass="com.learningjava.patterns.PrimitiveTypesInPatterns"
mvn exec:java -Dexec.mainClass="com.learningjava.constructors.FlexibleConstructorBodies"
mvn exec:java -Dexec.mainClass="com.learningjava.scopedvalues.ScopedValueExample"
mvn exec:java -Dexec.mainClass="com.learningjava.structuredconcurrency.StructuredConcurrencyExample"
mvn exec:java -Dexec.mainClass="com.learningjava.crypto.KeyDerivationExample"
mvn exec:java -Dexec.mainClass="com.learningjava.records.RecordExample"
mvn exec:java -Dexec.mainClass="com.learningjava.sealed.SealedExample"
mvn exec:java -Dexec.mainClass="com.learningjava.virtualthreads.VirtualThreadsExample"
mvn exec:java -Dexec.mainClass="com.learningjava.switchlang.SwitchExpressionsExample"
mvn exec:java -Dexec.mainClass="com.learningjava.compact.InstanceMainExample"- JDK 25 (e.g. from Adoptium or jdk.java.net/25)
- Maven 3.9+
Preview features are enabled in the POM (--enable-preview) so primitive patterns, structured concurrency, and other preview APIs work.
- Add new classes under
src/main/java/com/learningjava/in a package that matches the concept (or create a new package). - Each runnable example can have a
public static void main(String[] args)or (where supported) an instancevoid main(). - Use this repo to try new JEPs, refactor examples, or add exercises.