Add java25-features module: the 18 JEPs of JDK 25 with runnable demos, captured output and compile-error cases

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b5uFE41EgmSXEP4axJ
This commit is contained in:
asmhatre
2026-11-25 13:20:40 +05:30
co-authored by Claude Sonnet 5.5
parent 876ae1bb5c
commit 1fb1455734
36 changed files with 459 additions and 1 deletions
@@ -0,0 +1,7 @@
$ javac src/ScopedValuesDemo.java && java ScopedValuesDemo (25.0.5.1)
before by nobody
delete account by alice
nested rebind by admin
after nested by alice
after by nobody
call returned for bob
@@ -0,0 +1,3 @@
$ javac src/ModuleImportDemo.java && java ModuleImportDemo (25.0.5.1)
{4=[beta], 5=[alpha, gamma, delta]}
/tmp/x.txt 2025-09-16
@@ -0,0 +1,3 @@
$ java src/Hello.java (25.0.5.1)
Hello, Java 25
class name the launcher gave me: Hello
@@ -0,0 +1,4 @@
$ javac src/FlexibleConstructorDemo.java && java FlexibleConstructorDemo (25.0.5.1)
square side=4
old square side=0
rejected: side must be positive, got -1
+4
View File
@@ -0,0 +1,4 @@
$ javac src/KdfDemo.java && java KdfDemo (25.0.5.1)
OKM 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865
RFC 5869 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865
match true
@@ -0,0 +1,6 @@
$ javac --release 25 --enable-preview src/PrimitivePatternsPreview.java && java --enable-preview PrimitivePatternsPreview (25.0.5.1)
ok | server error 503 | client error 404 | other 302
42 fits in int as 42
5000000000 does not fit in int
3.0 instanceof int? true, 3.5 instanceof int? false
16777216 instanceof float? true, 16777217 instanceof float? false
@@ -0,0 +1,9 @@
$ javac --release 25 --enable-preview src/StableValuesPreview.java && java --enable-preview StableValuesPreview (25.0.5.1)
calls before first use: 0
config loaded (call #1)
config loaded (call #1)
calls after two gets: 1
sq(3)=9
sq(3)=9
calls after list use: 2 (one element computed, four not)
trySet first: true, trySet second: false, value: a
@@ -0,0 +1,4 @@
$ javac --release 25 --enable-preview src/StructuredConcurrencyPreview.java && java --enable-preview StructuredConcurrencyPreview (25.0.5.1)
user after 50ms | orders after 80ms
winner: fast mirror after 30ms
join threw FailedException caused by java.lang.IllegalStateException: boom
+7
View File
@@ -0,0 +1,7 @@
$ javac --release 25 --enable-preview src/PemPreview.java && java --enable-preview PemPreview (25.0.5.1)
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAKBmGVhQYHIYYS9a5T+AJ8IcxKzPBdjXHOrHxoNCp0EQ=
-----END PUBLIC KEY-----
round trip equal: true
private key header: -----BEGIN PRIVATE KEY-----
+6
View File
@@ -0,0 +1,6 @@
$ javac --add-modules jdk.incubator.vector src/VectorDemo.java && java --add-modules jdk.incubator.vector VectorDemo (25.0.5.1)
warning: [incubating] using incubating module(s): jdk.incubator.vector
1 warning
WARNING: Using incubator modules: jdk.incubator.vector
dot=6008.0 scalar=6008.0
species lanes (machine dependent): 16
@@ -0,0 +1,7 @@
$ javac src/HeaderSize.java && java HeaderSize (25.0.5.1)
bytes per object (two ints): 24
UseCompactObjectHeaders: (not set)
$ javac src/HeaderSize.java && java -XX:+UseCompactObjectHeaders HeaderSize (25.0.5.1)
bytes per object (two ints): 16
UseCompactObjectHeaders: -XX:+UseCompactObjectHeaders
+6
View File
@@ -0,0 +1,6 @@
$ java -XX:+UseShenandoahGC -Xlog:gc+init GcNamesDemo | grep Mode (25.0.5.1)
[info][gc,init] Mode: Snapshot-At-The-Beginning (SATB)
$ java -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xlog:gc+init GcNamesDemo | grep Mode (25.0.5.1)
[info][gc,init] Mode: Generational
+15
View File
@@ -0,0 +1,15 @@
$ java -XX:AOTCacheOutput=app.aot -cp app.jar AotApp (25.0.5.1)
1334 items, first 1 | 666 items, first 3 bb
Temporary AOTConfiguration recorded: app.aot.config
Launching child process java to assemble AOT cache app.aot using configuration app.aot.config
Picked up JAVA_TOOL_OPTIONS: -Djava.class.path=app.jar -XX:AOTCacheOutput=app.aot -XX:AOTConfiguration=app.aot.config -XX:AOTMode=create
Reading AOTConfiguration app.aot.config and writing AOTCache app.aot
AOTCache creation is complete: app.aot N bytes
Removed temporary AOT configuration file app.aot.config
startup, 5 runs each, wall milliseconds (indicative, machine dependent):
run 1: plain 88 ms with -XX:AOTCache 59 ms
run 2: plain 85 ms with -XX:AOTCache 70 ms
run 3: plain 107 ms with -XX:AOTCache 56 ms
run 4: plain 113 ms with -XX:AOTCache 76 ms
run 5: plain 108 ms with -XX:AOTCache 65 ms
+10
View File
@@ -0,0 +1,10 @@
$ java -XX:StartFlightRecording:filename=cpu.jfr,jdk.CPUTimeSample#enabled=true,jdk.CPUTimeSample#throttle=10ms CpuWork (25.0.5.1)
top frame of each jdk.CPUTimeSample event (counts vary run to run):
147 CpuWork.hot(int)
1 java.lang.Integer.numberOfTrailingZeros(int)
1 CpuWork.main(String[])
$ java -XX:StartFlightRecording:filename=mt.jfr,method-timing=CpuWork::hot,method-trace=CpuWork::cold CpuWork
method = CpuWork.hot(int)
invocations = 343
jdk.MethodTrace events for CpuWork.cold: 343
@@ -0,0 +1,27 @@
$ javac --release 25 broken/PreviewWithoutFlag.java (25.0.5.1)
broken/PreviewWithoutFlag.java:5: error: primitive patterns are a preview feature and are disabled by default.
if (v instanceof int i) System.out.println(i);
^
(use --enable-preview to enable primitive patterns)
1 error
$ javac broken/ThisBeforeSuper.java (25.0.5.1)
broken/ThisBeforeSuper.java:8: error: cannot reference describe() before supertype constructor has been called
System.out.println(describe()); // instance method call before super(): rejected
^
1 error
$ javac broken/AmbiguousModuleImport.java (25.0.5.1)
broken/AmbiguousModuleImport.java:6: error: reference to Date is ambiguous
Date d = null; // which Date?
^
both class java.sql.Date in java.sql and class java.util.Date in java.util match
1 error
$ javac --release 25 --enable-preview broken/ShutdownOnFailure21Style.java (25.0.5.1)
broken/ShutdownOnFailure21Style.java:4: error: cannot find symbol
try (var s = new StructuredTaskScope.ShutdownOnFailure()) { var f = s.fork(() -> "x"); s.join(); System.out.println(f.get()); } } }
^
symbol: class ShutdownOnFailure
location: interface StructuredTaskScope
1 error