Skip to content

“Your Java 25 sandbox.” A small Maven project to run and tweak real examples: primitive patterns, flexible constructors, sealed classes, ScopedValue, structured concurrency, virtual threads, records, and switch expressions. Clone, run mvn exec:java, pick a class, and play.

License

Notifications You must be signed in to change notification settings

gauravdasgupta/explore-java-25

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java 25 Practice Playground

A Maven project for practicing Java 25 and modern Java concepts. Requires JDK 25.

How to run and play locally

  1. 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
  2. Compile once (after any code change, run again if you want to check for errors):

    mvn compile
  3. Run the menu to see all runnable examples:

    mvn exec:java
  4. Run a specific example by class name. For instance, the sealed shapes example:

    mvn exec:java -Dexec.mainClass="com.learningjava.sealed.SealedExample"
  5. Play with the code: open any .java file under src/main/java/com/learningjava/, change it (e.g. add a new Shape, change numbers, add printlns), then run mvn compile and the same mvn 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.

Quick start (copy-paste)

# 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"

Concept index

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

Run any example

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"

Requirements

Preview features are enabled in the POM (--enable-preview) so primitive patterns, structured concurrency, and other preview APIs work.

Extending the playground

  • 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 instance void main().
  • Use this repo to try new JEPs, refactor examples, or add exercises.

About

“Your Java 25 sandbox.” A small Maven project to run and tweak real examples: primitive patterns, flexible constructors, sealed classes, ScopedValue, structured concurrency, virtual threads, records, and switch expressions. Clone, run mvn exec:java, pick a class, and play.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages