├── tmp └── .gitkeep ├── src └── main │ ├── resources │ ├── JDK11Info.json │ ├── jep512 │ │ ├── CompactHelloWorld.java │ │ └── BasicHelloWorld.java │ ├── jep458 │ │ ├── Main.java │ │ └── Helper.java │ ├── JDK13Info.json │ ├── JDK12Info.json │ ├── JDK19Info.json │ ├── JDK20Info.json │ ├── JDK18Info.json │ └── JDK15Info.json │ └── java │ └── org │ └── javademos │ ├── commons │ ├── IDemoLoader.java │ └── IDemo.java │ ├── java11 │ ├── var │ │ ├── IVarDemo.java │ │ ├── VarDemoVeryLongClassNameThatWeDoNotWantToRepeat.java │ │ ├── VarDemoParent.java │ │ ├── IVarDemoImpl1.java │ │ ├── IVarDemoImpl2.java │ │ ├── VarDemoSon.java │ │ └── VarDemoDaughter.java │ ├── j9 │ │ ├── IJ9DemoImpl.java │ │ ├── IJ9Demo.java │ │ └── J9DemoAutoCloseable.java │ └── string11 │ │ └── String11Demo.java │ ├── java16 │ ├── jep395 │ │ └── IRecord.java │ ├── extras │ │ └── MapMulti.java │ ├── jep397 │ │ └── SealedClassesDemo.java │ ├── jep338 │ │ └── VectorAPIDemo.java │ ├── jep389 │ │ └── ForeignLinkerDemo.java │ ├── jep393 │ │ └── ForeignMemoryAccessDemo.java │ ├── jep388 │ │ └── WindowsPortDemo.java │ ├── jep390 │ │ └── ValueBasedClassesDemo.java │ ├── jep394 │ │ └── InstanceofPatternMatchingDemo.java │ ├── jep386 │ │ └── AlpineLinuxPortDemo.java │ └── jep396 │ │ └── EncapsulationDemo.java │ ├── java14 │ ├── jep358 │ │ ├── NullPointerLevel4.java │ │ ├── NullPointerLevel1.java │ │ ├── NullPointerLevel2.java │ │ ├── NullPointerLevel3.java │ │ └── NullPointerDemo.java │ ├── jep359 │ │ └── RecordsPreviewDemo.java │ ├── jep368 │ │ └── TextBlockSecondPreviewDemo.java │ ├── jep305 │ │ └── InstanceofPatternMatchingPreview.java │ ├── jep370 │ │ └── ForeignMemoryAccessDemo.java │ ├── jep343 │ │ └── PackagingToolIncubatorDemo.java │ ├── jep362 │ │ └── SolarisSparcRemovalDemo.java │ ├── jep364 │ │ └── ZGarbageCollectorOnMacOS.java │ ├── jep365 │ │ └── ZGarbageCollectorOnWindows.java │ └── jep367 │ │ └── Pack200Demo.java │ ├── java15 │ ├── jep360 │ │ └── SealedClassesDemo.java │ ├── jep384 │ │ └── RecordsSecondPreviewDemo.java │ ├── jep375 │ │ └── InstanceofPatternMatchingSecondPreview.java │ ├── jep383 │ │ └── ForeignMemoryAccessDemo.java │ ├── jep381 │ │ └── SolarisSparcRemovalDemo.java │ ├── jep372 │ │ └── NashornRemovalDemo.java │ ├── jep373 │ │ └── DatagramSocketDemo.java │ └── jep377 │ │ └── ZGarbageCollectorDemo.java │ ├── java19 │ ├── jep425 │ │ └── VirtualThreads.java │ ├── jep405 │ │ └── RecordPatterns.java │ ├── jep426 │ │ └── VectorAPIDemo.java │ ├── jep428 │ │ └── StructuredConcurrencyDemo.java │ ├── jep427 │ │ └── PatternMatchingForSwitchThirdPreview.java │ ├── jep424 │ │ └── ForeignFunctionMemoryDemo.java │ └── jep422 │ │ └── LinuxRiscVPort.java │ ├── java20 │ ├── jep436 │ │ └── VirtualThreads.java │ ├── jep429 │ │ └── ScopedValuesDemo.java │ ├── jep438 │ │ └── VectorAPIDemo.java │ ├── jep432 │ │ └── RecordPatterns.java │ ├── jep437 │ │ └── StructuredConcurrencyDemo.java │ ├── jep433 │ │ └── PatternMatchingForSwitchFourthPreview.java │ └── jep434 │ │ └── ForeignFunctionMemoryDemo.java │ ├── java22 │ ├── jep457 │ │ └── ClassFileAPIDemo.java │ ├── jep464 │ │ └── ScopedValuesDemo.java │ ├── jep460 │ │ └── VectorAPIDemo.java │ ├── jep461 │ │ └── StreamGatherersDemo.java │ ├── jep447 │ │ └── StatementsBeforeSuper.java │ ├── jep462 │ │ └── StructuredConcurrencyDemo.java │ ├── jep463 │ │ └── ImplicitlyDeclaredClassesDemo.java │ ├── jep423 │ │ └── RegionPinningForG1.java │ ├── jep458 │ │ └── LaunchMultiFileSourceDemo.java │ ├── jep459 │ │ └── StringTemplatesSecondPreview.java │ └── jep454 │ │ └── ForeignFunctionMemoryDemo.java │ ├── java21 │ ├── jep446 │ │ └── ScopedValuesDemo.java │ ├── jep430 │ │ └── StringTemplatesDemo.java │ ├── jep448 │ │ └── VectorAPIDemo.java │ ├── jep453 │ │ └── StructuredConcurrencyDemo.java │ ├── jep445 │ │ └── UnnamedClassesDemo.java │ ├── jep442 │ │ └── ForeignFunctionMemoryDemo.java │ ├── jep443 │ │ └── UnnamedPatternsAndVariablesPreview.java │ ├── jep449 │ │ └── DeprecateWindows32BitX86Demo.java │ └── jep439 │ │ └── GenerationalZGC21.java │ ├── java23 │ ├── jep466 │ │ └── ClassFileAPIDemo.java │ ├── jep481 │ │ └── ScopedValuesDemo.java │ ├── jep469 │ │ └── VectorAPIDemo.java │ ├── jep473 │ │ └── StreamGatherersDemo.java │ ├── jep480 │ │ └── StructuredConcurrency.java │ ├── jep462 │ │ └── StructuredConcurrencyDemo.java │ ├── jep482 │ │ └── FlexibleConstructorBodies.java │ ├── jep476 │ │ └── ModuleImportDeclarations.java │ ├── jep477 │ │ └── ImplicitlyDeclaredClassesDemo.java │ ├── jep455 │ │ └── PrimitiveTypesInPatterns.java │ ├── jep471 │ │ └── DeprecateMemoryAccessMethods.java │ ├── jep467 │ │ └── MarkdownComments.java │ └── jep474 │ │ └── GenerationalZGC23.java │ ├── java24 │ ├── jep487 │ │ └── ScopedValuesDemo.java │ ├── jep489 │ │ └── VectorAPIDemo.java │ ├── jep492 │ │ └── FlexibleConstructorBodies.java │ ├── jep499 │ │ └── StructuredConcurrencyDemo.java │ ├── jep495 │ │ └── SimpleSourceFilesDemo.java │ ├── jep494 │ │ └── ModuleImportSecondPreview.java │ ├── jep404 │ │ └── GenerationalShenandoahExperimental.java │ ├── jep450 │ │ └── CompactObjectHeadersExperimental.java │ ├── jep488 │ │ └── PrimitiveTypesSecondPreview.java │ ├── jep478 │ │ └── KeyDerivationApiPreview.java │ ├── jep483 │ │ └── AotLoadingAndLinking.java │ ├── jep501 │ │ └── Deprecate32BitX86Demo.java │ ├── jep479 │ │ └── RemovedWindows32BitX86Demo.java │ ├── jep493 │ │ └── LinkingRunTimeImages493.java │ ├── jep486 │ │ └── DisableSecurityManager.java │ ├── jep490 │ │ └── ZgcNonGenerationalModeRemoval.java │ ├── jep498 │ │ └── MemoryAccessMethods.java │ ├── jep475 │ │ └── LateBarrierExpansionG1.java │ ├── jep491 │ │ └── SynchronizedNoPinning.java │ └── jep497 │ │ └── QuantumResistantModuleLatticeBasedDigitalSignature.java │ ├── java17 │ ├── jep414 │ │ └── VectorAPIDemo.java │ ├── jep406 │ │ └── PatternMatchingForSwitchPreview.java │ ├── jep411 │ │ └── DeprecateSecurityManagerDemo.java │ ├── jep412 │ │ └── ForeignFunctionMemoryDemo.java │ ├── jep409 │ │ ├── SealedDemoParent.java │ │ ├── SealedDemoBastard.java │ │ ├── SealedDemoChild.java │ │ └── SealedDemo.java │ ├── jep398 │ │ └── DeprecateAppletApiForRemovalDemo.java │ ├── jep356 │ │ └── RandomGeneratorsDemo.java │ ├── jep391 │ │ └── MacOsAarch64PortDemo.java │ ├── jep306 │ │ └── RestoreAlwaysStrictFloatingPointSemanticsDemo.java │ ├── jep410 │ │ └── RemoveAotJitDemo.java │ ├── extras │ │ └── J17DeprecatedDemo.java │ ├── jep403 │ │ └── StronglyEncapsulateInternalsDemo.java │ ├── jep382 │ │ └── MacosRenderingPipelineDemo.java │ └── jep407 │ │ └── RemoveRmiActivationDemo.java │ ├── java18 │ ├── jep417 │ │ └── VectorAPIDemo.java │ ├── jep420 │ │ └── PatternMatchingForSwitchSecondPreview.java │ ├── jep419 │ │ └── ForeignFunctionMemoryDemo.java │ ├── jep400 │ │ └── DefaultUTF8Demo.java │ └── jep421 │ │ └── DeprecateFinalization.java │ ├── init │ ├── Java12DemoLoader.java │ ├── Java13DemoLoader.java │ ├── Java11DemoLoader.java │ ├── Java19DemoLoader.java │ ├── Java20DemoLoader.java │ ├── Java18DemoLoader.java │ ├── Java15DemoLoader.java │ ├── Java23DemoLoader.java │ ├── Java22DemoLoader.java │ ├── Java16DemoLoader.java │ ├── Java17DemoLoader.java │ ├── Java21DemoLoader.java │ ├── Java14DemoLoader.java │ └── Java25DemoLoader.java │ ├── java13 │ ├── jep355 │ │ └── TextBlockFirstPreviewDemo.java │ └── jep354 │ │ └── SwitchExpressionsSecondPreview.java │ ├── java12 │ ├── jep325 │ │ └── SwitchExpressionsPreview.java │ └── extras │ │ └── String12Demo.java │ ├── java25 │ ├── jep518 │ │ └── JFRCooperativeSamplingDemo.java │ ├── jep470 │ │ └── PemEncodingsDemo.java │ ├── jep509 │ │ └── CpuTimeProfilingDemo.java │ ├── jep503 │ │ └── Remove32BitX86Demo.java │ ├── jep511 │ │ └── ModuleImportDeclarationsDemo.java │ ├── jep506 │ │ └── ScopedValuesDemo.java │ ├── jep502 │ │ └── StableValuesDemo.java │ ├── jep510 │ │ └── KeyDerivationFunctionDemo.java │ ├── jep513 │ │ └── FlexibleConstructorBodiesDemo.java │ ├── jep514 │ │ └── AheadOfTimeCLIDemo.java │ ├── jep515 │ │ └── AheadOfTimeMethodProfilingDemo.java │ └── jep519 │ │ └── CompactObjectHeaderDemo.java │ └── Main.java ├── .gitignore ├── LICENSE.txt └── .github └── workflows └── pr-build-check.yaml /tmp/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/JDK11Info.json: -------------------------------------------------------------------------------- 1 | [ 2 | 3 | ] -------------------------------------------------------------------------------- /src/main/resources/jep512/CompactHelloWorld.java: -------------------------------------------------------------------------------- 1 | void main() { 2 | IO.println("Hello from a compact source file!"); 3 | } 4 | -------------------------------------------------------------------------------- /src/main/resources/jep458/Main.java: -------------------------------------------------------------------------------- 1 | package jep458; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Helper.greet(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/jep458/Helper.java: -------------------------------------------------------------------------------- 1 | package jep458; 2 | 3 | public class Helper { 4 | public static void greet() { 5 | System.out.println("Hello from Helper!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/jep512/BasicHelloWorld.java: -------------------------------------------------------------------------------- 1 | package jep512; 2 | 3 | public class BasicHelloWorld { 4 | public static void main(String[] args) { 5 | System.out.println("Hello, World!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Typical .gitignore entries for a Java project 2 | /target/ 3 | nbactions.xml 4 | github.txt 5 | .idea 6 | .vscode 7 | 8 | # Accidentally committed class files 9 | *.class 10 | 11 | # Keep tmp directory 12 | !/tmp/.gitkeep 13 | 14 | # But ignore generated demo files 15 | /tmp/ -------------------------------------------------------------------------------- /src/main/java/org/javademos/commons/IDemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.commons; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Interface for loading demos for a specific Java version. 7 | */ 8 | public interface IDemoLoader { 9 | 10 | void loadDemos(Map demos); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/var/IVarDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.var; 2 | 3 | /** 4 | * Simple interface to show 'var' keyword behavior. 5 | * 6 | * @see VarDemo 7 | * 8 | * @author alois.seckar@gmail.com 9 | */ 10 | public interface IVarDemo { 11 | 12 | void foo(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/var/VarDemoVeryLongClassNameThatWeDoNotWantToRepeat.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.var; 2 | 3 | /** 4 | * Simple class to show 'var' keyword behavior. 5 | * 6 | * @see VarDemo 7 | * 8 | * @author alois.seckar@gmail.com 9 | */ 10 | public class VarDemoVeryLongClassNameThatWeDoNotWantToRepeat { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep395/IRecord.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep395; 2 | 3 | /** 4 | * Simple interface to show 'record' keyword behavior. 5 | * Java 'record' allows implementing interfaces. 6 | * 7 | * @see RecordDemo 8 | * 9 | * @author alois.seckar@gmail.com 10 | */ 11 | public interface IRecord { 12 | 13 | void foo(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/var/VarDemoParent.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.var; 2 | 3 | /** 4 | * Simple super-class to show 'var' keyword behavior. 5 | * 6 | * @see VarDemo 7 | * 8 | * @author alois.seckar@gmail.com 9 | */ 10 | public class VarDemoParent { 11 | 12 | public void foo() { 13 | System.out.println("I am parent"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/extras/MapMulti.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.extras; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | @Data 7 | @AllArgsConstructor 8 | public class MapMulti { 9 | 10 | int length; 11 | char first; 12 | boolean endsWithA; 13 | 14 | @Override 15 | public String toString() { 16 | return "[" + length + " " + first + " " + endsWithA + "] "; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/var/IVarDemoImpl1.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.var; 2 | 3 | /** 4 | * Simple implementation of IVarDemo to show 'var' keyword behavior. 5 | * 6 | * @see IVarDemo 7 | * @see VarDemo 8 | * 9 | * @author alois.seckar@gmail.com 10 | */ 11 | public class IVarDemoImpl1 implements IVarDemo { 12 | 13 | @Override 14 | public void foo() { 15 | System.out.println("Hello from IVarDemoImpl1"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/var/IVarDemoImpl2.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.var; 2 | 3 | /** 4 | * Simple implementation of IVarDemo to show 'var' keyword behavior. 5 | * 6 | * @see IVarDemo 7 | * @see VarDemo 8 | * 9 | * @author alois.seckar@gmail.com 10 | */ 11 | public class IVarDemoImpl2 implements IVarDemo { 12 | 13 | @Override 14 | public void foo() { 15 | System.out.println("Hello from IVarDemoImpl2"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/var/VarDemoSon.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.var; 2 | 3 | /** 4 | * Simple sub-class of VarDemoParent to show 'var' keyword behavior. 5 | * 6 | * @see VarDemoParent 7 | * @see VarDemo 8 | * 9 | * @author alois.seckar@gmail.com 10 | */ 11 | public class VarDemoSon extends VarDemoParent { 12 | 13 | @Override 14 | public void foo() { 15 | super.foo(); 16 | System.out.println("And I am his son"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep358/NullPointerLevel4.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep358; 2 | 3 | /** 4 | * Simple class to show 'helpful' NullPointerExceptions from Java 14. 5 | * Here we have 4-level nested class structure and somewhere on the way 6 | * one element is 'null', so invoking method on it will raise 'NullPointer'. 7 | * 8 | * @author Abhineshhh 9 | */ 10 | public class NullPointerLevel4 { 11 | 12 | // final level without any deeper nested members 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/var/VarDemoDaughter.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.var; 2 | 3 | /** 4 | * Simple subclass of VarDemoParent to show 'var' keyword behavior. 5 | * 6 | * @see VarDemoParent 7 | * @see VarDemo 8 | * 9 | * @author alois.seckar@gmail.com 10 | */ 11 | public class VarDemoDaughter extends VarDemoParent { 12 | 13 | @Override 14 | public void foo() { 15 | super.foo(); 16 | System.out.println("And I am his daughter"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep359/RecordsPreviewDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep359; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 359 - Records (Preview). 6 | /// 7 | /// This was a preview JEP. The feature was finalized in JDK 16 by JEP 395. 8 | /// @see org.javademos.java16.jep395.RecordDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class RecordsPreviewDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(359); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/resources/JDK13Info.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "jep": 354, 4 | "jdk": 13, 5 | "name": "JEP 354 - Switch Expressions (Second Preview)", 6 | "dscr": "Up-to-date demo in `org.javademos.java14.jep361.SwitchExpressionsDemo`.", 7 | "link": true, 8 | "code": false 9 | }, 10 | { 11 | "jep": 355, 12 | "jdk": 13, 13 | "name": "JEP 355 - Text Blocks (Preview)", 14 | "dscr": "Up-to-date demo in `org.javademos.java15.jep378.TextBlockDemo`.", 15 | "link": true, 16 | "code": false 17 | } 18 | ] -------------------------------------------------------------------------------- /src/main/java/org/javademos/java15/jep360/SealedClassesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java15.jep360; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 15 feature JEP 360 - Sealed Classes (Preview). 6 | /// 7 | /// This was a preview JEP. The feature was finalized in JDK 17 by JEP 409. 8 | /// @see org.javademos.java17.jep409.SealedDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class SealedClassesDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(360); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep397/SealedClassesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep397; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 16 feature JEP 397 - Sealed Classes (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature was finalized in JDK 17 by JEP 409. 8 | /// @see org.javademos.java17.jep409.SealedDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class SealedClassesDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(397); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java19/jep425/VirtualThreads.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java19.jep425; 2 | import org.javademos.commons.IDemo; 3 | 4 | /// Demo for JDK 19 feature JEP 425 - Virtual Threads(Preview). 5 | /// 6 | /// This was an incubator JEP. The feature is finalized in JDK 21 by JEP 444. 7 | /// 8 | /// @see org.javademos.java21.jep444.VirtualThreadsDemo 9 | /// 10 | /// @author @Rossville 11 | public class VirtualThreads implements IDemo{ 12 | public void demo(){ 13 | info(425); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java15/jep384/RecordsSecondPreviewDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java15.jep384; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 15 feature JEP 384 - Records (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature was finalized in JDK 16 by JEP 395. 8 | /// @see org.javademos.java16.jep395.RecordDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class RecordsSecondPreviewDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(384); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java19/jep405/RecordPatterns.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java19.jep405; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 19 feature JEP 405 - Record Patterns(Preview). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 21 by JEP 440. 8 | /// 9 | /// @see org.javademos.java21.jep440.RecordPatternsDemo 10 | /// 11 | /// @author @Rossville 12 | public class RecordPatterns implements IDemo { 13 | public void demo() { 14 | info(405); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java20/jep436/VirtualThreads.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java20.jep436; 2 | import org.javademos.commons.IDemo; 3 | 4 | /// Demo for JDK 20 feature JEP 436 - Virtual Threads(Second Preview). 5 | /// 6 | /// This was an incubator JEP. The feature is finalized in JDK 21 by JEP 444. 7 | /// 8 | /// @see org.javademos.java21.jep444.VirtualThreadsDemo 9 | /// 10 | /// @author @Rossville 11 | public class VirtualThreads implements IDemo{ 12 | public void demo(){ 13 | info(436); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep457/ClassFileAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep457; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 457 - Class-File API (Preview). 6 | /// 7 | /// Replaced with most recent [JEP 484](https://openjdk.org/jeps/484) 8 | /// @see org.javademos.java24.jep484.ClassFileApiDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class ClassFileAPIDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(457); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep446/ScopedValuesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep446; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 feature JEP 446 - Scoped Values (Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 25 by JEP 506. 8 | /// @see org.javademos.java25.jep506.ScopedValuesDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class ScopedValuesDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(446); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep338/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep338; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 16 feature JEP 338 - Vector API (Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(338); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java20/jep429/ScopedValuesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java20.jep429; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 20 feature JEP 429 - Scoped Values (Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 25 by JEP 506. 8 | /// @see org.javademos.java25.jep506.ScopedValuesDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class ScopedValuesDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(429); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep464/ScopedValuesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep464; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 464 - Scoped Values (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 25 by JEP 506. 8 | /// @see org.javademos.java25.jep506.ScopedValuesDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class ScopedValuesDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(464); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep466/ClassFileAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep466; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 466 - Class-File API (Second Preview). 6 | /// 7 | /// Replaced with most recent [JEP 484](https://openjdk.org/jeps/484) 8 | /// @see org.javademos.java24.jep484.ClassFileApiDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class ClassFileAPIDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(466); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep481/ScopedValuesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep481; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 481 - Scoped Values (Third Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 25 by JEP 506. 8 | /// @see org.javademos.java25.jep506.ScopedValuesDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class ScopedValuesDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(481); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep487/ScopedValuesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep487; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 487 - Scoped Values (Fourth Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 25 by JEP 506. 8 | /// @see org.javademos.java25.jep506.ScopedValuesDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class ScopedValuesDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(487); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep414/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep414; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 414 - Vector API (Second Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(414); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java18/jep417/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java18.jep417; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 18 feature JEP 417 - Vector API (Third Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(417); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java19/jep426/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java19.jep426; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 19 feature JEP 426 - Vector API (Fourth Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(426); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java20/jep438/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java20.jep438; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 20 feature JEP 438 - Vector API (Fifth Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(438); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep430/StringTemplatesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep430; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 feature JEP 430 - String Templates (Preview). 6 | /// 7 | /// Replaced with most recent [JEP 459](https://openjdk.org/jeps/459) 8 | /// @see org.javademos.java22.jep459.StringTemplatesSecondPreview 9 | /// 10 | /// @author mayankvyas1306 11 | public class StringTemplatesDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(430); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep448/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep448; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 feature JEP 448 - Vector API (Sixth Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(448); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep460/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep460; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 460 - Vector API (Seventh Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(460); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep461/StreamGatherersDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep461; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 461 - Stream Gatherers (Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 24 by JEP 485. 8 | /// @see org.javademos.java24.jep485.StreamGatherersDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class StreamGatherersDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(461); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep469/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep469; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 469 - Vector API (Eighth Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(469); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep489/VectorAPIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep489; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 489 - Vector API (Ninth Incubator). 6 | /// 7 | /// Replaced with most recent [JEP 508](https://openjdk.org/jeps/508) 8 | /// @see org.javademos.java25.jep508.VectorAPIDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class VectorAPIDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(489); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java20/jep432/RecordPatterns.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java20.jep432; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 20 feature JEP 432 - Record Patterns(Second Preview). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 21 by JEP 440. 8 | /// 9 | /// @see org.javademos.java21.jep440.RecordPatternsDemo 10 | /// 11 | /// @author @Rossville 12 | public class RecordPatterns implements IDemo { 13 | @Override 14 | public void demo() { 15 | info(432); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep473/StreamGatherersDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep473; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 473 - Stream Gatherers (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 24 by JEP 485. 8 | /// @see org.javademos.java24.jep485.StreamGatherersDemo 9 | /// 10 | /// @author ankitkrshah30 11 | public class StreamGatherersDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(473); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep453/StructuredConcurrencyDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep453; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 feature JEP 453 - Structured Concurrency (Preview). 6 | /// 7 | /// This was a preview JEP. The feature's latest iteration is in JDK 25 by JEP 505. 8 | /// @see org.javademos.java25.jep505.StructuredConcurrencyDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class StructuredConcurrencyDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(453); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep447/StatementsBeforeSuper.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep447; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | 6 | /// Demo for JDK 22 feature JEP 447 - Statements before super(...). 7 | /// 8 | /// Replaced with [JEP 513](https://openjdk.org/jeps/513) 9 | /// @see org.javademos.java25.jep513.FlexibleConstructorBodiesDemo 10 | /// 11 | /// @author alois.seckar@gmail.com 12 | public class StatementsBeforeSuper implements IDemo { 13 | 14 | @Override 15 | public void demo() { 16 | info(447); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep480/StructuredConcurrency.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep480; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 480 - Structured Concurrency (Third Preview). 6 | /// 7 | /// This was a preview JEP. The feature's latest iteration is in JDK 25 by JEP 505. 8 | /// @see org.javademos.java25.jep505.StructuredConcurrencyDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class StructuredConcurrency implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(480); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep492/FlexibleConstructorBodies.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep492; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 492 - Flexible Constructor Bodies (Third Preview). 6 | /// 7 | /// Replaced with [JEP 513](https://openjdk.org/jeps/513) 8 | /// @see org.javademos.java25.jep513.FlexibleConstructorBodiesDemo 9 | /// 10 | /// @author rishabhrawat05 11 | 12 | public class FlexibleConstructorBodies implements IDemo { 13 | 14 | @Override 15 | public void demo() { 16 | info(492); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java19/jep428/StructuredConcurrencyDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java19.jep428; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 19 feature JEP 428 - Structured Concurrency (Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature's latest iteration is in JDK 25 by JEP 505. 8 | /// @see org.javademos.java25.jep505.StructuredConcurrencyDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class StructuredConcurrencyDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(428); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep462/StructuredConcurrencyDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep462; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 462 - Structured Concurrency (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature's latest iteration is in JDK 25 by JEP 505. 8 | /// @see org.javademos.java25.jep505.StructuredConcurrencyDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class StructuredConcurrencyDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(462); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep462/StructuredConcurrencyDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep462; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 462 - Structured Concurrency (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature's latest iteration is in JDK 25 by JEP 505. 8 | /// @see org.javademos.java25.jep505.StructuredConcurrencyDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class StructuredConcurrencyDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(462); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep499/StructuredConcurrencyDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep499; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 499 - Structured Concurrency (Fourth Preview). 6 | /// 7 | /// This was a preview JEP. The feature's latest iteration is in JDK 25 by JEP 505. 8 | /// @see org.javademos.java25.jep505.StructuredConcurrencyDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class StructuredConcurrencyDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(499); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java20/jep437/StructuredConcurrencyDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java20.jep437; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 20 feature JEP 437 - Structured Concurrency (Second Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature's latest iteration is in JDK 25 by JEP 505. 8 | /// @see org.javademos.java25.jep505.StructuredConcurrencyDemo 9 | /// 10 | /// @author Adarsh80416 11 | public class StructuredConcurrencyDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(437); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep445/UnnamedClassesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep445; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 feature JEP 445 - Unnamed Classes and Instance Main Methods (Preview). 6 | /// 7 | /// Replaced with most recent [JEP 512](https://openjdk.org/jeps/512) 8 | /// @see org.javademos.java25.jep512.CompactSourceFilesDemo 9 | /// 10 | /// @author kishansingh956196@gmail.com 11 | public class UnnamedClassesDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(445); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/resources/JDK12Info.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "jep": 325, 4 | "jdk": 12, 5 | "name": "JEP 325 - Switch Expressions (Preview)", 6 | "dscr": "Up-to-date demo in `org.javademos.java14.jep361.SwitchExpressionsDemo`.", 7 | "link": true, 8 | "code": false 9 | }, 10 | { 11 | "jep": 334, 12 | "jdk": 12, 13 | "name": "JEP 334 - JVM Constants API", 14 | "dscr": "Introduces an API to model nominal descriptions of class file and runtime artifacts, especially constants loadable from the constant pool.", 15 | "link": false, 16 | "code": true 17 | } 18 | ] -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep495/SimpleSourceFilesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep495; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 495 - Simple Source Files and Instance Main Methods (Fourth Preview). 6 | /// 7 | /// Replaced with most recent [JEP 512](https://openjdk.org/jeps/512) 8 | /// @see org.javademos.java25.jep512.CompactSourceFilesDemo 9 | /// 10 | /// @author dhruv-git-sys 11 | public class SimpleSourceFilesDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(495); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep389/ForeignLinkerDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep389; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 16 feature JEP 389 - Foreign-Linker API (Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignLinkerDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(389); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep406/PatternMatchingForSwitchPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep406; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// 6 | /// # JEP 406: Pattern Matching for switch (Preview) 7 | /// 8 | /// @author mayankvyas1306 9 | /// 10 | /// This is a linking class to the final implementation in JEP 441. 11 | /// Please see {@link org.javademos.java21.jep441.PatternMatchingForSwitchDemo}. 12 | /// 13 | public class PatternMatchingForSwitchPreview implements IDemo { 14 | 15 | @Override 16 | public void demo() { 17 | info(406); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep411/DeprecateSecurityManagerDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep411; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 411 - Deprecate the Security Manager for Removal. 6 | /// 7 | /// This was the deprecation step. The feature is permanently disabled in JDK 24 by JEP 486. 8 | /// @see org.javademos.java24.jep486.DisableSecurityManager 9 | /// 10 | /// @author Adarsh80416 11 | public class DeprecateSecurityManagerDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(411); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep368/TextBlockSecondPreviewDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep368; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 368 - Text Blocks (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 15 by JEP 378. 8 | /// @see org.javademos.java15.jep378.TextBlockDemo 9 | /// 10 | /// @author SanjanaMahapatra 11 | 12 | 13 | public class TextBlockSecondPreviewDemo implements IDemo { 14 | 15 | @Override 16 | public void demo() { 17 | info(368); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep305/InstanceofPatternMatchingPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep305; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 305 - Pattern Matching for instanceof (Preview). 6 | /// 7 | /// This was a preview JEP. The feature was finalized in JDK 16 by JEP 394. 8 | /// @see org.javademos.java16.jep394.InstanceofPatternMatchingDemo 9 | /// 10 | /// @author Shuvam00032 11 | public class InstanceofPatternMatchingPreview implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(305); 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep482/FlexibleConstructorBodies.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep482; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | 6 | /// Demo for JDK 23 feature JEP 482 - Flexible Constructor Bodies (Second Preview). 7 | /// 8 | /// Replaced with [JEP 513](https://openjdk.org/jeps/513) 9 | /// @see org.javademos.java25.jep513.FlexibleConstructorBodiesDemo 10 | /// 11 | /// @author alois.seckar@gmail.com 12 | public class FlexibleConstructorBodies implements IDemo { 13 | @Override 14 | public void demo() { 15 | info(482); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java15/jep375/InstanceofPatternMatchingSecondPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java15.jep375; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 15 feature JEP 375 - Pattern Matching for instanceof (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature was finalized in JDK 16 by JEP 394. 8 | /// @see org.javademos.java16.jep394.InstanceofPatternMatchingDemo 9 | /// 10 | /// @author Shuvam00032 11 | public class InstanceofPatternMatchingSecondPreview implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(375); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java18/jep420/PatternMatchingForSwitchSecondPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java18.jep420; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// 6 | /// # JEP 420: Pattern Matching for switch (Second Preview) 7 | /// 8 | /// @author mayankvyas1306 9 | /// 10 | /// This is a linking class to the final implementation in JEP 441. 11 | /// Please see {@link org.javademos.java21.jep441.PatternMatchingForSwitchDemo}. 12 | /// 13 | public class PatternMatchingForSwitchSecondPreview implements IDemo { 14 | 15 | @Override 16 | public void demo() { 17 | info(420); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java19/jep427/PatternMatchingForSwitchThirdPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java19.jep427; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// 6 | /// # JEP 427: Pattern Matching for switch (Third Preview) 7 | /// 8 | /// @author mayankvyas1306 9 | /// 10 | /// This is a linking class to the final implementation in JEP 441. 11 | /// Please see {@link org.javademos.java21.jep441.PatternMatchingForSwitchDemo}. 12 | /// 13 | public class PatternMatchingForSwitchThirdPreview implements IDemo { 14 | 15 | @Override 16 | public void demo() { 17 | info(427); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java20/jep433/PatternMatchingForSwitchFourthPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java20.jep433; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// 6 | /// # JEP 433: Pattern Matching for switch (Fourth Preview) 7 | /// 8 | /// @author mayankvyas1306 9 | /// 10 | /// This is a linking class to the final implementation in JEP 441. 11 | /// Please see {@link org.javademos.java21.jep441.PatternMatchingForSwitchDemo}. 12 | /// 13 | public class PatternMatchingForSwitchFourthPreview implements IDemo { 14 | 15 | @Override 16 | public void demo() { 17 | info(433); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep370/ForeignMemoryAccessDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep370; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 370 - Foreign-Memory Access API (Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignMemoryAccessDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(370); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep476/ModuleImportDeclarations.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep476; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 476 - Module Import Declarations (Preview). 6 | /// 7 | /// This was the first preview of this feature. 8 | /// The feature is finalized in JDK 25 (JEP 511). 9 | /// @see org.javademos.java25.jep511.ModuleImportDeclarationsDemo 10 | /// 11 | /// @author harshitkumar7525 12 | public class ModuleImportDeclarations implements IDemo { 13 | @Override 14 | public void demo() { 15 | info(476); 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java15/jep383/ForeignMemoryAccessDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java15.jep383; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 15 feature JEP 383 - Foreign-Memory Access API (Second Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignMemoryAccessDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(383); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep393/ForeignMemoryAccessDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep393; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 16 feature JEP 393 - Foreign-Memory Access API (Third Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignMemoryAccessDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(393); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java19/jep424/ForeignFunctionMemoryDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java19.jep424; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 19 feature JEP 424 - Foreign Function & Memory API (Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignFunctionMemoryDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(424); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep412/ForeignFunctionMemoryDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep412; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 412 - Foreign Function & Memory API (Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignFunctionMemoryDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(412); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java20/jep434/ForeignFunctionMemoryDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java20.jep434; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 20 feature JEP 434 - Foreign Function & Memory API (Second Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignFunctionMemoryDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(434); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep442/ForeignFunctionMemoryDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep442; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 feature JEP 442 - Foreign Function & Memory API (Third Preview). 6 | /// 7 | /// This was a preview JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignFunctionMemoryDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(442); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep494/ModuleImportSecondPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep494; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 494 - Module Import Declarations (Second Preview). 6 | /// 7 | /// This was the second preview of this feature. 8 | /// The feature is finalized in JDK 25 (JEP 511). 9 | /// @see org.javademos.java25.jep511.ModuleImportDeclarationsDemo 10 | /// 11 | /// @author harshitkumar7525 12 | public class ModuleImportSecondPreview implements IDemo { 13 | @Override 14 | public void demo() { 15 | info(494); 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java18/jep419/ForeignFunctionMemoryDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java18.jep419; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 18 feature JEP 419 - Foreign Function & Memory API (Second Incubator). 6 | /// 7 | /// This was an incubator JEP. The feature is finalized in JDK 25 by JEP 454. 8 | /// @see org.javademos.java25.jep454.ForeignFunctionMemoryDemo 9 | /// 10 | /// @author Alois Seckar 11 | public class ForeignFunctionMemoryDemo implements IDemo { 12 | @Override 13 | public void demo() { 14 | info(419); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep463/ImplicitlyDeclaredClassesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep463; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 463 - Implicitly Declared Classes and Instance Main Methods (Second Preview). 6 | /// 7 | /// Replaced with most recent [JEP 512](https://openjdk.org/jeps/512) 8 | /// @see org.javademos.java25.jep512.CompactSourceFilesDemo 9 | /// 10 | /// @author kishansingh956196@gmail.com 11 | public class ImplicitlyDeclaredClassesDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(463); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep477/ImplicitlyDeclaredClassesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep477; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 477 - Implicitly Declared Classes and Instance Main Methods (Third Preview). 6 | /// 7 | /// Replaced with most recent [JEP 512](https://openjdk.org/jeps/512) 8 | /// @see org.javademos.java25.jep512.CompactSourceFilesDemo 9 | /// 10 | /// @author Ankit Kumar Shah @ankitkrshah30 11 | public class ImplicitlyDeclaredClassesDemo implements IDemo { 12 | 13 | @Override 14 | public void demo() { 15 | info(477); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep409/SealedDemoParent.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep409; 2 | 3 | /** 4 | * Simple class to show 'sealed class' concept from Java 17. 5 | * If class is 'sealed', it MUST also have 'permits' section with 1-n 6 | * allowed subclasses. Those subclasses must exist and MUST extend parent. 7 | * 8 | * @see SealedDemoChild 9 | * @see SealedDemoBastard 10 | * 11 | * @author alois.seckar@gmail.com 12 | */ 13 | public sealed class SealedDemoParent permits SealedDemoChild { 14 | 15 | public void foo() { 16 | System.out.println("Hello from parent class"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep455/PrimitiveTypesInPatterns.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep455; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 455 - Primitive Types in Patterns, instanceof, and switch (Preview). 6 | /// 7 | /// This was the first preview of this feature. 8 | /// The feature is in its third preview in JDK 25 (JEP 507). 9 | /// @see org.javademos.java25.jep507.PrimitiveTypesDemo 10 | /// 11 | /// @author harshitkumar7525 12 | public class PrimitiveTypesInPatterns implements IDemo { 13 | 14 | @Override 15 | public void demo() { 16 | info(455); 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep404/GenerationalShenandoahExperimental.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep404; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 404 - Generational Shenandoah (Experimental). 6 | /// 7 | /// This was an experimental version of the feature. 8 | /// The main demo is for the final implementation in JDK 25 (JEP 521). 9 | /// @see org.javademos.java25.jep521.GenerationalShenandoahDemo 10 | /// 11 | /// @author harshitkumar7525 12 | public class GenerationalShenandoahExperimental implements IDemo { 13 | @Override 14 | public void demo() { 15 | info(404); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java12DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java12.jep325.SwitchExpressionsPreview; 9 | import org.javademos.java12.jep334.ConstantsAPIDemo; 10 | 11 | /** 12 | * Loads demos for Java 12. 13 | */ 14 | public class Java12DemoLoader implements IDemoLoader { 15 | 16 | @Override 17 | public void loadDemos(Map demos) { 18 | demos.put(325, new SwitchExpressionsPreview()); 19 | demos.put(334, new ConstantsAPIDemo()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep450/CompactObjectHeadersExperimental.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep450; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 450 - Compact Object Headers (Experimental). 6 | /// 7 | /// This was an experimental version of the feature. 8 | /// The main demo is for the final implementation in JDK 25 (JEP 519). 9 | /// @see org.javademos.java25.jep519.CompactObjectHeaderDemo 10 | /// 11 | /// @author harshitkumar7525 12 | public class CompactObjectHeadersExperimental implements IDemo { 13 | @Override 14 | public void demo() { 15 | info(450); 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/j9/IJ9DemoImpl.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.j9; 2 | 3 | import org.javademos.Main; 4 | 5 | /** 6 | * Sample implementation for private methods in interfaces feature from Java 9. 7 | * 8 | * @see Main 9 | * 10 | * @author alois.seckar@gmail.com 11 | */ 12 | public class IJ9DemoImpl implements IJ9Demo { 13 | 14 | /** 15 | * This method is implementation-specific. 16 | */ 17 | @Override 18 | public void foo() { 19 | System.out.println("Traditional implementation of interface method"); 20 | } 21 | 22 | // we don't want to re-implement default void stuff() from the interface 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep488/PrimitiveTypesSecondPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep488; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 488 - Primitive Types in Patterns, instanceof, and switch (Second Preview). 6 | /// 7 | /// This was the second preview of this feature. 8 | /// The feature is in its third preview in JDK 25 (JEP 507). 9 | /// @see org.javademos.java25.jep507.PrimitiveTypesDemo 10 | /// 11 | /// @author harshitkumar7525 12 | public class PrimitiveTypesSecondPreview implements IDemo { 13 | 14 | @Override 15 | public void demo() { 16 | info(488); 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java13DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java13.jep354.SwitchExpressionsSecondPreview; 9 | import org.javademos.java13.jep355.TextBlockFirstPreviewDemo; 10 | 11 | /** 12 | * Loads demos for Java 13. 13 | */ 14 | public class Java13DemoLoader implements IDemoLoader { 15 | 16 | @Override 17 | public void loadDemos(Map demos) { 18 | demos.put(354, new SwitchExpressionsSecondPreview()); 19 | demos.put(355, new TextBlockFirstPreviewDemo()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep478/KeyDerivationApiPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep478; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature Key Derivation Function API (Preview) (JEP 478). 6 | /// 7 | /// This JEP was a preview and is finalized in JDK 25 by JEP 510. 8 | /// The working demo is in the JEP 510 class. 9 | /// 10 | /// @see org.javademos.java25.jep510.KeyDerivationFunctionDemo 11 | /// @see JEP 478 12 | /// @author ankitkrshah30 13 | public class KeyDerivationApiPreview implements IDemo { 14 | @Override 15 | public void demo() { 16 | info(478); 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java11DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | /** 9 | * Loads demos for Java 11. 10 | */ 11 | public class Java11DemoLoader implements IDemoLoader { 12 | 13 | @Override 14 | public void loadDemos(Map demos) { 15 | //TODO align old demos and add necessary JDKInfo.json 16 | 17 | // Java 11 18 | // demos.put(11, new J9Demo()); 19 | // demos.put(11, new VarDemo()); 20 | // demos.put(11, new HttpDemo()); 21 | // demos.put(11, new String11Demo()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java13/jep355/TextBlockFirstPreviewDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java13.jep355; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 13 feature JEP 355 - Text Blocks (Preview). 6 | /// 7 | /// Relates to: 8 | /// - [JEP 326: Raw String Literals (Preview)](https://openjdk.org/jeps/326) 9 | /// 10 | /// This was a preview JEP. The feature is finalized in JDK 15 by JEP 378. 11 | /// @see org.javademos.java15.jep378.TextBlockDemo 12 | /// 13 | /// @author SanjanaMahapatra 14 | 15 | 16 | public class TextBlockFirstPreviewDemo implements IDemo { 17 | @Override 18 | public void demo() { 19 | info(355); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep483/AotLoadingAndLinking.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep483; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 483 - Ahead-of-Time Class Loading & Linking. 6 | /// 7 | /// This was an experimental feature. 8 | /// The main demos are for the final implementations in JDK 25 (JEP 514 and JEP 515). 9 | /// @see org.javademos.java25.jep514.AheadOfTimeCLIDemo 10 | /// @see org.javademos.java25.jep515.AheadOfTimeMethodProfilingDemo 11 | /// 12 | /// @author harshitkumar7525 13 | public class AotLoadingAndLinking implements IDemo { 14 | @Override 15 | public void demo() { 16 | info(483); 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep358/NullPointerLevel1.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep358; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * Simple class to show 'helpful' NullPointerExceptions from Java 14. 7 | * Here we have 4-level nested class structure and somewhere on the way 8 | * one element is 'null', so invoking method on it will raise 'NullPointer'. 9 | * 10 | * @author Abhineshhh 11 | */ 12 | public class NullPointerLevel1 { 13 | 14 | @Getter 15 | private final NullPointerLevel2 level2; 16 | 17 | public NullPointerLevel1() { 18 | // this is ok, nested member is properly initialized 19 | level2 = new NullPointerLevel2(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep358/NullPointerLevel2.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep358; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * Simple class to show 'helpful' NullPointerExceptions from Java 14. 7 | * Here we have 4-level nested class structure and somewhere on the way 8 | * one element is 'null', so invoking method on it will raise 'NullPointer'. 9 | * 10 | * @author Abhineshhh 11 | */ 12 | public class NullPointerLevel2 { 13 | 14 | @Getter 15 | private final NullPointerLevel3 level3; 16 | 17 | public NullPointerLevel2() { 18 | // this is still ok, nested member is properly initialized 19 | level3 = new NullPointerLevel3(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep358/NullPointerLevel3.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep358; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * Simple class to show 'helpful' NullPointerExceptions from Java 14. 7 | * Here we have 4-level nested class structure and somewhere on the way 8 | * one element is 'null', so invoking method on it will raise 'NullPointer'. 9 | * 10 | * @author Abhineshhh 11 | */ 12 | public class NullPointerLevel3 { 13 | 14 | @Getter 15 | private final NullPointerLevel4 level4; 16 | 17 | public NullPointerLevel3() { 18 | // here is our design flaw 19 | // nested member is not initialized 20 | level4 = null; 21 | // level4 = new NullPointerLevel4(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep343/PackagingToolIncubatorDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep343; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 343 - Packaging Tool (Incubator). 6 | /// 7 | /// Relates to: 8 | /// - [JEP 311 - Java Packager API & CLI](https://openjdk.org/jeps/311) 9 | /// - JDK 16: [JEP 392 - Packaging Tool (Production)](https://openjdk.org/jeps/392) 10 | /// 11 | /// Create a tool for packaging self-contained Java applications. 12 | /// @see org.javademos.java16.jep392.PackagingToolDemo 13 | /// 14 | /// @author SanjanaMahapatra 15 | 16 | public class PackagingToolIncubatorDemo implements IDemo { 17 | @Override 18 | public void demo() { 19 | info(343); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep362/SolarisSparcRemovalDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep362; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 362 - Deprecate the Solaris and SPARC Ports. 6 | /// 7 | /// 8 | /// Relates to: 9 | /// - JDK 15: [JEP 381 - Remove the Solaris and SPARC Ports](https://openjdk.org/jeps/381) 10 | /// 11 | /// Deprecate the Solaris/SPARC, Solaris/x64, and Linux/SPARC ports, with the intent to remove them in a future release. 12 | /// @see org.javademos.java15.jep381.SolarisSparcRemovalDemo 13 | /// 14 | /// @author SanjanaMahapatra 15 | 16 | public class SolarisSparcRemovalDemo implements IDemo { 17 | @Override 18 | public void demo() { 19 | info(362); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep409/SealedDemoBastard.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep409; 2 | 3 | /** 4 | * Simple class to show 'sealed class' concept from Java 17. 5 | * This class is not allowed, therefore it cannot extend from SealedDemoParent. 6 | * 7 | * @see SealedDemoParent 8 | * 9 | * @author alois.seckar@gmail.com 10 | */ 11 | 12 | // following two declarations are invalid: 13 | 14 | // class is not allowed to extend sealed class: SealedDemoParent (as it is not listed in its permits' clause) 15 | // public class SealedDemoBastard extends SealedDemoParent { 16 | 17 | // non-sealed modifier not allowed here 18 | // (class SealedDemoBastard does not have any sealed supertypes) 19 | // public non-sealed class SealedDemoBastard { 20 | 21 | public class SealedDemoBastard { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java13/jep354/SwitchExpressionsSecondPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java13.jep354; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 13 feature JEP 354 - Switch Expressions (Second Preview). 6 | /// 7 | /// This was the second preview of switch expressions. The main change from JEP 325 8 | /// was replacing the `break` statement with the new `yield` statement for returning 9 | /// values from switch expressions. 10 | /// 11 | /// The feature was finalized in JDK 14 by JEP 361. 12 | /// @see org.javademos.java12.jep325.SwitchExpressionsPreview 13 | /// @see org.javademos.java14.jep361.SwitchExpressionsDemo 14 | /// 15 | /// @author Abhineshhh 16 | public class SwitchExpressionsSecondPreview implements IDemo { 17 | @Override 18 | public void demo() { 19 | info(354); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep409/SealedDemoChild.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep409; 2 | 3 | /** 4 | * Simple class to show 'sealed class' concept from Java 17. 5 | * If class is declared in super-class' 'permits' section, 6 | * it MUST extend the parent (otherwise compiler error is raised in parent). 7 | * The class also MUST be either: 8 | * 'sealed' - with another 'permits' list 9 | * 'non-sealed' - all sub-classes allowed again 10 | * 'final' - standard Java way of disallowing further inheritance 11 | * 12 | * @see SealedDemoParent 13 | * 14 | * @author alois.seckar@gmail.com 15 | */ 16 | public final class SealedDemoChild extends SealedDemoParent { 17 | 18 | @Override 19 | public void foo() { 20 | super.foo(); 21 | System.out.println("Hello from child class"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep364/ZGarbageCollectorOnMacOS.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep364; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 364 - ZGC on macOS (Experimental). 6 | /// 7 | /// Depends on: 8 | /// - JDK 11: [JEP 333 - ZGC: A Scalable Low-Latency Garbage Collector (Experimental)](https://openjdk.org/jeps/333) 9 | /// 10 | /// Relates to: 11 | /// - JDK 15: [JEP 377 - ZGC: A Scalable Low-Latency Garbage Collector (Production)](https://openjdk.org/jeps/377) 12 | /// 13 | /// Port the ZGC garbage collector to macOS 14 | /// @see org.javademos.java15.jep377.ZGarbageCollectorDemo 15 | /// 16 | /// @author SanjanaMahapatra 17 | 18 | 19 | public class ZGarbageCollectorOnMacOS implements IDemo { 20 | @Override 21 | public void demo() { 22 | info(364); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep365/ZGarbageCollectorOnWindows.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep365; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 365 - ZGC on Windows (Experimental). 6 | /// 7 | /// Depends on: 8 | /// - JDK 11: [JEP 333 - ZGC: A Scalable Low-Latency Garbage Collector (Experimental)](https://openjdk.org/jeps/333) 9 | /// 10 | /// Relates to: 11 | /// - JDK 15: [JEP 377 - ZGC: A Scalable Low-Latency Garbage Collector (Production)](https://openjdk.org/jeps/377) 12 | /// 13 | /// Port the ZGC garbage collector to Windows 14 | /// @see org.javademos.java15.jep377.ZGarbageCollectorDemo 15 | /// 16 | /// @author SanjanaMahapatra 17 | 18 | public class ZGarbageCollectorOnWindows implements IDemo { 19 | @Override 20 | public void demo() { 21 | info(365); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java12/jep325/SwitchExpressionsPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java12.jep325; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 12 feature JEP 325 - Switch Expressions (Preview). 6 | /// 7 | /// This was the first preview of switch expressions, introducing the arrow label syntax 8 | /// and the ability to use switch as an expression. In this preview, values were returned 9 | /// using `break `, which was later changed to `yield ` in JEP 354. 10 | /// 11 | /// The feature was finalized in JDK 14 by JEP 361. 12 | /// @see org.javademos.java13.jep354.SwitchExpressionsSecondPreview 13 | /// @see org.javademos.java14.jep361.SwitchExpressionsDemo 14 | /// 15 | /// @author Abhineshhh 16 | public class SwitchExpressionsPreview implements IDemo { 17 | @Override 18 | public void demo() { 19 | info(325); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep443/UnnamedPatternsAndVariablesPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep443; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 feature JEP 443 - Unnamed Patterns and Variables (preview). 6 | /// 7 | /// **New version of this JEP exists: JEP 456 in JDK 22** 8 | /// This was the preview JEP for unnamed patterns and variables. The feature was 9 | /// finalized in JDK 22 by JEP 456. 10 | /// 11 | /// This demo is a placeholder. For the full implementation, see the final JEP. 12 | /// 13 | /// Superseded by [JEP 456](https://openjdk.org/jeps/456). 14 | /// @author [Krushit Babariya](https://github.com/Krushit-Babariya) 15 | /// @see org.javademos.java22.jep456.UnnamedVariablesAndPatternsDemo 16 | /// 17 | public class UnnamedPatternsAndVariablesPreview implements IDemo { 18 | 19 | @Override 20 | public void demo() { 21 | info(443); 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/j9/IJ9Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.j9; 2 | 3 | /** 4 | * Interface for private methods in interfaces feature from Java 9. 5 | * 6 | * @see J9Demo 7 | * 8 | * @author alois.seckar@gmail.com 9 | */ 10 | public interface IJ9Demo { 11 | 12 | /** 13 | * Method that HAS to be implemented. 14 | */ 15 | void foo(); 16 | 17 | /** 18 | * Default method (Java 8 feature) that CAN be re-implemented. 19 | */ 20 | default void stuff() { 21 | System.out.println("Public default method inside interface"); 22 | 23 | // split longer definitions into private methods 24 | privateStuff(); 25 | } 26 | 27 | // if you try this in Java < 9, compiler will throw: 28 | // "private interface methods are not supported in -source X" 29 | private void privateStuff() { 30 | System.out.println("Private method inside interface"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/j9/J9DemoAutoCloseable.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.j9; 2 | 3 | import org.javademos.Main; 4 | 5 | /** 6 | * Demo class for improved try-with-resources in Java 9. 7 | * 8 | * @see Main 9 | * 10 | * @author alois.seckar@gmail.com 11 | */ 12 | public class J9DemoAutoCloseable implements AutoCloseable { 13 | 14 | /** 15 | * Method that we would like to call before working with the resource. 16 | */ 17 | public void init() { 18 | System.out.println("Initializing internal state"); 19 | } 20 | 21 | /** 22 | * Here would be the actual load of work. 23 | */ 24 | public void doStuff() { 25 | System.out.println("Doing stuff with the resource"); 26 | } 27 | 28 | /** 29 | * This method ensures proper closing. 30 | */ 31 | @Override 32 | public void close() { 33 | System.out.println("Performing operations required to close the resource"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep423/RegionPinningForG1.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep423; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 423 - Region Pinning for G1. 6 | /// 7 | /// JEP history: 8 | /// - JDK 22: [JEP 423 - Region Pinning for G1](https://openjdk.org/jeps/423) 9 | /// 10 | /// Further reading: 11 | /// - [Understanding Region Pinning in G1 GC](https://www.kosmadunikowski.com/posts/understanding-region-pinning-in-g1-gc/) 12 | /// 13 | /// @author alois.seckar@gmail.com 14 | public class RegionPinningForG1 implements IDemo { 15 | @Override 16 | public void demo() { 17 | info(423); 18 | 19 | // performance improvement for G1 garbage collector 20 | // this update allows G1 to "pin" certain regions of JVM memory 21 | // related to JNI native operations 22 | // those regions are excluded from garbage collection process 23 | // but GC is not completely disabled as it was before 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java15/jep381/SolarisSparcRemovalDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java15.jep381; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// ## JEP 381: Remove the Solaris and SPARC Ports 6 | /// 7 | /// ### History 8 | /// Support for the Solaris operating system and SPARC processor architecture 9 | /// was costly to maintain and usage had declined significantly. This JEP 10 | /// removed the source code and build support for these platforms. 11 | /// 12 | /// ### Links 13 | /// - [Official JEP 381](https://openjdk.org/jeps/381) 14 | /// 15 | /// @since Java 15 16 | public class SolarisSparcRemovalDemo implements IDemo { 17 | 18 | @Override 19 | public void demo() { 20 | // Call info helper 21 | info(381); 22 | 23 | // This JEP removed platform support for Solaris/SPARC, Solaris/x64, and Linux/SPARC. 24 | // There are no Java APIs or language features associated with this change. 25 | // The primary outcome was a reduction in the JDK's codebase and maintenance effort. 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep388/WindowsPortDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep388; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// ## JEP 388: Windows/AArch64 Port 6 | /// 7 | /// ### History 8 | /// This JEP involved the significant engineering effort required to make the 9 | /// JDK (including the HotSpot JVM) run successfully on the Windows operating 10 | /// system when using ARM64 processors (AArch64 architecture). 11 | /// 12 | /// ### Links 13 | /// - [Official JEP 388](https://openjdk.org/jeps/388) 14 | /// 15 | /// @since Java 16 16 | public class WindowsPortDemo implements IDemo { 17 | 18 | 19 | @Override 20 | public void demo() { 21 | // Call info helper 22 | info(388); 23 | 24 | // This JEP was a porting effort to make the JDK runnable on Windows/AArch64. 25 | // It does not introduce new Java APIs or language features. 26 | // Therefore, there is no specific code to demonstrate its effects directly. 27 | // The main outcome is the availability of JDK builds for this platform. 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep518/JFRCooperativeSamplingDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep518; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 25 feature JEP 518 - JFR Cooperative Sampling. 6 | /// 7 | /// JEP history: 8 | /// - JDK 25: [JEP 518 - JFR Cooperative Sampling](https://openjdk.org/jeps/518) 9 | /// 10 | /// Further reading: 11 | /// - [JFR Cooperative Sampling overview](https://openjdk.org/jeps/518) 12 | /// 13 | /// @author Arjun Vijay Prakash @ArjunCodess 14 | public class JFRCooperativeSamplingDemo implements IDemo { 15 | 16 | @Override 17 | public void demo() { 18 | info(518); 19 | 20 | // explanation: 21 | // jep 518 introduces cooperative sampling for java flight recorder (jfr). 22 | // the jvm and java libraries participate in sampling decisions to reduce 23 | // safepoint bias and profiling overhead compared to timer-only sampling. 24 | // 25 | // this is a jvm/jfr runtime change; there is no public java se api call 26 | // to demonstrate here. to observe behavior, run a workload and capture 27 | // a jfr recording using tooling like `jcmd JFR.start` and analyze it. 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java19DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java19.jep405.RecordPatterns; 9 | import org.javademos.java19.jep422.LinuxRiscVPort; 10 | import org.javademos.java19.jep424.ForeignFunctionMemoryDemo; 11 | import org.javademos.java19.jep425.VirtualThreads; 12 | import org.javademos.java19.jep426.VectorAPIDemo; 13 | import org.javademos.java19.jep427.PatternMatchingForSwitchThirdPreview; 14 | import org.javademos.java19.jep428.StructuredConcurrencyDemo; 15 | 16 | /** 17 | * Loads demos for Java 19. 18 | */ 19 | public class Java19DemoLoader implements IDemoLoader { 20 | 21 | @Override 22 | public void loadDemos(Map demos) { 23 | demos.put(405, new RecordPatterns()); 24 | demos.put(422, new LinuxRiscVPort()); 25 | demos.put(424, new ForeignFunctionMemoryDemo()); 26 | demos.put(425, new VirtualThreads()); 27 | demos.put(426, new VectorAPIDemo()); 28 | demos.put(427, new PatternMatchingForSwitchThirdPreview()); 29 | demos.put(428, new StructuredConcurrencyDemo()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java20DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java20.jep429.ScopedValuesDemo; 9 | import org.javademos.java20.jep432.RecordPatterns; 10 | import org.javademos.java20.jep433.PatternMatchingForSwitchFourthPreview; 11 | import org.javademos.java20.jep434.ForeignFunctionMemoryDemo; 12 | import org.javademos.java20.jep436.VirtualThreads; 13 | import org.javademos.java20.jep437.StructuredConcurrencyDemo; 14 | import org.javademos.java20.jep438.VectorAPIDemo; 15 | 16 | /** 17 | * Loads demos for Java 20. 18 | */ 19 | public class Java20DemoLoader implements IDemoLoader { 20 | 21 | @Override 22 | public void loadDemos(Map demos) { 23 | demos.put(429, new ScopedValuesDemo()); 24 | demos.put(432, new RecordPatterns()); 25 | demos.put(433, new PatternMatchingForSwitchFourthPreview()); 26 | demos.put(434, new ForeignFunctionMemoryDemo()); 27 | demos.put(436, new VirtualThreads()); 28 | demos.put(437, new StructuredConcurrencyDemo()); 29 | demos.put(438, new VectorAPIDemo()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java15/jep372/NashornRemovalDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java15.jep372; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// ## JEP 372: Remove the Nashorn JavaScript Engine 6 | /// 7 | /// ### History 8 | /// Nashorn was introduced in Java 8 (JEP 174) as a replacement for the older 9 | /// Rhino engine. However, with the rapid evolution of ECMAScript (JavaScript), 10 | /// maintaining Nashorn became difficult. It was deprecated in Java 11 (JEP 335) 11 | /// and removed entirely by this JEP. 12 | /// 13 | /// ### Links 14 | /// - [Official JEP 372](https://openjdk.org/jeps/372) 15 | /// 16 | /// @since Java 15 17 | public class NashornRemovalDemo implements IDemo { 18 | 19 | @Override 20 | public void demo() { 21 | // Call info helper 22 | info(372); 23 | 24 | // This JEP removed the Nashorn JavaScript engine, APIs, and the jjs tool. 25 | // There are no specific APIs or language features to demonstrate its absence. 26 | // Trying to import or use classes from the jdk.nashorn package would now 27 | // result in a compilation error. For example: 28 | // import jdk.nashorn.api.scripting.NashornScriptEngineFactory; // This import fails in JDK 15+ 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep501/Deprecate32BitX86Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep501; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 change **Deprecate the 32-bit x86 Port for Removal** (JEP 501) 6 | /// 7 | /// ### JEP history 8 | /// - JDK 21: [JEP 449 - Deprecate the 32-bit x86 Windows Port for Removal](https://openjdk.org/jeps/449) 9 | /// - JDK 24: [JEP 479 - Remove the 32-bit x86 Windows Port](https://openjdk.org/jeps/479) 10 | /// - JDK 24: [JEP 501 - Deprecate the 32-bit x86 Port for Removal](https://openjdk.org/jeps/501) 11 | /// - JDK 25: [JEP 503 - Remove the 32-bit x86 Port](https://openjdk.org/jeps/503) 12 | /// 13 | /// ### Key points 14 | /// - JDK 24 marked the **entire 32-bit x86 port** as deprecated. 15 | /// - This was a warning for developers that support would end soon. 16 | /// - The actual removal happened in JDK 25 (JEP 503). 17 | /// 18 | /// Replaced with most recent [JEP 503 - Remove the 32-bit x86 Port](https://openjdk.org/jeps/503) 19 | /// @see org.javademos.java25.jep503.Remove32BitX86Demo 20 | /// 21 | /// @author adeelFeroz77 22 | 23 | public class Deprecate32BitX86Demo implements IDemo { 24 | 25 | @Override 26 | public void demo() { 27 | info(501); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep479/RemovedWindows32BitX86Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep479; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 change **Remove the 32-bit x86 Windows Port** (JEP 479) 6 | /// 7 | /// ### JEP history 8 | /// - JDK 21: [JEP 449 - Deprecate the 32-bit x86 Windows Port for Removal](https://openjdk.org/jeps/449) 9 | /// - JDK 24: [JEP 479 - Remove the 32-bit x86 Windows Port](https://openjdk.org/jeps/479) 10 | /// - JDK 24: [JEP 501 - Deprecate the 32-bit x86 Port for Removal](https://openjdk.org/jeps/501) 11 | /// - JDK 25: [JEP 503 - Remove the 32-bit x86 Port](https://openjdk.org/jeps/503) 12 | /// 13 | /// ### Key points 14 | /// - JDK 24 removed **Windows-only 32-bit x86 port**. 15 | /// - 32-bit x86 builds for Linux/other OSes were still available. 16 | /// - This was an intermediate step before the full removal in JDK 25 (JEP 503). 17 | /// 18 | /// Replaced with most recent [JEP 503 - Remove the 32-bit x86 Port](https://openjdk.org/jeps/503) 19 | /// @see org.javademos.java25.jep503.Remove32BitX86Demo 20 | /// 21 | /// @author adeelFeroz77 22 | 23 | public class RemovedWindows32BitX86Demo implements IDemo { 24 | 25 | @Override 26 | public void demo() { 27 | info(479); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep449/DeprecateWindows32BitX86Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep449; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 change **Deprecate the 32-bit x86 Windows Port for Removal** (JEP 449) 6 | /// 7 | /// ### JEP history 8 | /// - JDK 21: [JEP 449 - Deprecate the 32-bit x86 Windows Port for Removal](https://openjdk.org/jeps/449) 9 | /// - JDK 24: [JEP 479 - Remove the 32-bit x86 Windows Port](https://openjdk.org/jeps/479) 10 | /// - JDK 24: [JEP 501 - Deprecate the 32-bit x86 Port for Removal](https://openjdk.org/jeps/501) 11 | /// - JDK 25: [JEP 503 - Remove the 32-bit x86 Port](https://openjdk.org/jeps/503) 12 | /// 13 | /// ### Key points 14 | /// - JDK 21 did **not** remove the Windows 32-bit x86 port. 15 | /// - It was only **deprecated**, meaning developers were warned about future removal. 16 | /// - This was the first formal signal that the port was going away. 17 | /// 18 | /// Replaced with most recent [JEP 503 - Remove the 32-bit x86 Port](https://openjdk.org/jeps/503) 19 | /// @see org.javademos.java25.jep503.Remove32BitX86Demo 20 | /// 21 | /// @author adeelFeroz77 22 | 23 | public class DeprecateWindows32BitX86Demo implements IDemo { 24 | 25 | @Override 26 | public void demo() { 27 | info(449); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep470/PemEncodingsDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep470; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 25 feature JEP 470 - PEM Encodings of Cryptographic Objects (Preview). 6 | /// 7 | /// JEP history: 8 | /// - JDK 25 (preview): [JEP 470 - PEM Encodings of Cryptographic Objects](https://openjdk.org/jeps/470) 9 | /// 10 | /// Further reading: 11 | /// - [JEP 470](https://openjdk.org/jeps/470) 12 | /// 13 | /// NOTE: this is a preview feature; run with --enable-preview 14 | /// 15 | /// @author Arjun Vijay Prakash @ArjunCodess 16 | public class PemEncodingsDemo implements IDemo { 17 | @Override 18 | public void demo() { 19 | info(470); 20 | 21 | // todo: consider adding a real pem encode/decode sample using jdk 25 preview apis 22 | 23 | // the actual crypto apis for pem encoding/decoding are part of the preview jdk 25 api surface. 24 | // to keep this demo portable across environments and jdks, we only print guidance here. 25 | System.out.println("this demo illustrates the new pem encoding/decoding support introduced in jdk 25 (preview)."); 26 | System.out.println("to try it, use jdk 25 with --enable-preview and the new pem apis in java.security to read/write keys and certs."); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep398/DeprecateAppletApiForRemovalDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep398; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 398 - Deprecate the Applet API for Removal. 6 | /// 7 | /// JEP history: 8 | /// - JDK 17: [JEP 398 - Deprecate the Applet API for Removal](https://openjdk.org/jeps/398) 9 | /// - JDK 9: [JEP 289 - Deprecate the Applet API](https://openjdk.org/jeps/289) (Initial step) 10 | /// 11 | /// Further reading: 12 | /// - [Java applet - wiki page](https://en.wikipedia.org/wiki/Java_applet) 13 | /// 14 | /// @author Alexander Schneider @ab-schneider 15 | public class DeprecateAppletApiForRemovalDemo implements IDemo { 16 | @Override 17 | public void demo() { 18 | info(398); 19 | 20 | // The Applet API (java.applet.Applet) existed to run Java code inside browsers via the NPAPI plug-in. 21 | // As all major browsers removed NPAPI (Chrome 2015, Firefox 2017, Edge never), 22 | // the API became unusable: deprecated in JDK 9 (JEP 289), marked for removal in JDK 17 (JEP 398), 23 | // and removed in JDK 26 (JEP 504). 24 | // 25 | // In case remaining uses of these APIs do exist, developers can suppress compiler warnings 26 | // via the @SuppressWarnings("removal") annotation or the -Xlint:-removal command-line option of the javac compiler. 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep493/LinkingRunTimeImages493.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep493; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 493 - Linking Run-Time Images without JMODs. 6 | /// 7 | /// JEP history: 8 | /// - JDK 24: [JEP 493 - Linking Run-Time Images without JMODs](https://openjdk.org/jeps/493) 9 | /// 10 | /// Further reading: 11 | /// - [Inside Java: JEP 493 Overview](https://openjdk.org/jeps/493) 12 | /// 13 | /// @author shepherdking67 14 | public class LinkingRunTimeImages493 implements IDemo { 15 | 16 | @Override 17 | public void demo() { 18 | info(493); 19 | 20 | // JEP 493 enhances the jlink tool to allow linking run-time images 21 | // without requiring JMOD files. Previously, jlink depended on JMODs 22 | // shipped with the JDK, but now it can directly consume the class and 23 | // resource files from the JDK installation. 24 | // 25 | // Why this matters: 26 | // - Simplifies creation of custom JDK runtime images. 27 | // - Removes dependency on JMOD packaging. 28 | // - Makes jlink usage more flexible and straightforward. 29 | // 30 | // Example (shell, not Java code): 31 | // jlink --add-modules java.base --output myimage 32 | // 33 | // The above works even if JMOD files are not present in the JDK. 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep486/DisableSecurityManager.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep486; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 486 - Permanently Disable the Security Manager. 6 | /// 7 | /// JEP history: 8 | /// - JDK 24: [JEP 486 - Permanently Disable the Security Manager](https://openjdk.org/jeps/486) 9 | /// 10 | /// Further reading: 11 | /// - [JEP 411 (Deprecate the Security Manager)](https://openjdk.org/jeps/411) 12 | /// - [JEP 486 - Details](https://openjdk.org/jeps/486) 13 | /// 14 | /// @author shepherdking67 15 | @SuppressWarnings({"removal"}) // comment out to see warnings 16 | public class DisableSecurityManager implements IDemo { 17 | 18 | @Override 19 | public void demo() { 20 | // JEP reference info 21 | info(486); 22 | 23 | // The Security Manager was deprecated for removal in earlier releases 24 | // and is now permanently disabled as of JDK 24. 25 | // 26 | // Any attempt to call System.setSecurityManager(...) results in an 27 | // UnsupportedOperationException. 28 | try { 29 | // deprecated in JDK 17,removed in JDK 24+ 30 | // this code will intentionally throw an exception 31 | System.setSecurityManager(new SecurityManager()); 32 | } catch (UnsupportedOperationException e) { 33 | System.out.println("SecurityManager is permanently disabled: " + e); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java15/jep373/DatagramSocketDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java15.jep373; 2 | 3 | import org.javademos.commons.IDemo; 4 | import java.net.DatagramPacket; 5 | import java.net.DatagramSocket; 6 | import java.net.InetAddress; 7 | 8 | /// Demo for JDK 15 feature JEP 373 - Reimplement the Legacy DatagramSocket API. 9 | /// 10 | /// This JEP modernized the implementation of the legacy DatagramSocket 11 | /// and DatagramSocketImpl APIs without changing their behavior. 12 | /// The reimplementation uses java.nio infrastructure under the hood, 13 | /// improving maintainability and performance. 14 | /// 15 | /// JEP link: 16 | /// - [JEP 373 - Reimplement the Legacy DatagramSocket API](https://openjdk.org/jeps/373) 17 | /// 18 | /// 19 | /// @author sayiamarora 20 | public class DatagramSocketDemo implements IDemo { 21 | 22 | @Override 23 | public void demo() { 24 | info(373); 25 | 26 | try (DatagramSocket socket = new DatagramSocket()) { 27 | String message = "Hello from JEP 373!"; 28 | byte[] buffer = message.getBytes(); 29 | 30 | InetAddress address = InetAddress.getLocalHost(); 31 | DatagramPacket packet = new DatagramPacket(buffer, buffer.length, address, 9999); 32 | socket.send(packet); 33 | 34 | System.out.println("Datagram sent successfully using reimplemented API!"); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java18DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java18.jep400.DefaultUTF8Demo; 9 | import org.javademos.java18.jep408.SimpleWebServerDemo; 10 | import org.javademos.java18.jep413.CodeSnippetsInJavadoc; 11 | import org.javademos.java18.jep416.CoreReflectionWithMethodHandles; 12 | import org.javademos.java18.jep417.VectorAPIDemo; 13 | import org.javademos.java18.jep418.InternetAddressResolutionSPI; 14 | import org.javademos.java18.jep419.ForeignFunctionMemoryDemo; 15 | import org.javademos.java18.jep420.PatternMatchingForSwitchSecondPreview; 16 | import org.javademos.java18.jep421.DeprecateFinalization; 17 | /** 18 | * Loads demos for Java 18. 19 | */ 20 | public class Java18DemoLoader implements IDemoLoader { 21 | 22 | @Override 23 | public void loadDemos(Map demos) { 24 | demos.put(400, new DefaultUTF8Demo()); 25 | demos.put(408, new SimpleWebServerDemo()); 26 | demos.put(413, new CodeSnippetsInJavadoc()); 27 | demos.put(416, new CoreReflectionWithMethodHandles()); 28 | demos.put(417, new VectorAPIDemo()); 29 | demos.put(418, new InternetAddressResolutionSPI()); 30 | demos.put(419, new ForeignFunctionMemoryDemo()); 31 | demos.put(420, new PatternMatchingForSwitchSecondPreview()); 32 | demos.put(421, new DeprecateFinalization()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java18/jep400/DefaultUTF8Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java18.jep400; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.nio.charset.Charset; 9 | 10 | /// Demo for JDK 18 feature JEP 400 - UTF-8 by Default. 11 | /// 12 | /// JEP history: 13 | /// - JDK 18: [JEP 400 - UTF-8 by Default (Preview)](https://openjdk.org/jeps/400) 14 | /// 15 | /// @author biswarup.chatterjee@tuta.io 16 | public class DefaultUTF8Demo implements IDemo { 17 | @Override 18 | public void demo() { 19 | info(400); 20 | 21 | System.out.println("Default charset: " + Charset.defaultCharset()); 22 | 23 | String text = "Hello, 世界 🌍"; 24 | 25 | // Write a file without specifying charset 26 | try (FileWriter writer = new FileWriter("./tmp/demo.txt")) { 27 | writer.write(text); 28 | } catch (IOException e) { 29 | throw new RuntimeException(e); 30 | } 31 | 32 | // Read the same file without specifying charset 33 | try (FileReader reader = new FileReader("./tmp/demo.txt")) { 34 | char[] buffer = new char[100]; 35 | int len = reader.read(buffer); 36 | String readText = new String(buffer, 0, len); 37 | System.out.println("Read text: " + readText); 38 | } 39 | catch (IOException e) { 40 | throw new RuntimeException(e); 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep509/CpuTimeProfilingDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep509; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | import jdk.jfr.Recording; 6 | import jdk.jfr.Configuration; 7 | import java.nio.file.Path; 8 | 9 | /// Demo for JDK 25 feature JEP 509 - JFR CPU-Time Profiling. 10 | /// 11 | /// JEP history: 12 | /// - JDK 25: JEP 509 - JFR CPU-Time Profiling (Experimental) 13 | /// 14 | /// Further reading: 15 | /// - https://openjdk.org/jeps/509 16 | /// 17 | /// Author: @adityamep 18 | 19 | public class CpuTimeProfilingDemo implements IDemo { 20 | 21 | @Override 22 | public void demo() { 23 | info(509); 24 | 25 | System.out.println("Starting JFR CPU-Time Profiling demo..."); 26 | 27 | try (Recording recording = new Recording(Configuration.getConfiguration("profile"))) { 28 | recording.setToDisk(true); 29 | recording.setDestination(Path.of("./tmp/cpu-profile.jfr")); 30 | recording.start(); 31 | 32 | // CPU-intensive workload 33 | for (int i = 0; i < 5; i++) { 34 | fibonacci(35); 35 | } 36 | 37 | recording.stop(); 38 | System.out.println("Recording finished. File 'tmp/cpu-profile.jfr' generated."); 39 | } catch (Exception e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | 44 | private long fibonacci(int n) { 45 | if (n <= 1) return n; 46 | return fibonacci(n - 1) + fibonacci(n - 2); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /.github/workflows/pr-build-check.yaml: -------------------------------------------------------------------------------- 1 | name: PR build check (Compile against Java 25 using Maven) 2 | 3 | on: 4 | pull_request: 5 | types: [opened, synchronize, reopened] 6 | 7 | permissions: 8 | contents: read 9 | 10 | concurrency: 11 | group: pr-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | build: 16 | name: build 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v4 22 | 23 | - name: Set up Java 25 (GraalVM) 24 | uses: actions/setup-java@v4 25 | with: 26 | distribution: 'graalvm' 27 | java-version: '25' 28 | cache: maven 29 | 30 | - name: Maven clean install (compile only) 31 | run: mvn -B -ntp -DskipTests clean install 32 | 33 | - name: Test run (fail on runtime exceptions) 34 | id: demo-run 35 | shell: bash 36 | run: | 37 | set -euo pipefail 38 | mkdir -p tmp 39 | export JAVA_TOOL_OPTIONS="-Djava.io.tmpdir=$(pwd)/tmp" 40 | 41 | java --enable-preview --add-modules=jdk.incubator.vector \ 42 | -jar target/JavaDemos-25.0.jar > run.log 2>&1 || { 43 | echo "Non-zero exit code:" 44 | cat run.log 45 | exit 1 46 | } 47 | 48 | - name: Upload run.log on runtime failure 49 | if: steps.demo-run.outcome == 'failure' 50 | uses: actions/upload-artifact@v4 51 | with: 52 | name: run-log 53 | path: run.log 54 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep471/DeprecateMemoryAccessMethods.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep471; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 471 - Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal. 6 | /// 7 | /// JEP history: 8 | /// - JDK 23: [JEP 471 - Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal](https://openjdk.org/jeps/471) 9 | /// 10 | /// Further reading: 11 | /// - [Embracing Safer Memory Access with JEP 471](https://foojay.io/today/unsafe-is-finally-going-away-embracing-safer-memory-access-with-jep-471/) 12 | /// 13 | /// @see sun.misc.Unsafe 14 | /// @author alois.seckar@gmail.com 15 | public class DeprecateMemoryAccessMethods implements IDemo { 16 | @Override 17 | public void demo() { 18 | info(471); 19 | 20 | // methods from sun.misc.Unsafe class are now annotated 21 | // @Deprecated(since="23", forRemoval=true) 22 | // this means they are about to be removed in the upcoming versions of JDK 23 | // the process of removing will continue over next few releases 24 | 25 | // the reason behind the removal is to avoid risks resulting from incorrect usage of provided methods 26 | // potential problems include: 27 | // - memory leaks 28 | // - invalid memory access crashes 29 | // - buffer overflow security flaws 30 | 31 | // safer alternatives provided 32 | // JEP 193: Variable Handles (JDK 9) 33 | // JEP 454: Foreign Function & Memory API (JDK 22) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep467/MarkdownComments.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep467; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// # Demo for JDK 23 feature JEP 467 - Markdown Documentation Comments 6 | /// 7 | /// ## JEP history 8 | /// - JDK 23: [JEP 467 - Markdown Documentation Comments](https://openjdk.org/jeps/467) 9 | /// 10 | /// ## Further reading 11 | /// - [Java Enhances Documentation with Markdown Support](https://www.infoq.com/news/2024/05/jep467-markdown-in-javadoc/) 12 | /// 13 | /// @author alois.seckar@gmail.com 14 | 15 | @SuppressWarnings("DanglingJavadoc") // because of the examples 16 | public class MarkdownComments implements IDemo { 17 | @Override 18 | public void demo() { 19 | info(467); 20 | } 21 | 22 | // Markdown syntax is now possible in Javadoc comments 23 | // It has to be started with different prefix - /// instead of /** 24 | 25 | // BEFORE JDK 23 - Javadoc header 26 | 27 | /** 28 | *

29 | * Demo for JDK 23 feature JEP 467 - Markdown Documentation Comments 30 | *

31 | */ 32 | 33 | // AFTER JDK 23 - Javadoc header 34 | 35 | /// # Demo for JDK 23 feature **JEP 467 - Markdown Documentation Comments** 36 | 37 | // ISSUES / LIMITATIONS 38 | 39 | // @see and external links 40 | // ----------------------- 41 | // /// @see [JEP 467](https://openjdk.org/jeps/467) 42 | // md syntax is currently not possible 43 | // /// @see JEP 467 44 | // html tag renders fine... 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep490/ZgcNonGenerationalModeRemoval.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep490; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JEP 490: **ZGC: Remove the Non-Generational Mode** 6 | /// 7 | /// JEP history: 8 | /// - JDK 21: [JEP 439 - Generational ZGC](https://openjdk.org/jeps/439) 9 | /// - JDK 23: [JEP 474 - ZGC: Generational Mode by Default](https://openjdk.org/jeps/474) 10 | /// - JDK 24: [JEP 490 - ZGC: Remove the Non-Generational Mode](https://openjdk.org/jeps/490) 11 | /// 12 | /// @author dhruv-git-sys 13 | public class ZgcNonGenerationalModeRemoval implements IDemo { 14 | 15 | @Override 16 | public void demo() { 17 | info(490); 18 | 19 | /* 20 | * This JEP concerns a change in JVM options and internal GC behavior. Such a change 21 | * cannot be demonstrated with code running inside the main demo runner. Instead, 22 | * its effects must be observed by running the JVM with specific command-line flags. 23 | * 24 | * --- 25 | * ✅ How to Verify This Change 26 | * --- 27 | * 28 | * 1. Create any simple Java application (e.g., a "Hello, World"). 29 | * 30 | * 2. Run it from your terminal using the now-obsolete flag to disable generational mode: 31 | * >> java -XX:+UseZGC -XX:-ZGenerational YourApp.java 32 | * 33 | * 3. Observe the console output. You will see a WARNING MESSAGE from the JVM, 34 | * confirming the flag is obsolete and the non-generational mode is gone. 35 | */ 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep356/RandomGeneratorsDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep356; 2 | 3 | import org.javademos.commons.IDemo; 4 | import java.util.random.RandomGenerator; 5 | import java.util.random.RandomGeneratorFactory; 6 | import java.util.random.RandomGenerator.JumpableGenerator; 7 | 8 | /// Demo for JDK 17 feature JEP 356 - Enhanced Pseudo-Random Number Generators. 9 | /// 10 | /// Introduced new interfaces to improve random number generation: 11 | /// - `RandomGenerator` and `RandomGeneratorFactory` 12 | /// - Support for LXM family generators (`L32X64Mix`, `L64X128Mix`) 13 | /// - Added streamable and jumpable generators for parallel computation. 14 | /// 15 | /// JEP link: 16 | /// - [JEP 356 - Enhanced Pseudo-Random Number Generators](https://openjdk.org/jeps/356) 17 | /// 18 | /// Further reading: 19 | /// - [Baeldung: Enhanced Pseudo-Random Number Generators in Java 17](https://www.baeldung.com/java-17-random-number-generators) 20 | /// 21 | /// @author alois.seckar@gmail.com 22 | public class RandomGeneratorsDemo implements IDemo { 23 | 24 | @Override 25 | public void demo() { 26 | info(356); 27 | 28 | RandomGenerator generator = RandomGenerator.getDefault(); 29 | System.out.println("Default Random Int: " + generator.nextInt()); 30 | System.out.println("Default Random Double: " + generator.nextDouble()); 31 | 32 | JumpableGenerator jumpable = 33 | (JumpableGenerator) RandomGeneratorFactory.of("Xoshiro256PlusPlus").create(); 34 | System.out.println("Jumpable Random Int: " + jumpable.nextInt()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep458/LaunchMultiFileSourceDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep458; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 458 - Launch Multi-File Source-Code Programs. 6 | /// 7 | /// JEP history: 8 | /// - JDK 22: [JEP 458 - Launch Multi-File Source-Code Programs](https://openjdk.org/jeps/458) 9 | /// 10 | /// Further reading: 11 | /// - [Introducing Multi-File Program Launching](https://www.infoq.com/news/2024/02/multi-file-program-launching/) 12 | /// 13 | /// @author kishansingh956196@gmail.com 14 | public class LaunchMultiFileSourceDemo implements IDemo { 15 | @Override 16 | public void demo() { 17 | info(458); 18 | 19 | // Demonstrable feature: You can run multiple source files directly without compilation. 20 | // Example (requires separate files in the same directory): 21 | // java Main.java Helper.java 22 | // 23 | // // Main.java 24 | // public class Main { 25 | // public static void main(String[] args) { 26 | // Helper.greet(); 27 | // } 28 | // } 29 | // 30 | // // Helper.java 31 | // public class Helper { 32 | // public static void greet() { 33 | // System.out.println("Hello from Helper!"); 34 | // } 35 | // } 36 | // 37 | // When running `java Main.java`, both classes will be compiled and executed out of the box. 38 | // 39 | // Try it by running: 40 | // - java src/main/resources/jep458/Main.java 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java15DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java15.jep339.EdDSADemo; 9 | import org.javademos.java15.jep360.SealedClassesDemo; 10 | import org.javademos.java15.jep371.HiddenClassesDemo; 11 | import org.javademos.java15.jep372.NashornRemovalDemo; 12 | import org.javademos.java15.jep373.DatagramSocketDemo; 13 | import org.javademos.java15.jep375.InstanceofPatternMatchingSecondPreview; 14 | import org.javademos.java15.jep377.ZGarbageCollectorDemo; 15 | import org.javademos.java15.jep378.TextBlockDemo; 16 | import org.javademos.java15.jep381.SolarisSparcRemovalDemo; 17 | import org.javademos.java15.jep383.ForeignMemoryAccessDemo; 18 | import org.javademos.java15.jep384.RecordsSecondPreviewDemo; 19 | 20 | /** 21 | * Loads demos for Java 15. 22 | */ 23 | public class Java15DemoLoader implements IDemoLoader { 24 | 25 | @Override 26 | public void loadDemos(Map demos) { 27 | demos.put(339, new EdDSADemo()); 28 | demos.put(360, new SealedClassesDemo()); 29 | demos.put(371, new HiddenClassesDemo()); 30 | demos.put(372, new NashornRemovalDemo()); 31 | demos.put(373, new DatagramSocketDemo()); 32 | demos.put(375, new InstanceofPatternMatchingSecondPreview()); 33 | demos.put(377, new ZGarbageCollectorDemo()); 34 | demos.put(378, new TextBlockDemo()); 35 | demos.put(381, new SolarisSparcRemovalDemo()); 36 | demos.put(383, new ForeignMemoryAccessDemo()); 37 | demos.put(384, new RecordsSecondPreviewDemo()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep390/ValueBasedClassesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep390; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// ## JEP 390: Warnings for Value-Based Classes 6 | /// 7 | /// ### History 8 | /// Primitive wrapper classes (like Integer, Double) are now designated as 9 | /// "value-based". This JEP adds new warnings when you try to use them in 10 | /// ways that are not intended, like synchronizing on them. 11 | /// 12 | /// ### Links 13 | /// - [Official JEP 390](https://openjdk.org/jeps/390) 14 | /// 15 | /// @since Java 16 16 | public class ValueBasedClassesDemo implements IDemo { 17 | 18 | @Override 19 | @SuppressWarnings("synchronization") // This is needed for mvn clean install to pass 20 | public void demo() { 21 | // Call the info helper 22 | info(390); 23 | 24 | // The Demo 25 | // This is the code that demonstrates the feature. 26 | // We create an Integer (a value-based class). 27 | Integer myLock = 10; 28 | 29 | System.out.println("Attempting to synchronize on an instance of Integer..."); 30 | System.out.println("Compiling this file without '@SuppressWarnings' would produce a warning:"); 31 | System.out.println("\"synchronization on instance of a value-based class\""); 32 | 33 | // This 'synchronized' block IS the demo. 34 | // It will compile, but the compiler warns against this practice. 35 | synchronized (myLock) { 36 | // This code is now flagged by the compiler as a bad practice. 37 | System.out.println("This code block is inside a synchronized block on an Integer."); 38 | } 39 | System.out.println("Demo complete."); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep459/StringTemplatesSecondPreview.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep459; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 22 feature JEP 459 - String Templates (Second Preview). 6 | /// # JEP 459: String Templates (Second Preview) 7 | 8 | /// This JEP provided a second preview of String Templates, a feature designed to simplify string 9 | /// composition in Java. It followed the first preview in JEP 430 (JDK 21). 10 | /// 11 | /// ## IMPORTANT NOTE 12 | /// String Templates were a preview feature in JDK 21 and 22 but were **REMOVED** from the language 13 | /// in JDK 23. They do not exist in JDK 23 or later. This demo is for historical and educational 14 | /// purposes only. 15 | /// 16 | /// JEP history: 17 | /// - [JEP 459: String Templates (Second Preview)](https://openjdk.org/jeps/459) 18 | /// - [JEP 430: String Templates (Preview)](https://openjdk.org/jeps/430) 19 | /// 20 | /// @author mayankvyas1306 21 | public class StringTemplatesSecondPreview implements IDemo { 22 | 23 | @Override 24 | public void demo() { 25 | info(459); 26 | 27 | // IMPORTANT: This feature was a preview in JDK 21/22 and was REMOVED in JDK 23. 28 | // The following information is for historical and educational purposes only. 29 | 30 | // The feature introduced processors (e.g., STR) to embed expressions into strings. 31 | 32 | // // Example from the preview (this code will not compile): 33 | // // int value = 10; 34 | // // String s = STR."The result is \\{value}"; 35 | // // This would have produced the string: "The result is 10" 36 | 37 | // The goal was to create safer, more readable strings than using simple '+' concatenation. 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/resources/JDK19Info.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "jep": 405, 4 | "jdk": 19, 5 | "name": "JEP 405 - Record Patterns (Preview)", 6 | "dscr": "Up-to-date demo in `org.javademos.java21.jep440.RecordPatternsDemo`.", 7 | "link": true, 8 | "code": false 9 | }, 10 | { 11 | "jep": 422, 12 | "jdk": 19, 13 | "name": "JEP 422 – Linux/RISC-V Port", 14 | "dscr": "No executable code, see `LinuxRiscVPort.java` for further info.", 15 | "link": false, 16 | "code": false 17 | }, 18 | { 19 | "jep": 424, 20 | "jdk": 19, 21 | "name": "JEP 424 - Foreign Function & Memory API (Preview)", 22 | "dscr": "Up-to-date demo in `org.javademos.java22.jep454.ForeignFunctionMemoryDemo`.", 23 | "link": true, 24 | "code": false 25 | }, 26 | { 27 | "jep": 425, 28 | "jdk": 19, 29 | "name": "JEP 425 - Virtual Threads (Preview)", 30 | "dscr": "Up-to-date demo in `org.javademos.java21.jep444.VirtualThreadsDemo`.", 31 | "link": true, 32 | "code": false 33 | }, 34 | { 35 | "jep": 426, 36 | "jdk": 19, 37 | "name": "JEP 426 - Vector API (Fourth Incubator)", 38 | "dscr": "Up-to-date demo in `org.javademos.java25.jep508.VectorAPIDemo`.", 39 | "link": true, 40 | "code": false 41 | }, 42 | { 43 | "jep": 427, 44 | "jdk": 19, 45 | "name": "JEP 427 - Pattern Matching for switch (Third Preview)", 46 | "dscr": "Up-to-date demo in `org.javademos.java21.jep441.PatternMatchingForSwitchDemo`.", 47 | "link": true, 48 | "code": false 49 | }, 50 | { 51 | "jep": 428, 52 | "jdk": 19, 53 | "name": "JEP 428 - Structured Concurrency (Incubator)", 54 | "dscr": "Up-to-date demo in `org.javademos.java25.jep505.StructuredConcurrencyDemo`.", 55 | "link": true, 56 | "code": false 57 | } 58 | ] -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep498/MemoryAccessMethods.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep498; 2 | 3 | import org.javademos.commons.IDemo; 4 | import sun.misc.Unsafe; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | /// Demo for JDK 24 feature JEP 498 - Warn upon Use of Memory-Access Methods in sun.misc.Unsafe. 9 | /// 10 | /// ### JEP history 11 | /// - JDK 24: [JEP 498 - Warn upon Use of Memory-Access Methods in sun.misc.Unsafe](https://openjdk.org/jeps/498) 12 | /// 13 | /// ### Further reading 14 | /// - [JEP 498 - Warn upon Use of Memory-Access Methods in sun.misc.Unsafe](https://openjdk.org/jeps/498) 15 | /// 16 | /// @see sun.misc.Unsafe 17 | /// 18 | /// @author @adeelFeroz77 19 | @SuppressWarnings({"removal"}) // comment out to see warnings 20 | public class MemoryAccessMethods implements IDemo { 21 | 22 | @Override 23 | public void demo() { 24 | info(498); 25 | 26 | try { 27 | // note methods `allocateMemory`, `putInt`, `getInt`, and `freeMemory` 28 | // are deprecated and marked for removal 29 | 30 | // theUnsafe is static singleton defined inside Unsafe class 31 | Field f = Unsafe.class.getDeclaredField("theUnsafe"); 32 | f.setAccessible(true); 33 | Unsafe unsafe = (Unsafe) f.get(null); 34 | 35 | // allocating some bytes 36 | long memoryAddress = unsafe.allocateMemory(4); 37 | unsafe.putInt(memoryAddress, 42); 38 | 39 | int value = unsafe.getInt(memoryAddress); 40 | 41 | System.out.println("Value read from Unsafe memory: " + value); 42 | 43 | unsafe.freeMemory(memoryAddress); 44 | 45 | } catch (Exception e) { 46 | System.err.println("Unsafe access failed: " + e.getMessage()); 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java19/jep422/LinuxRiscVPort.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java19.jep422; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 19 feature JEP 422 - Linux/RISC-V Port. 6 | /// 7 | /// JEP history: 8 | /// - JDK 19: [JEP 422 - Linux/RISC-V Port](https://openjdk.org/jeps/422) 9 | /// 10 | /// Further reading: 11 | /// - [OpenJDK RISC-V Port Project](https://openjdk.org/projects/riscv/) 12 | /// 13 | /// @author biswarup.chatterjee@tuta.io 14 | public class LinuxRiscVPort implements IDemo { 15 | @Override 16 | public void demo() { 17 | info(422); 18 | // This JEP ports the JDK to Linux running on the RISC-V architecture — a 19 | // free and open instruction set architecture (ISA) that is seeing rapid adoption 20 | // in both academic and industrial contexts. 21 | // 22 | // The goal is to make the Java Platform run efficiently on RISC-V systems 23 | // without introducing new language features or APIs, ensuring Java applications 24 | // can execute unmodified on RISC-V hardware. 25 | // JEP 422 delivers a port of the JDK to Linux on the RISC-V architecture. 26 | // RISC-V is a modular, open-source instruction set designed to be simple, 27 | // extensible, and royalty-free — making it ideal for research and industry adoption. 28 | 29 | // The port targets the RV64GV configuration, which includes: 30 | // - 64-bit general-purpose registers 31 | // - Floating-point unit 32 | // - Vector instructions 33 | 34 | // No new Java APIs or language features are introduced. 35 | // The goal is to provide parity with existing JDK ports (e.g., x64, AArch64) 36 | // so that developers can run unmodified Java applications on RISC-V systems. 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/resources/JDK20Info.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "jep": 429, 4 | "jdk": 20, 5 | "name": "JEP 429 - Scoped Values (Incubator)", 6 | "dscr": "Up-to-date demo in `org.javademos.java25.jep506.ScopedValuesDemo`.", 7 | "link": true, 8 | "code": false 9 | }, 10 | { 11 | "jep": 432, 12 | "jdk": 20, 13 | "name": "JEP 432 - Record Patterns (Second Preview)", 14 | "dscr": "Up-to-date demo in `org.javademos.java21.jep440.RecordPatternsDemo`.", 15 | "link": true, 16 | "code": false 17 | }, 18 | { 19 | "jep": 433, 20 | "jdk": 20, 21 | "name": "JEP 433 - Pattern Matching for switch (Fourth Preview)", 22 | "dscr": "Up-to-date demo in `org.javademos.java21.jep441.PatternMatchingForSwitchDemo`.", 23 | "link": true, 24 | "code": false 25 | }, 26 | { 27 | "jep": 434, 28 | "jdk": 20, 29 | "name": "JEP 434 - Foreign Function & Memory API (Second Preview)", 30 | "dscr": "Up-to-date demo in `org.javademos.java22.jep454.ForeignFunctionMemoryDemo`.", 31 | "link": true, 32 | "code": false 33 | }, 34 | { 35 | "jep": 436, 36 | "jdk": 20, 37 | "name": "JEP 436 - Virtual Threads (Second Preview)", 38 | "dscr": "Up-to-date demo in `org.javademos.java21.jep444.VirtualThreadsDemo`.", 39 | "link": true, 40 | "code": false 41 | }, 42 | { 43 | "jep": 437, 44 | "jdk": 20, 45 | "name": "JEP 437 - Structured Concurrency (Second Incubator)", 46 | "dscr": "Up-to-date demo in `org.javademos.java25.jep505.StructuredConcurrencyDemo`.", 47 | "link": true, 48 | "code": false 49 | }, 50 | { 51 | "jep": 438, 52 | "jdk": 20, 53 | "name": "JEP 438 - Vector API (Fifth Incubator)", 54 | "dscr": "Up-to-date demo in `org.javademos.java25.jep508.VectorAPIDemo`.", 55 | "link": true, 56 | "code": false 57 | } 58 | ] -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java23DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java23.jep455.PrimitiveTypesInPatterns; 9 | import org.javademos.java23.jep466.ClassFileAPIDemo; 10 | import org.javademos.java23.jep467.MarkdownComments; 11 | import org.javademos.java23.jep469.VectorAPIDemo; 12 | import org.javademos.java23.jep471.DeprecateMemoryAccessMethods; 13 | import org.javademos.java23.jep473.StreamGatherersDemo; 14 | import org.javademos.java23.jep474.GenerationalZGC23; 15 | import org.javademos.java23.jep476.ModuleImportDeclarations; 16 | import org.javademos.java23.jep477.ImplicitlyDeclaredClassesDemo; 17 | import org.javademos.java23.jep480.StructuredConcurrency; 18 | import org.javademos.java23.jep481.ScopedValuesDemo; 19 | import org.javademos.java23.jep482.FlexibleConstructorBodies; 20 | 21 | /** 22 | * Loads demos for Java 23. 23 | */ 24 | public class Java23DemoLoader implements IDemoLoader { 25 | 26 | @Override 27 | public void loadDemos(Map demos) { 28 | demos.put(455, new PrimitiveTypesInPatterns()); 29 | demos.put(466, new ClassFileAPIDemo()); 30 | demos.put(467, new MarkdownComments()); 31 | demos.put(469, new VectorAPIDemo()); 32 | demos.put(471, new DeprecateMemoryAccessMethods()); 33 | demos.put(473, new StreamGatherersDemo()); 34 | demos.put(474, new GenerationalZGC23()); 35 | demos.put(476, new ModuleImportDeclarations()); 36 | demos.put(477, new ImplicitlyDeclaredClassesDemo()); 37 | demos.put(480, new StructuredConcurrency()); 38 | demos.put(481, new ScopedValuesDemo()); 39 | demos.put(482, new FlexibleConstructorBodies()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep394/InstanceofPatternMatchingDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep394; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 16 feature JEP 394 - Pattern Matching for instanceof. 6 | /// 7 | /// The basic idea is to allow 'instanceof' check and re-casting to respective 8 | /// data type within one command. 9 | /// 10 | /// JEP history: 11 | /// - JDK 16: [JEP 394 - Pattern Matching for instanceof](https://openjdk.org/jeps/394) 12 | /// - JDK 15: [JEP 375 - Pattern Matching for instanceof (Second Preview)](https://openjdk.org/jeps/375) 13 | /// - JDK 14: [JEP 305 - Pattern Matching for instanceof (Preview)](https://openjdk.org/jeps/305) 14 | /// 15 | /// Further reading: 16 | /// - [Using New Pattern Matching Feature in Java 16](https://www.agileconnection.com/article/using-new-pattern-matching-feature-java-16) 17 | /// 18 | /// @author alois.seckar@gmail.com 19 | public class InstanceofPatternMatchingDemo implements IDemo { 20 | 21 | @Override 22 | public void demo() { 23 | info(394); 24 | 25 | Object x = 5; 26 | System.out.println("X is: " + x); 27 | 28 | // Java < 16 29 | // first we had to perform 'instanceof' check 30 | // then we explicitly cast the variable to Integer 31 | if (x instanceof Integer) { 32 | System.out.println("X is integer"); 33 | System.out.println(((Integer) x).compareTo(10)); 34 | } 35 | 36 | // Java 16+ 37 | // 'instanceof' itself provides variable, that is already re-casted 38 | if (x instanceof Integer integer) { 39 | System.out.println("X is integer"); 40 | System.out.println(integer.compareTo(10)); 41 | } 42 | 43 | System.out.println(); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep475/LateBarrierExpansionG1.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep475; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 24 feature JEP 475 - Late Barrier Expansion for G1. 6 | /// 7 | /// Internal JVM enhancement to reduce compilation overhead and improve maintainability 8 | /// by deferring G1 GC barrier expansion to the code emission phase. 9 | /// 10 | /// @see JEP 475 11 | /// @author Shivansh @Shivansh-22866 12 | 13 | public class LateBarrierExpansionG1 implements IDemo { 14 | 15 | @Override 16 | public void demo() { 17 | info(475); 18 | 19 | // Since this is a GC/compiler-internal change, we cannot demonstrate it 20 | // with executable Java code. Instead, we explain the behavior here. 21 | 22 | 23 | // This JEP changes when G1 Garbage Collector write/read barriers are expanded during JIT compilation. 24 | 25 | // Previously: 26 | // - Barriers were expanded early, during bytecode-to-IR phase 27 | // - Resulted in 10–20% extra C2 compilation overhead 28 | // - Required deep knowledge of C2 compiler internals 29 | 30 | // Now: 31 | // - Barriers are expanded late, at code emission stage 32 | // - Reduces C2 workload 33 | // - Simplifies GC development 34 | // - Reuses existing interpreter assembly barrier code 35 | 36 | // Benefits: 37 | // - Better performance in C2 compilation 38 | // - Easier to maintain and evolve GC barriers 39 | // - Lower complexity for future barrier optimizations 40 | 41 | // Limitations: 42 | // - No direct way to observe this in regular Java apps 43 | // - Testing/benchmarking is internal to HotSpot/JVM developers 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep503/Remove32BitX86Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep503; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 25 change **Remove the 32-bit x86 Port** (JEP 503) 6 | /// 7 | /// ### JEP history 8 | /// - JDK 21: [JEP 449 - Deprecate the Windows 32-bit x86 Port](https://openjdk.org/jeps/449) 9 | /// - JDK 24: [JEP 479 - Remove the Windows 32-bit x86 Port](https://openjdk.org/jeps/479) 10 | /// - JDK 24: [JEP 501 - Deprecate the 32-bit x86 Port for Removal](https://openjdk.org/jeps/501) 11 | /// - JDK 25: [JEP 503 - Remove the 32-bit x86 Port](https://openjdk.org/jeps/503) 12 | /// 13 | /// ### Further reading 14 | /// - [JEP 503 – Motivation and Discussion](https://openjdk.org/jeps/503) 15 | /// 16 | /// @see java.lang.System#getProperty(String) 17 | /// 18 | /// @author @CodeSakshamY 19 | public class Remove32BitX86Demo implements IDemo { 20 | 21 | @Override 22 | public void demo() { 23 | info(503); 24 | 25 | // JEP History of Removal 32-bit Port 26 | // - JDK 21: Marked Windows 32-bit x86 for removal (JEP 449) 27 | // - JDK 24: Removed Windows 32-bit x86 port (JEP 479) 28 | // - JDK 24: Marked full 32-bit x86 port for removal (JEP 501) 29 | // - JDK 25: Fully removed 32-bit x86 port (JEP 503) 30 | 31 | System.out.println("=== Remove 32-bit x86 Port Demo ==="); 32 | 33 | String arch = System.getProperty("os.arch"); 34 | System.out.println("Running on architecture: " + arch); 35 | 36 | System.out.println("\nExplanation:"); 37 | System.out.println("- In JDK 25, the 32-bit x86 port has been removed."); 38 | System.out.println("- You must use a 64-bit JDK build to run Java programs."); 39 | System.out.println("- This simplifies maintenance and improves performance optimizations."); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java22DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java22.jep423.RegionPinningForG1; 9 | import org.javademos.java22.jep447.StatementsBeforeSuper; 10 | import org.javademos.java22.jep454.ForeignFunctionMemoryDemo; 11 | import org.javademos.java22.jep456.UnnamedVariablesAndPatternsDemo; 12 | import org.javademos.java22.jep457.ClassFileAPIDemo; 13 | import org.javademos.java22.jep458.LaunchMultiFileSourceDemo; 14 | import org.javademos.java22.jep459.StringTemplatesSecondPreview; 15 | import org.javademos.java22.jep460.VectorAPIDemo; 16 | import org.javademos.java22.jep461.StreamGatherersDemo; 17 | import org.javademos.java22.jep462.StructuredConcurrencyDemo; 18 | import org.javademos.java22.jep463.ImplicitlyDeclaredClassesDemo; 19 | import org.javademos.java22.jep464.ScopedValuesDemo; 20 | 21 | /** 22 | * Loads demos for Java 22. 23 | */ 24 | public class Java22DemoLoader implements IDemoLoader { 25 | 26 | @Override 27 | public void loadDemos(Map demos) { 28 | demos.put(423, new RegionPinningForG1()); 29 | demos.put(447, new StatementsBeforeSuper()); 30 | demos.put(454, new ForeignFunctionMemoryDemo()); 31 | demos.put(456, new UnnamedVariablesAndPatternsDemo()); 32 | demos.put(457, new ClassFileAPIDemo()); 33 | demos.put(458, new LaunchMultiFileSourceDemo()); 34 | demos.put(459, new StringTemplatesSecondPreview()); 35 | demos.put(460, new VectorAPIDemo()); 36 | demos.put(461, new StreamGatherersDemo()); 37 | demos.put(462, new StructuredConcurrencyDemo()); 38 | demos.put(463, new ImplicitlyDeclaredClassesDemo()); 39 | demos.put(464, new ScopedValuesDemo()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep511/ModuleImportDeclarationsDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep511; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | import module java.base; 6 | 7 | /// Demo for JDK 25 feature JEP 511 - Module Import Declarations. 8 | /// 9 | /// JEP history: 10 | /// - JDK 25: [JEP 511 - Module Import Declarations](https://openjdk.org/jeps/511) 11 | /// - JDK 24: [JEP 494 - Module Import Declarations (Second Preview)](https://openjdk.org/jeps/494) 12 | /// - JDK 23: [JEP 476 - Module Import Declarations (Preview)](https://openjdk.org/jeps/476) 13 | /// 14 | /// Further reading: 15 | /// - [Simplifying Java Development with Module Import](https://www.infoq.com/news/2024/05/simplifying-java-module-import/) 16 | /// 17 | /// @author Arjun Vijay Prakash @ArjunCodess 18 | public class ModuleImportDeclarationsDemo implements IDemo { 19 | 20 | @Override 21 | public void demo() { 22 | info(511); 23 | 24 | // all exported memberes of a Java module can be imported in a single statement 25 | // no explicit package imports are required 26 | 27 | // PRIOR to JDK 25: 28 | // import java.nio.file.Path; 29 | // import java.util.List; 30 | // import java.util.ArrayList; 31 | // import java.util.Arrays; 32 | 33 | // SINCE JDK 25: 34 | // import module java.base; 35 | 36 | // examples of types from multiple packages within module java.base 37 | List values = new ArrayList<>(Arrays.asList("a", "b", "c")); 38 | System.out.println("values: " + values); 39 | System.out.println("random: " + Math.random()); 40 | System.out.println("path: " + Path.of("/tmp")); 41 | 42 | // in case of name conflicts across modules, add explicit class imports 43 | // or use fully-qualified names for the ambiguous types 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java16DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java16.jep338.VectorAPIDemo; 9 | import org.javademos.java16.jep347.Cpp14FeaturesDemo; 10 | import org.javademos.java16.jep380.UnixDomainSocketsDemo; 11 | import org.javademos.java16.jep386.AlpineLinuxPortDemo; 12 | import org.javademos.java16.jep388.WindowsPortDemo; 13 | import org.javademos.java16.jep389.ForeignLinkerDemo; 14 | import org.javademos.java16.jep390.ValueBasedClassesDemo; 15 | import org.javademos.java16.jep392.PackagingToolDemo; 16 | import org.javademos.java16.jep393.ForeignMemoryAccessDemo; 17 | import org.javademos.java16.jep394.InstanceofPatternMatchingDemo; 18 | import org.javademos.java16.jep395.RecordDemo; 19 | import org.javademos.java16.jep396.EncapsulationDemo; 20 | import org.javademos.java16.jep397.SealedClassesDemo; 21 | 22 | /** 23 | * Loads demos for Java 16. 24 | */ 25 | public class Java16DemoLoader implements IDemoLoader { 26 | 27 | @Override 28 | public void loadDemos(Map demos) { 29 | demos.put(338, new VectorAPIDemo()); 30 | demos.put(347, new Cpp14FeaturesDemo()); 31 | demos.put(380, new UnixDomainSocketsDemo()); 32 | demos.put(386, new AlpineLinuxPortDemo()); 33 | demos.put(388, new WindowsPortDemo()); 34 | demos.put(389, new ForeignLinkerDemo()); 35 | demos.put(390, new ValueBasedClassesDemo()); 36 | demos.put(392, new PackagingToolDemo()); 37 | demos.put(393, new ForeignMemoryAccessDemo()); 38 | demos.put(394, new InstanceofPatternMatchingDemo()); 39 | demos.put(395, new RecordDemo()); 40 | demos.put(396, new EncapsulationDemo()); 41 | demos.put(397, new SealedClassesDemo()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep391/MacOsAarch64PortDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep391; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 391 - macOS/AArch64 Port. 6 | /// 7 | /// This JEP provided a port of the JDK to the macOS operating system running 8 | /// on the AArch64 (ARM64) architecture, primarily for Apple Silicon hardware. 9 | /// This allows the JDK and Java applications to run natively on newer Macs 10 | /// without requiring Rosetta 2 translation, improving performance. 11 | /// 12 | /// JEP history: 13 | /// - JDK 17: [JEP 391 - macOS/AArch64 Port](https://openjdk.org/jeps/391) 14 | /// 15 | /// Further reading: 16 | /// - [JEP 391 Details](https://openjdk.org/jeps/391) 17 | /// - [Related: JEP 388 - Windows/AArch64 Port](https://openjdk.org/jeps/388) 18 | /// 19 | /// @author Adarsh80416 20 | public class MacOsAarch64PortDemo implements IDemo { 21 | 22 | @Override 23 | public void demo() { 24 | // Print the standard JEP info header 25 | info(391); 26 | 27 | // This JEP is about providing a build of the JDK for a specific platform (macOS on ARM64). 28 | // There isn't specific Java code to demonstrate the port itself within this application. 29 | // The existence of a downloadable JDK build for macOS/AArch64 is the result of this JEP. 30 | 31 | // Key aspects mentioned in the JEP: 32 | // - Allows Java applications to run natively on Apple Silicon Macs. 33 | // - Avoids performance penalties associated with Rosetta 2 translation for x64 JDK builds. 34 | // - Reused existing AArch64 code from Linux and Windows ports. 35 | // - Implemented support for macOS/AArch64's W^X (Write-XOR-Execute) memory policy in HotSpot. 36 | 37 | // To benefit from this JEP, users simply download and install the 38 | // appropriate JDK build for their macOS/AArch64 system. 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep367/Pack200Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep367; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 367 - Remove the Pack200 Tools and API. 6 | /// 7 | /// JEP 367 removed the Pack200 API and tools from the JDK. This demo documents the 8 | /// removal and shows a small runtime check that the `java.util.jar.Pack200` class is 9 | /// no longer available on the classpath of modern JDKs. Since Pack200 was removed, 10 | /// attempting to reference the API may fail at runtime (NoClassDefFoundError) when 11 | /// running on a JDK that no longer contains it. 12 | /// 13 | /// JEP link: https://openjdk.org/jeps/367 14 | /// 15 | /// @author adripo 16 | public class Pack200Demo implements IDemo { 17 | 18 | @Override 19 | public void demo() { 20 | info(367); 21 | 22 | System.out.println("Checking availability of Pack200 classes at runtime..."); 23 | 24 | try { 25 | // Try to load the Pack200 class reflectively. On JDKs where Pack200 26 | // has been removed this will throw ClassNotFoundException. 27 | Class.forName("java.util.jar.Pack200"); 28 | // If the class is present, show a short note: 29 | System.out.println("java.util.jar.Pack200 is present on this JVM. Pack200 APIs are available."); 30 | } catch (ClassNotFoundException | NoClassDefFoundError ex) { 31 | // Expected on JDKs that removed Pack200 (JDK 14 removal) 32 | System.out.println("Pack200 classes are NOT available on this JVM (removed by JEP 367)."); 33 | System.out.println("If you still need Pack200 functionality consider using an external library or alternate packaging/compression."); 34 | System.out.println("Pack200 was deprecated for removal earlier and removed by JEP 367 in JDK 14."); 35 | } 36 | 37 | System.out.println(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java21/jep439/GenerationalZGC21.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java21.jep439; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 21 feature JEP 439 - Generational ZGC. 6 | /// 7 | /// JEP history: 8 | /// - JDK 21: [JEP 439 - Generational Mode by Default](https://openjdk.org/jeps/439) 9 | /// 10 | /// Further reading: 11 | /// - [Introducing Generational ZGC](https://inside.java/2023/11/28/gen-zgc-explainer/) 12 | /// 13 | /// @author alois.seckar@gmail.com 14 | public class GenerationalZGC21 implements IDemo { 15 | @Override 16 | public void demo() { 17 | info(439); 18 | 19 | // ZGC garbage collector was introduced by JEP 333 (Java 11) and made 20 | // production-ready via JEP 377 (Java 15). 21 | // This is the further evolution - Generational ZGC. 22 | // It can be turned on via `-XX:+UseZGC -XX:+ZGenerational`. 23 | 24 | // ZGC is intended to manage very large memory heaps (up to 16TB) with low 25 | // latency achieved by strong concurrency in exchange for consuming relatively 26 | // more CPU. Generational ZGC optimization is based on dividing the heap into 27 | // "young" and "old" generation. New objects appear in "young" generation, 28 | // which is small and more frequently scanned. Most objects do exists only 29 | // for a short period of time. After some time of existence, persisting objects 30 | // are moved into "old" generation. It is more probable they will last longer, 31 | // so garbage collecting may be performed in longer intervals. 32 | 33 | // This helps to utilize CPU time more effectively, leaving more for the app 34 | // itself, which improves throughput and latency. Generational ZGC is especially 35 | // effective in preventing allocation stalls (may happen when the rate of new 36 | // object allocation is faster than the rate of memory reclaiming). 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep506/ScopedValuesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep506; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 25 feature JEP 506 - Scoped Values. 6 | /// 7 | /// ### JEP history 8 | /// - JDK 25: [JEP 506 - Scoped Values](https://openjdk.org/jeps/506) 9 | /// - JDK 23: [JEP 481 - Scoped Values (Third Preview)](https://openjdk.org/jeps/481) 10 | /// - JDK 22: [JEP 464 - Scoped Values (Second Preview)](https://openjdk.org/jeps/464) 11 | /// - JDK 21: [JEP 446 - Scoped Values (Preview)](https://openjdk.org/jeps/446) 12 | /// - JDK 20: [JEP 429 - Scoped Values (Incubator)](https://openjdk.org/jeps/429) 13 | /// 14 | /// ### Further reading 15 | /// - [Inside Java – Scoped Values](https://inside.java/tag/scoped-values/) 16 | /// 17 | /// @see java.lang.ScopedValue 18 | /// 19 | /// @author @CodeSakshamY 20 | public class ScopedValuesDemo implements IDemo { 21 | 22 | private static final ScopedValue USER = ScopedValue.newInstance(); 23 | 24 | @Override 25 | public void demo() { 26 | info(506); 27 | 28 | // Scoped values allow sharing immutable data safely across threads 29 | // Unlike ThreadLocal, ScopedValue avoids accidental leaks 30 | 31 | // USER is defined with value "Alice" 32 | ScopedValue.where(USER, "Alice").run(() -> { 33 | System.out.println("Inside scope: " + USER.get()); 34 | 35 | // Nested USER will be "Bob" within this block 36 | ScopedValue.where(USER, "Bob").run(() -> { 37 | System.out.println("Nested scope: " + USER.get()); 38 | }); 39 | 40 | // USER is "Alice again" 41 | System.out.println("Back to outer scope: " + USER.get()); 42 | }); 43 | 44 | // USER is not defined here anymore 45 | // would result into `java.util.NoSuchElementException: ScopedValue not bound` 46 | // System.out.println("Outside of scope: " + USER.get()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java14/jep358/NullPointerDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java14.jep358; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 14 feature JEP 358 - Helpful NullPointerExceptions. 6 | /// 7 | /// JEP history: 8 | /// - JDK 14: [JEP 358 - Helpful NullPointerExceptions](https://openjdk.org/jeps/358) 9 | /// 10 | /// Further reading: 11 | /// - [Java 14 NullPointerException](https://www.baeldung.com/java-14-nullpointerexception) 12 | /// 13 | /// @author Abhineshhh 14 | @SuppressWarnings("null") // we are deliberately invoking `NullPointerException` in this demo 15 | public class NullPointerDemo implements IDemo { 16 | 17 | @Override 18 | public void demo() { 19 | info(358); 20 | 21 | try { 22 | // this will raise NullPointerException, but with helpful hint 23 | String s = null; 24 | s.charAt(0); 25 | } catch (Exception ex) { 26 | // in Java 8 you will get just: 27 | // java.lang.NullPointerException 28 | // with helpful NullPointerExceptions the output is: 29 | // java.lang.NullPointerException: Cannot invoke "String.charAt(int)" because "s" is null 30 | ex.printStackTrace(System.out); 31 | } 32 | 33 | try { 34 | // the benefits can be better seen when applied to chained methods 35 | var nullPointer = new NullPointerLevel1(); 36 | // how long would you need to spot the 'null' reference 37 | // by analysing the code yourself? 38 | nullPointer.getLevel2().getLevel3().getLevel4(); 39 | } catch (Exception ex) { 40 | // without the hint, you will have to elaborate, which part 41 | // of the chain was 'null', but now JVM simply tells you, 42 | // and you can narrow your point of interest during debugging 43 | ex.printStackTrace(System.out); 44 | } 45 | 46 | System.out.println(); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep306/RestoreAlwaysStrictFloatingPointSemanticsDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep306; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 306 - Restore Always-Strict Floating-Point Semantics. 6 | /// 7 | /// JEP history: 8 | /// - JDK 17: [JEP 306 - Restore Always-Strict Floating-Point Semantics](https://openjdk.org/jeps/306) 9 | /// 10 | /// Further reading: 11 | /// - [Restore Always-Strict Floating-Point Semantics](https://openjdk.org/jeps/306) 12 | /// 13 | /// @author Alexander Schneider @ab-schneider 14 | public class RestoreAlwaysStrictFloatingPointSemanticsDemo implements IDemo { 15 | @Override 16 | public void demo() { 17 | info(306); 18 | 19 | System.out.println("Use of 'strictfp' modifier will produce a compile time warning: "); 20 | System.out.println("as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required"); 21 | 22 | // Before JDK 17, the default floating-point evaluation could keep wider intermediates (e.g., x87 80-bit). 23 | // Marking code with 'strictfp' modifier forced strict IEEE-754 evaluation, 24 | // avoiding those extended intermediates. As a result, the same program could produce 25 | // bit-different results across machines/JVMs if it did NOT use 'strictfp'. 26 | // 27 | // Since JDK 17, all floating-point expressions are strict by default, 28 | // so adding 'strictfp' no longer changes numerical results. If you *do* write 'strictfp', 29 | // javac will warn it's unnecessary when compiled 30 | 31 | compute(); 32 | } 33 | 34 | // Before JDK 17 to use strict floating-point instead of default 'strictfp' modifier was necessary 35 | // 36 | // public strictfp double strictCompute() { 37 | // ... 38 | // } 39 | 40 | public double compute() { 41 | var s = 0.0; 42 | for (int i = 0; i < 1_000; i++) { 43 | s += Math.sin(i); 44 | } 45 | return s; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep410/RemoveAotJitDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep410; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 410 - Remove the Experimental AOT and JIT Compiler. 6 | /// 7 | /// This JEP removed the experimental Java-based ahead-of-time (AOT) and 8 | /// just-in-time (JIT) Graal compiler from the JDK. These features saw little use 9 | /// and required significant maintenance effort. The Java-Level JVM Compiler 10 | /// Interface (JVMCI) was retained for external compiler usage (like GraalVM). 11 | /// 12 | /// JEP history: 13 | /// - JDK 17: [JEP 410 - Remove the Experimental AOT and JIT Compiler](https://openjdk.org/jeps/410) 14 | /// - JDK 10: [JEP 317 - Experimental Java-Based JIT Compiler](https://openjdk.org/jeps/317) (Introduced Graal JIT) 15 | /// - JDK 9: [JEP 295 - Ahead-of-Time Compilation](https://openjdk.org/jeps/295) (Introduced jaotc) 16 | /// 17 | /// Further reading: 18 | /// - [JEP 410 Details](https://openjdk.org/jeps/410) 19 | /// 20 | /// @author Adarsh80416 21 | public class RemoveAotJitDemo implements IDemo { 22 | 23 | @Override 24 | public void demo() { 25 | // Print the standard JEP info header 26 | info(410); 27 | 28 | // Since this JEP is about removing features (jaotc tool, Graal JIT modules), 29 | // there is no specific code to demonstrate its functionality directly 30 | // within a standard JDK 17+ environment. 31 | 32 | // JEP 410 removed the experimental AOT (jaotc tool) and Graal JIT compiler modules: 33 | // - jdk.aot 34 | // - jdk.internal.vm.compiler 35 | // - jdk.internal.vm.compiler.management 36 | // These features were experimental, saw little use, and were costly to maintain. 37 | // Developers wishing to use Graal for JIT or AOT can use GraalVM builds. 38 | // The JVMCI (JVM Compiler Interface) remains for external compiler integration. 39 | 40 | // No executable demo code needed for a removal JEP. 41 | // An empty line will be printed by the info() method's formatting. 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep491/SynchronizedNoPinning.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep491; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JEP 491: **Synchronize Virtual Threads without Pinning** 6 | /// 7 | /// JEP history: 8 | /// - JDK 21: [JEP 444 - Virtual Threads](https://openjdk.org/jeps/444) (Introduced pinning issue with `synchronized`) 9 | /// - JDK 24: [JEP 491 - Synchronize Virtual Threads without Pinning](https://openjdk.org/jeps/491) 10 | /// 11 | /// @author dhruv-git-sys 12 | public class SynchronizedNoPinning implements IDemo { 13 | 14 | @Override 15 | public void demo() { 16 | info(491); 17 | 18 | /* 19 | * This JEP changes the behavior of `synchronized` blocks for virtual threads. 20 | * Before this change, a virtual thread blocking on a monitor would "pin" its 21 | * carrier platform thread, preventing it from running other virtual threads. 22 | * After this change, the virtual thread unmounts, freeing the platform thread. 23 | * 24 | * --- 25 | * ✅ How to Verify This Change 26 | * --- 27 | * 28 | * You can observe this improved scalability by writing a simple test program: 29 | * 30 | * 1. Create a shared object to use as a lock. 31 | * 32 | * 2. Start a large number of virtual threads (e.g., 200) using a 33 | * `VirtualThreadPerTaskExecutor`. 34 | * 35 | * 3. Have each virtual thread execute a task that enters a `synchronized` 36 | * block using the shared lock object and then sleeps for a short duration 37 | * (e.g., `Thread.sleep(100)`). 38 | * 39 | * 4. **Observation**: Monitor the number of platform threads used by the scheduler's 40 | * underlying pool. Even with 200 virtual threads contending for the lock, 41 | * the number of active platform threads will remain very low (close to the 42 | * number of CPU cores). This demonstrates that the waiting virtual threads 43 | * have unmounted and are not pinning platform threads. 44 | */ 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep409/SealedDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep409; 2 | 3 | import org.javademos.commons.IDemo; 4 | import java.util.Arrays; 5 | 6 | /// Demo for JDK 17 feature JEP 409 - Sealed Classes. 7 | /// 8 | /// We can now 'seal' classes (and interfaces) to avoid unwanted extending 9 | /// (implementing). With new 'sealed' and 'permits' keywords we can limit 10 | /// inheritance (implementation) only to white-listed subclasses. 11 | /// 12 | /// JEP history: 13 | /// - JDK 17: [JEP 409 - Sealed Classes](https://openjdk.org/jeps/409) 14 | /// - JDK 16: [JEP 397 - Sealed Classes (Second Preview)](https://openjdk.org/jeps/397) 15 | /// - JDK 15: [JEP 360 - Sealed Classes (Preview)](https://openjdk.org/jeps/360) 16 | /// 17 | /// Further reading: 18 | /// - [Java Sealed Classes and Interfaces](https://www.baeldung.com/java-sealed-classes-interfaces) 19 | /// 20 | /// @author alois.seckar@gmail.com 21 | public class SealedDemo implements IDemo { 22 | 23 | @Override 24 | public void demo() { 25 | info(409); 26 | 27 | // refer to class declarations for more info 28 | // org.javademos.java17.jep409.SealedDemoParent 29 | // org.javademos.java17.jep409.SealedDemoChild 30 | // org.javademos.java17.jep409.SealedDemoBastard 31 | 32 | SealedDemoParent seal = new SealedDemoChild(); 33 | seal.foo(); 34 | 35 | // TODO sealed interface (works pretty much the same as class inheritance) 36 | 37 | // Reflection API (https://www.baeldung.com/java-reflection) provides 38 | // two new classes: 39 | // isSealed() - to check whether 'sealed' rules apply to given class 40 | // getPermittedSubclasses() - list of class' 'permits' contents 41 | System.out.println(SealedDemoParent.class.isSealed()); 42 | System.out.println(Arrays.toString(SealedDemoParent.class.getPermittedSubclasses())); 43 | System.out.println(SealedDemoChild.class.isSealed()); 44 | System.out.println(Arrays.toString(SealedDemoChild.class.getPermittedSubclasses())); 45 | 46 | System.out.println(); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/Main.java: -------------------------------------------------------------------------------- 1 | package org.javademos; 2 | 3 | import java.util.Comparator; 4 | import java.util.Map; 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.ArgsFilterUtil; 7 | import static org.javademos.init.JEPInfo.JEP_DEMO; 8 | import static org.javademos.init.JEPInfo.JEP_DATA; 9 | 10 | /// This application helps to show some new features from Java 11 to Java 21. 11 | /// The `JEP_DATA` map consists of simple `IDemo` interface implementations. 12 | /// Code logic is being implemented inside each `.demo()` method. 13 | /// 14 | /// @see IDemo 15 | /// @author alois.seckar@gmail.com 16 | public class Main { 17 | 18 | /// Main method supports filtering demos based on command line arguments. 19 | /// 20 | /// Supported arguments and examples: 21 | /// - `--skip-links`: Skip demos that are link-only to other JEP 22 | /// - `--code-only`: Only run demos that contain code 23 | /// - `--jdk=17,25`: Only run demos from specific JDK versions 24 | /// - `--only=382,409`: Only run specific JEP numbers 25 | /// 26 | /// @see ArgsFilterUtil 27 | public static void main(String[] args) { 28 | // get list of demos to run(possibly filtered by args) 29 | // sorted by JDK version and JEP number 30 | var filteredJepData = ArgsFilterUtil.getFilteredJepData(args, JEP_DATA); 31 | 32 | // run selected demos 33 | System.out.println("\n-------------------------------------------------"); 34 | System.out.println("\n=== EXECUTING JAVA DEMOS ==="); 35 | 36 | JEP_DEMO.entrySet().stream() 37 | .filter(e -> filteredJepData.containsKey(e.getKey())) 38 | .sorted( 39 | Comparator 40 | .comparingInt((Map.Entry e) -> JEP_DATA.get(e.getKey()).jdk()) 41 | .thenComparingInt(Map.Entry::getKey) 42 | ) 43 | .map(Map.Entry::getValue) 44 | .forEach(IDemo::demo); 45 | 46 | System.out.println("\n=== EXECUTION COMPLETE ==="); 47 | System.out.println("\n-------------------------------------------------"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java17DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java17.jep306.RestoreAlwaysStrictFloatingPointSemanticsDemo; 9 | import org.javademos.java17.jep356.RandomGeneratorsDemo; 10 | import org.javademos.java17.jep382.MacosRenderingPipelineDemo; 11 | import org.javademos.java17.jep391.MacOsAarch64PortDemo; 12 | import org.javademos.java17.jep398.DeprecateAppletApiForRemovalDemo; 13 | import org.javademos.java17.jep403.StronglyEncapsulateInternalsDemo; 14 | import org.javademos.java17.jep406.PatternMatchingForSwitchPreview; 15 | import org.javademos.java17.jep407.RemoveRmiActivationDemo; 16 | import org.javademos.java17.jep409.SealedDemo; 17 | import org.javademos.java17.jep410.RemoveAotJitDemo; 18 | import org.javademos.java17.jep411.DeprecateSecurityManagerDemo; 19 | import org.javademos.java17.jep412.ForeignFunctionMemoryDemo; 20 | import org.javademos.java17.jep414.VectorAPIDemo; 21 | import org.javademos.java17.jep415.ContextSpecificDeserializationFiltersDemo; 22 | 23 | /** 24 | * Loads demos for Java 17. 25 | */ 26 | public class Java17DemoLoader implements IDemoLoader { 27 | 28 | @Override 29 | public void loadDemos(Map demos) { 30 | demos.put(306, new RestoreAlwaysStrictFloatingPointSemanticsDemo()); 31 | demos.put(356, new RandomGeneratorsDemo()); 32 | demos.put(382, new MacosRenderingPipelineDemo()); 33 | demos.put(391, new MacOsAarch64PortDemo()); 34 | demos.put(398, new DeprecateAppletApiForRemovalDemo()); 35 | demos.put(403, new StronglyEncapsulateInternalsDemo()); 36 | demos.put(406, new PatternMatchingForSwitchPreview()); 37 | demos.put(407, new RemoveRmiActivationDemo()); 38 | demos.put(409, new SealedDemo()); 39 | demos.put(410, new RemoveAotJitDemo()); 40 | demos.put(411, new DeprecateSecurityManagerDemo()); 41 | demos.put(412, new ForeignFunctionMemoryDemo()); 42 | demos.put(414, new VectorAPIDemo()); 43 | demos.put(415, new ContextSpecificDeserializationFiltersDemo()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java21DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java21.jep430.StringTemplatesDemo; 9 | import org.javademos.java21.jep431.SequencedCollectionsDemo; 10 | import org.javademos.java21.jep439.GenerationalZGC21; 11 | import org.javademos.java21.jep440.RecordPatternsDemo; 12 | import org.javademos.java21.jep441.PatternMatchingForSwitchDemo; 13 | import org.javademos.java21.jep442.ForeignFunctionMemoryDemo; 14 | import org.javademos.java21.jep443.UnnamedPatternsAndVariablesPreview; 15 | import org.javademos.java21.jep444.VirtualThreadsDemo; 16 | import org.javademos.java21.jep445.UnnamedClassesDemo; 17 | import org.javademos.java21.jep446.ScopedValuesDemo; 18 | import org.javademos.java21.jep448.VectorAPIDemo; 19 | import org.javademos.java21.jep449.DeprecateWindows32BitX86Demo; 20 | import org.javademos.java21.jep451.DisallowDynamicAgentLoading; 21 | import org.javademos.java21.jep452.KeyEncapsulationMechanismAPIDemo; 22 | import org.javademos.java21.jep453.StructuredConcurrencyDemo; 23 | 24 | /** 25 | * Loads demos for Java 21. 26 | */ 27 | public class Java21DemoLoader implements IDemoLoader { 28 | 29 | @Override 30 | public void loadDemos(Map demos) { 31 | demos.put(430, new StringTemplatesDemo()); 32 | demos.put(431, new SequencedCollectionsDemo()); 33 | demos.put(439, new GenerationalZGC21()); 34 | demos.put(440, new RecordPatternsDemo()); 35 | demos.put(441, new PatternMatchingForSwitchDemo()); 36 | demos.put(442, new ForeignFunctionMemoryDemo()); 37 | demos.put(443, new UnnamedPatternsAndVariablesPreview()); 38 | demos.put(444, new VirtualThreadsDemo()); 39 | demos.put(445, new UnnamedClassesDemo()); 40 | demos.put(446, new ScopedValuesDemo()); 41 | demos.put(448, new VectorAPIDemo()); 42 | demos.put(449, new DeprecateWindows32BitX86Demo()); 43 | demos.put(451, new DisallowDynamicAgentLoading()); 44 | demos.put(452, new KeyEncapsulationMechanismAPIDemo()); 45 | demos.put(453, new StructuredConcurrencyDemo()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/commons/IDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.commons; 2 | 3 | import org.javademos.init.JEPInfo; 4 | 5 | /// Simple interface to unify the demo building process. 6 | /// 7 | /// Override method 'demo()' in your implementation and include new instance 8 | /// into demoPool in Main.java 9 | /// 10 | /// Last review: 2024-11-12 11 | /// 12 | /// TEMPLATE for demo implementation class JavaDocs: 13 | /// ``` 14 | /// /// Demo for JDK feature JEP - . 15 | /// /// 16 | /// /// JEP history: 17 | /// /// - JDK : [JEP - ](https://openjdk.org/jeps/) 18 | /// /// - (repeat 1-n) 19 | /// /// 20 | /// /// Further reading: 21 | /// /// - []() 22 | /// /// - (repeat 1-n) 23 | /// /// 24 | /// /// @see 25 | /// /// @author alois.seckar@gmail.com 26 | /// ``` 27 | /// 28 | /// @author alois.seckar@gmail.com 29 | public interface IDemo { 30 | 31 | /// Header recommended to be displayed at the beginning of each demo's output. 32 | /// 33 | /// @param demoName Name of the demo feature 34 | /// @param demoDscr Description of the purpose 35 | default void info(String demoName, String demoDscr) { 36 | System.out.println(); 37 | System.out.println("-------------------------------------------------"); 38 | System.out.println(demoName); 39 | System.out.println(demoDscr); 40 | System.out.println("-------------------------------------------------"); 41 | System.out.println(); 42 | } 43 | 44 | /// Header recommended to be displayed at the beginning of each demo's output. 45 | /// 46 | /// This method accepts intended number of JEP and looks for data in DEMO_INFO map. 47 | /// 48 | /// @param jepNumber JEP number to be displayed 49 | /// @see JEPInfo#JEP_DATA 50 | default void info (int jepNumber) { 51 | var demoInfo = JEPInfo.JEP_DATA.get(jepNumber); 52 | if (demoInfo != null) { 53 | info(demoInfo.name(), demoInfo.dscr()); 54 | } else { 55 | info (String.valueOf(jepNumber), "No description available"); 56 | } 57 | } 58 | 59 | /// Method to perform the actual work for each demo feature. 60 | void demo(); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep502/StableValuesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep502; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 25 feature JEP 502 - Stable Values (Preview). 6 | /// 7 | /// ### JEP history 8 | /// - JDK 25: [JEP 502 - Stable Values (Preview)](https://openjdk.org/jeps/502) 9 | /// 10 | /// ### Further reading 11 | /// - [JEP 502 - Stable Values. New Feature of Java 25 Explained](https://softwaremill.com/jep-502-stable-values-new-feature-of-java-25-explained/) 12 | /// 13 | /// @author @CodeSakshamY / alois.seckar@gmail.com 14 | public class StableValuesDemo implements IDemo { 15 | 16 | // this is the classic constant declaration in JDK <= 24 17 | // it gets initialized immediately during class loading 18 | // you will find the console log at the very begining of the program execution 19 | private static final ExpensiveObject AS_CONSTANT = new ExpensiveObject(1); 20 | 21 | // since JDK 25 we can init a "stable value" like this 22 | // the variable is also treated as "private static final" 23 | // but its initialization is deferred until the first time it is requested 24 | private static final StableValue AS_STABLE_OBJECT = StableValue.of(); 25 | 26 | // the initialization of stable object will happen ONCE when values are requested the first time 27 | // "orElseSet" accepts a lambda supplier function to initialize the stable value with data 28 | public static ExpensiveObject getExpensiveObject() { 29 | return AS_STABLE_OBJECT.orElseSet(() -> new ExpensiveObject(2)); 30 | } 31 | 32 | @Override 33 | public void demo() { 34 | info(502); 35 | 36 | System.out.println("Stable Values demo started"); 37 | 38 | // here we ask for the stable value for the first time during runtime 39 | getExpensiveObject(); 40 | 41 | System.out.println(AS_CONSTANT); 42 | System.out.println(AS_STABLE_OBJECT); 43 | System.out.println(); 44 | } 45 | } 46 | 47 | class ExpensiveObject { 48 | public ExpensiveObject(int id) { 49 | // imagine this class instance takes long to load 50 | // or consumes a lot of resources during that 51 | System.out.println( "JEP 502 Demo - New ExpensiveObject " + id + " created!"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java23/jep474/GenerationalZGC23.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java23.jep474; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 23 feature JEP 474 - ZGC: Generational Mode by Default. 6 | /// 7 | /// JEP history: 8 | /// - JDK 23: [JEP 474 - Generational Mode by Default](https://openjdk.org/jeps/474) 9 | /// 10 | /// Further reading: 11 | /// - [Generational Mode Now Standard for ZGC in Java](https://www.infoq.com/news/2024/05/java-zgc-update/) 12 | /// - [Introducing Generational ZGC](https://inside.java/2023/11/28/gen-zgc-explainer/) 13 | /// 14 | /// @author alois.seckar@gmail.com 15 | public class GenerationalZGC23 implements IDemo { 16 | @Override 17 | public void demo() { 18 | info(474); 19 | 20 | // ZGC garbage collector was introduced by JEP 333 (Java 11) and made 21 | // production-ready via JEP 377 (Java 15). 22 | // Further evolution - Generational ZGC - appeared in JEP 439 (Java 21). 23 | // Now this mode is being marked default in favor over the older solution. 24 | // Non-generational mode is now deprecated and has to be explicitly turned 25 | // on via `-XX:+UseZGC -XX:-ZGenerational` (will show warnings). 26 | // It will be removed in JDK 24 (see JEP 490). 27 | 28 | // ZGC is intended to manage very large memory heaps (up to 16TB) with low 29 | // latency achieved by strong concurrency in exchange for consuming relatively 30 | // more CPU. Generational ZGC optimization is based on dividing the heap into 31 | // "young" and "old" generation. New objects appear in "young" generation, 32 | // which is small and more frequently scanned. Most objects do exists only 33 | // for a short period of time. After some time of existence, persisting objects 34 | // are moved into "old" generation. It is more probable they will last longer, 35 | // so garbage collecting may be performed in longer intervals. 36 | 37 | // This helps to utilize CPU time more effectively, leaving more for the app 38 | // itself, which improves throughput and latency. Generational ZGC is especially 39 | // effective in preventing allocation stalls (may happen when the rate of new 40 | // object allocation is faster than the rate of memory reclaiming). 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java14DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | import org.javademos.java14.jep305.InstanceofPatternMatchingPreview; 8 | import org.javademos.java14.jep343.PackagingToolIncubatorDemo; 9 | import org.javademos.java14.jep345.NumaAwareG1Demo; 10 | import org.javademos.java14.jep349.JFREventStreamingDemo; 11 | import org.javademos.java14.jep352.NonVolatileMappedByteBuffersDemo; 12 | import org.javademos.java14.jep358.NullPointerDemo; 13 | import org.javademos.java14.jep359.RecordsPreviewDemo; 14 | import org.javademos.java14.jep361.SwitchExpressionsDemo; 15 | import org.javademos.java14.jep362.SolarisSparcRemovalDemo; 16 | import org.javademos.java14.jep363.RemoveTheCMSGarbageCollectorDemo; 17 | import org.javademos.java14.jep364.ZGarbageCollectorOnMacOS; 18 | import org.javademos.java14.jep365.ZGarbageCollectorOnWindows; 19 | import org.javademos.java14.jep366.ParallelScavengeGCCombinationDemo; 20 | import org.javademos.java14.jep367.Pack200Demo; 21 | import org.javademos.java14.jep368.TextBlockSecondPreviewDemo; 22 | import org.javademos.java14.jep370.ForeignMemoryAccessDemo; 23 | 24 | /** 25 | * Loads demos for Java 14. 26 | */ 27 | public class Java14DemoLoader implements IDemoLoader { 28 | 29 | @Override 30 | public void loadDemos(Map demos) { 31 | demos.put(305, new InstanceofPatternMatchingPreview()); 32 | demos.put(343, new PackagingToolIncubatorDemo()); 33 | demos.put(345, new NumaAwareG1Demo()); 34 | demos.put(349, new JFREventStreamingDemo()); 35 | demos.put(352, new NonVolatileMappedByteBuffersDemo()); 36 | demos.put(358, new NullPointerDemo()); 37 | demos.put(359, new RecordsPreviewDemo()); 38 | demos.put(361, new SwitchExpressionsDemo()); 39 | demos.put(362, new SolarisSparcRemovalDemo()); 40 | demos.put(363, new RemoveTheCMSGarbageCollectorDemo()); 41 | demos.put(364, new ZGarbageCollectorOnMacOS()); 42 | demos.put(365, new ZGarbageCollectorOnWindows()); 43 | demos.put(366, new ParallelScavengeGCCombinationDemo()); 44 | demos.put(367, new Pack200Demo()); 45 | demos.put(368, new TextBlockSecondPreviewDemo()); 46 | demos.put(370, new ForeignMemoryAccessDemo()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep510/KeyDerivationFunctionDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep510; 2 | 3 | import org.javademos.commons.IDemo; 4 | import java.security.NoSuchAlgorithmException; 5 | import javax.crypto.SecretKey; 6 | import javax.crypto.spec.PBEKeySpec; 7 | import javax.crypto.SecretKeyFactory; 8 | import java.util.Base64; 9 | 10 | /// Demo for JDK 25 feature JEP 510 - Key Derivation Function API. 11 | /// 12 | /// JEP history: 13 | /// - JDK 24: [JEP 478 - Key Derivation Function API (Preview)](https://openjdk.org/jeps/478) 14 | /// Further reading: 15 | /// - [JEP 510: Key Derivation Function API @ daily.dev](https://app.daily.dev/posts/jep-510-key-derivation-function-api-18iteuevj) 16 | /// 17 | /// @author Kishan Singh @Kishan_Singh 18 | public class KeyDerivationFunctionDemo implements IDemo { 19 | @Override 20 | public void demo() { 21 | info(510); // Print JEP info header 22 | System.out.println("\nJEP 510 introduces a standard API for Key Derivation Functions (KDFs) in Java."); 23 | System.out.println("This demo shows how to derive a key from a password using PBKDF2."); 24 | System.out.println(); 25 | 26 | // Example parameters 27 | String password = "mySecretPassword"; 28 | byte[] salt = "randomSalt123456".getBytes(); 29 | int iterations = 65536; 30 | int keyLength = 256; 31 | 32 | try { 33 | // In Java 25+, you can use the new KeyDerivationFunction API (JEP 510) 34 | // For demonstration, we use PBKDF2 via SecretKeyFactory (backward compatible) 35 | // Replace with KeyDerivationFunction API when available in your JDK 36 | PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, keyLength); 37 | SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); 38 | SecretKey key = skf.generateSecret(spec); 39 | byte[] derivedKey = key.getEncoded(); 40 | 41 | System.out.println("Derived key (Base64): " + Base64.getEncoder().encodeToString(derivedKey)); 42 | System.out.println("\nNote: In Java 25+, use the new KeyDerivationFunction API for a more unified approach."); 43 | } catch (NoSuchAlgorithmException | java.security.spec.InvalidKeySpecException e) { 44 | System.out.println("Key derivation failed: " + e.getMessage()); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep513/FlexibleConstructorBodiesDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep513; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 25 feature JEP 513 - Flexible Constructors Bodies. 6 | /// 7 | /// JEP history: 8 | /// - JDK 25 (preview): 9 | /// [JEP 513 - Flexible Constructors Bodies](https://openjdk.org/jeps/513) 10 | /// 11 | /// Further reading: 12 | /// - [JEP 513](https://openjdk.org/jeps/513) 13 | /// - [JEP 492](https://openjdk.org/jeps/492) (Third Preview) 14 | /// 15 | /// @author Ashutosh Singh @Rossville 16 | public class FlexibleConstructorBodiesDemo implements IDemo{ 17 | @Override 18 | public void demo(){ 19 | info(513); 20 | 21 | new SubClass(1, 2); 22 | } 23 | } 24 | 25 | class SuperClass { 26 | public SuperClass(int x) { 27 | if (x<0) { 28 | throw new IllegalArgumentException(); 29 | } 30 | 31 | // WARNING - This is technically possible, but rather a bad practice. 32 | // Calling a overridden method in the constructor body 33 | // may result into unpredictable behavior. 34 | // In this case, SubClass.show() would be actually called (see the demo output). 35 | show(); 36 | } 37 | 38 | protected void show() { 39 | System.out.println("Show in SuperClass"); 40 | } 41 | } 42 | 43 | class SubClass extends SuperClass { 44 | 45 | private int b; 46 | 47 | // In JDK <= 24, the compiler performs implicit constructor invocation i.e super(...) or this(...). 48 | // If parent constructor call isn't there as a first line of statement [explicit invocation], 49 | // compilation errors occurs. 50 | public SubClass(int x, int b) { 51 | 52 | // in JDK <= 24, you were required to call parent constructor here 53 | // as the first statement in child constructor body 54 | // super(x); 55 | 56 | // since JDK 25 this allows to fail fast 57 | if (x<0) { 58 | throw new IllegalArgumentException(); 59 | } 60 | 61 | // you can also initialize child class members here 62 | this.b = b; 63 | 64 | // and make the explicit parent constructor invocation later 65 | super(x); // would throw compilation error in JDK <= 24 66 | } 67 | 68 | @Override 69 | public void show() { 70 | System.out.println("Show in SubClass - B:" + b); 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java12/extras/String12Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java12.extras; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 12 **String API** enhancements. 6 | /// 7 | /// REFERENCES: 8 | /// - JDK 12: [String::transform](https://bugs.openjdk.org/browse/JDK-8203442) 9 | /// - JDK 12: [String::align, String::indent](https://bugs.openjdk.org/browse/JDK-8200435) 10 | /// 11 | /// Further reading: 12 | /// - [Java 12 String API](https://www.baeldung.com/java12-string-api) 13 | /// 14 | /// @author alois.seckar@gmail.com 15 | public class String12Demo implements IDemo { 16 | 17 | @Override 18 | public void demo() { 19 | info("STRING J12 DEMO", "Examples for Java 12 new String methods"); 20 | 21 | // String::align 22 | // NOTE: align() method was removed again before Java 12 was released 23 | // through https://bugs.openjdk.org/browse/JDK-8215490 24 | 25 | // String::indent 26 | // Adjusts the indentation of each line of this string based on the value of n, 27 | // and normalizes line termination characters. 28 | 29 | // here we will intend "a" with 1, 2 and 3 spaces 30 | System.out.println("String:indent"); 31 | System.out.println("a".indent(1)); 32 | System.out.println("a".indent(2)); 33 | System.out.println("a".indent(3)); 34 | 35 | // String::transform 36 | // This method allows the application of a function to this string. 37 | // The function should expect a single String argument and produce an R result. 38 | 39 | // here we are turning the original word 'hello' into 'transformed hello world!' text 40 | System.out.println("String.transform()"); 41 | String result = "hello".transform(input -> "transformed " + input + " world!"); 42 | System.out.println(result); 43 | 44 | // NOTE: we have to explicitly cast .transform() result to String 45 | // before printing it out, because println() accepts many data types, 46 | // while the output of .transform() may vary. 47 | // Trying to print the result without casting will throw: 48 | // "reference to print is ambiguous 49 | // both method print(char[]) in PrintStream and method print(String) in PrintStream match" 50 | // System.out.print("hello".transform(input -> input + " world!")); 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep514/AheadOfTimeCLIDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep514; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 25 feature JEP 514 - Ahead-of-Time Command-Line Ergonomics. 6 | /// 7 | /// This demo shows how JEP 514 improves the command-line experience for Ahead-of-Time compilation. 8 | /// It simulates a CLI workflow with simplified commands and helpful feedback. 9 | /// 10 | /// JEP history: 11 | /// - JDK 25: [JEP 514 - Ahead-of-Time Command-Line Ergonomics](https://openjdk.org/jeps/514) 12 | /// - JDK 24: [JEP 483 - Ahead-of-Time Class Loading & Linking](https://openjdk.org/jeps/483) 13 | /// 14 | /// Further reading: 15 | /// - [What's New in Project Leyden - JEP 514 and JEP 515 Explained](https://softwaremill.com/whats-new-in-project-leyden-jep-514-and-jep-515-explained/) 16 | /// 17 | /// @author Shivansh @Shivansh-22866 18 | public class AheadOfTimeCLIDemo implements IDemo { 19 | 20 | @Override 21 | public void demo() { 22 | info(514); 23 | 24 | System.out.println("Starting JEP 514 - Ahead-of-Time Command-Line Ergonomics Demo..."); 25 | System.out.println("This demo simulates simplified 'java -AOT' usage with helpful guidance.\n"); 26 | 27 | System.out.println("Step 1: Cold run without any prior AOT compilation."); 28 | simulateCLICommand("java MyApp.java"); 29 | 30 | System.out.println("\nStep 2: Training run (simulating profiling hints for AOT)."); 31 | simulateCLICommand("java -AOT MyApp.java --train"); 32 | 33 | System.out.println("\nStep 3: Production run with cached AOT data applied."); 34 | simulateCLICommand("java -AOT MyApp"); 35 | 36 | System.out.println("\nNOTE: This demo simulates CLI ergonomics. Actual Ahead-of-Time compilation"); 37 | System.out.println("requires JDK 25 support and may involve native image generation under the hood."); 38 | } 39 | 40 | /** 41 | * Simulates a CLI command execution and prints a result as if it ran. 42 | * @param command the CLI command to simulate 43 | */ 44 | private void simulateCLICommand(String command) { 45 | System.out.printf("Running command: %s%n", command); 46 | try { 47 | // Simulate some processing time 48 | Thread.sleep(200); 49 | } catch (InterruptedException e) { 50 | Thread.currentThread().interrupt(); 51 | } 52 | System.out.println("-> Success! Command executed with simplified AOT workflow."); 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java11/string11/String11Demo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java11.string11; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 11 **String API** enhancements. 6 | /// 7 | /// This class demonstrates new methods available on java.lang.String since Java 11. 8 | /// 9 | /// REFERENCES: 10 | /// - JDK 11: [String::isBlank](https://bugs.openjdk.org/browse/JDK-8200437) 11 | /// - JDK 11: [String::lines](https://bugs.openjdk.org/browse/JDK-8200425) 12 | /// - JDK 11: [String::strip, String::stripLeading, String::stripTrailing](https://bugs.openjdk.org/browse/JDK-8200378) 13 | /// - JDK 11: [String::repeat](https://bugs.openjdk.org/browse/JDK-8197594) 14 | /// 15 | /// Further reading: 16 | /// - [Applying New JDK 11 String Methods](https://dzone.com/articles/applying-new-jdk-11-string-methods) 17 | /// 18 | /// @author alois.seckar@gmail.com 19 | public class String11Demo implements IDemo { 20 | 21 | @Override 22 | public void demo() { 23 | info("STRING J11 DEMO", "Examples for Java 11 new String methods"); 24 | 25 | // true if the String contains at least one non-whitespace character 26 | System.out.println("String.isBlank()"); 27 | System.out.println("".isBlank()); 28 | System.out.println(" ".isBlank()); 29 | System.out.println("s".isBlank()); 30 | 31 | // removes whitespaces surrounding the String 32 | System.out.println("String.strip()"); 33 | System.out.print("|"); 34 | System.out.print(" aaa ".strip()); 35 | System.out.println("|"); 36 | 37 | // removes whitespaces BEFORE the String 38 | System.out.println("String.stripLeading()"); 39 | System.out.print("|"); 40 | System.out.print(" aaa ".stripLeading()); 41 | System.out.println("|"); 42 | 43 | // removes whitespaces AFTER the String 44 | System.out.println("String.stripTrailing()"); 45 | System.out.print("|"); 46 | System.out.print(" aaa ".stripTrailing()); 47 | System.out.println("|"); 48 | 49 | // slices the String into Stream by \n characters 50 | System.out.println("String.lines()"); 51 | "line1\nline2\nline3".lines().forEach(System.out::println); 52 | 53 | // repeats the String n-times 54 | System.out.println("String.repeat(n)"); 55 | System.out.println("abc".repeat(5)); 56 | 57 | System.out.println(); 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/extras/J17DeprecatedDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.extras; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 **deprecated APIs**. 6 | /// 7 | /// This class shows some examples of deprecated APIs from Java 17 Platform. 8 | /// 9 | /// REFERENCES: 10 | /// - JDK 17: TODO specify relevant JEP(s) / JBS(s) 11 | /// 12 | /// Further reading: 13 | /// - [Java 17 Deprecated List](https://docs.oracle.com/en/java/javase/17/docs/api/deprecated-list.html) - full list of DEPRECATED features still present in Java 17 14 | /// - [Removed Tools and Components](https://docs.oracle.com/en/java/javase/17/migrate/removed-tools-and-components.html) - list of DEPRECATED and REMOVED from platform features until Java 17 15 | /// 16 | /// @author alois.seckar@gmail.com 17 | public class J17DeprecatedDemo implements IDemo { 18 | 19 | @Override 20 | public void demo() { 21 | info("DEPRECATED DEMO", "What is deprecated in Java 17"); 22 | 23 | System.out.println("There is nothing to display in this demo"); 24 | System.out.println("Go and check DeprecatedDemo.java class"); 25 | System.out.println("to see what is not meant to be used anymore"); 26 | System.out.println(); 27 | 28 | 29 | // natural primitive-wrapping classes' constructors 30 | // @Deprecated(since="9", forRemoval = true) 31 | // var i = new Integer("5"); 32 | // use static factory method instead 33 | // var j = Integer.valueOf("5"); 34 | 35 | 36 | // Applet API 37 | // @deprecated + forRemoval = true 38 | // Applet lastTryOfApplet = new Applet(); 39 | // DO NOT seek for replacement, do it differently 40 | // https://www.oracle.com/technetwork/java/javase/migratingfromapplets-2872444.pdf 41 | 42 | 43 | // SecurityManager 44 | // @Deprecated(since="17", forRemoval=true) 45 | // SecurityManager secMan = new SecurityManager(); 46 | // 47 | // disabled by default and not widely used 48 | // however, can be found e.g. in Tomcat or ElasticSearch 49 | // 50 | // (dis)allows almost all JVM actions based on white-list policies 51 | // 52 | // .policy file 53 | // grant codeBase "file:${{java.ext.dirs}}/*" { 54 | // permission java.security.AllPermission; 55 | // }; 56 | // 57 | // read https://openjdk.org/jeps/411 to know more 58 | // 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/init/Java25DemoLoader.java: -------------------------------------------------------------------------------- 1 | package org.javademos.init; 2 | 3 | import java.util.Map; 4 | 5 | import org.javademos.commons.IDemo; 6 | import org.javademos.commons.IDemoLoader; 7 | 8 | import org.javademos.java25.jep470.PemEncodingsDemo; 9 | import org.javademos.java25.jep502.StableValuesDemo; 10 | import org.javademos.java25.jep503.Remove32BitX86Demo; 11 | import org.javademos.java25.jep505.StructuredConcurrencyDemo; 12 | import org.javademos.java25.jep506.ScopedValuesDemo; 13 | import org.javademos.java25.jep507.PrimitiveTypesDemo; 14 | import org.javademos.java25.jep508.VectorAPIDemo; 15 | import org.javademos.java25.jep509.CpuTimeProfilingDemo; 16 | import org.javademos.java25.jep510.KeyDerivationFunctionDemo; 17 | import org.javademos.java25.jep511.ModuleImportDeclarationsDemo; 18 | import org.javademos.java25.jep512.CompactSourceFilesDemo; 19 | import org.javademos.java25.jep513.FlexibleConstructorBodiesDemo; 20 | import org.javademos.java25.jep514.AheadOfTimeCLIDemo; 21 | import org.javademos.java25.jep515.AheadOfTimeMethodProfilingDemo; 22 | import org.javademos.java25.jep518.JFRCooperativeSamplingDemo; 23 | import org.javademos.java25.jep519.CompactObjectHeaderDemo; 24 | import org.javademos.java25.jep520.Jep520MethodTracingDemo; 25 | import org.javademos.java25.jep521.GenerationalShenandoahDemo; 26 | 27 | /** 28 | * Loads demos for Java 25. 29 | */ 30 | public class Java25DemoLoader implements IDemoLoader { 31 | 32 | @Override 33 | public void loadDemos(Map demos) { 34 | demos.put(470, new PemEncodingsDemo()); 35 | demos.put(502, new StableValuesDemo()); 36 | demos.put(503, new Remove32BitX86Demo()); 37 | demos.put(505, new StructuredConcurrencyDemo()); 38 | demos.put(506, new ScopedValuesDemo()); 39 | demos.put(507, new PrimitiveTypesDemo()); 40 | demos.put(508, new VectorAPIDemo()); 41 | demos.put(509, new CpuTimeProfilingDemo()); 42 | demos.put(510, new KeyDerivationFunctionDemo()); 43 | demos.put(511, new ModuleImportDeclarationsDemo()); 44 | demos.put(512, new CompactSourceFilesDemo()); 45 | demos.put(513, new FlexibleConstructorBodiesDemo()); 46 | demos.put(514, new AheadOfTimeCLIDemo()); 47 | demos.put(515, new AheadOfTimeMethodProfilingDemo()); 48 | demos.put(518, new JFRCooperativeSamplingDemo()); 49 | demos.put(519, new CompactObjectHeaderDemo()); 50 | demos.put(520, new Jep520MethodTracingDemo()); 51 | demos.put(521, new GenerationalShenandoahDemo()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java15/jep377/ZGarbageCollectorDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java15.jep377; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 15 feature JEP 377 – ZGC: A Scalable Low-Latency Garbage Collector. 6 | /// 7 | /// JEP history: 8 | /// - JDK 15: [JEP 377 - ZGC: A Scalable Low-Latency Garbage Collector](https://openjdk.org/jeps/377) 9 | /// - JDK 11: [JEP 333 - ZGC: A Scalable Low-Latency Garbage Collector (Experimental)](https://openjdk.org/jeps/333) 10 | /// 11 | /// Further reading: 12 | /// - [Java ZGC Overview](https://www.baeldung.com/jvm-zgc) 13 | /// - [Inside Java – The Z Garbage Collector](https://inside.java/2020/06/29/zgc-production/) 14 | /// 15 | /// @author wassef 16 | 17 | public class ZGarbageCollectorDemo implements IDemo { 18 | 19 | @Override 20 | public void demo() { 21 | info(377); 22 | 23 | // ZGC (Z Garbage Collector) is a scalable, low-latency garbage collector 24 | // introduced experimentally in Java 11 (JEP 333) and promoted to production 25 | // in Java 15 (JEP 377). 26 | 27 | // Its design goal is to keep GC pause times consistently under 10 ms, 28 | // regardless of heap size — even for multi-terabyte heaps. 29 | // To achieve this, ZGC performs all heavy operations (marking, relocation, 30 | // and remapping) concurrently with the running application threads. 31 | 32 | // Core characteristics: 33 | // - Pause times: typically < 10 ms, independent of heap size 34 | // - Scalable: supports heaps up to multiple TB 35 | // - Compacting: prevents fragmentation while staying concurrent 36 | // - Load-barrier based, using “colored pointers” to track object state 37 | 38 | // Suitable for: 39 | // - Latency-sensitive systems (e.g. trading, analytics) 40 | // - Applications requiring large heaps and predictable response times 41 | 42 | // --- Usage examples --- 43 | 44 | // Enable ZGC (basic): 45 | // java -XX:+UseZGC -Xmx4g -Xms4g -jar myapp.jar 46 | 47 | // Enable detailed GC logging: 48 | // java -XX:+UseZGC -Xlog:gc* -jar myapp.jar 49 | 50 | // Optional tuning flags: 51 | // -XX:SoftMaxHeapSize=2g # soft heap limit for adaptive resizing 52 | // -Xlog:gc+heap=debug # show region allocation details 53 | 54 | // Supported platforms (as of JDK 15): 55 | // • Linux/x64 56 | // • Windows/x64 57 | // • macOS/x64 58 | // • Linux/AArch64 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep386/AlpineLinuxPortDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep386; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 16 feature JEP 386 - Alpine Linux Port. 6 | /// 7 | /// JEP history: 8 | /// - JDK 16: [JEP 386 - Alpine Linux Port](https://openjdk.org/jeps/386) 9 | /// 10 | /// Further reading: 11 | /// - [JEP 386 Details](https://openjdk.org/jeps/386) 12 | /// - [Alpine Linux](https://alpinelinux.org/) 13 | /// - [musl libc](https://musl.libc.org/) 14 | /// 15 | /// @author Shuvam00032 16 | public class AlpineLinuxPortDemo implements IDemo { 17 | 18 | @Override 19 | public void demo() { 20 | info(386); 21 | 22 | // JEP 386 provided a port of the JDK to run on Alpine Linux and other Linux distributions 23 | // that use the musl C standard library (libc). 24 | // 25 | // --- Why Alpine Linux and musl? --- 26 | // - Alpine Linux is a lightweight, security-oriented Linux distribution. 27 | // - It's very popular for container images due to its small size (often under 10MB). 28 | // - Alpine uses 'musl' as its C library, unlike most other Linux distributions that use 'glibc'. 29 | // - Before this JEP, running Java on Alpine required workarounds or specific builds, 30 | // as the standard OpenJDK builds primarily targeted glibc. 31 | // 32 | // --- What did this JEP achieve? --- 33 | // - It made the necessary changes in the JDK source code (HotSpot JVM and core libraries) 34 | // to compile and run correctly with musl libc. 35 | // - This allows standard OpenJDK builds (or builds derived from them) to target Alpine Linux directly. 36 | // - It simplifies deploying Java applications in Alpine-based Docker containers. 37 | // 38 | // --- How to observe the effect? --- 39 | // - The primary outcome is the *availability* of official or community OpenJDK builds 40 | // specifically for Alpine Linux (linux-x64-musl or linux-aarch64-musl). 41 | // - You can run Java applications within an Alpine Linux container using a compatible JDK build. 42 | // 43 | // Example (Conceptual - Running in an Alpine Docker container): 44 | // docker run -it --rm openjdk:16-jdk-alpine java -version 45 | // (This would show the JDK running successfully on Alpine) 46 | // 47 | // Since this JEP is about platform support, there's no specific Java code API to demonstrate. 48 | // The benefit is realized at the deployment and runtime environment level. 49 | 50 | 51 | } 52 | 53 | 54 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep403/StronglyEncapsulateInternalsDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep403; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 403 - Strongly Encapsulate JDK Internals. 6 | /// 7 | /// JEP history: 8 | /// - JDK 17: [JEP 403 - Strongly Encapsulate JDK Internals](https://openjdk.org/jeps/403) 9 | /// - JDK 9: [JEP 260 - Encapsulate Most Internal APIs](https://openjdk.org/jeps/260) (Initial step) 10 | /// 11 | /// Further reading: 12 | /// - [Understanding JEP 403: Strongly Encapsulate JDK Internals](https://www.baeldung.com/java-internal-apis-strong-encapsulation) 13 | /// 14 | /// @author Shuvam00032 15 | public class StronglyEncapsulateInternalsDemo implements IDemo { 16 | 17 | @Override 18 | public void demo() { 19 | info(403); 20 | /*System.out.println("This feature restricts access to internal JDK APIs by default."); 21 | System.out.println(); 22 | System.out.println("Why was this done?"); 23 | System.out.println("- Improve JDK Security: Prevents unintended use of internal classes."); 24 | System.out.println("- Improve Maintainability: Allows JDK developers to change internal APIs without breaking user code."); 25 | System.out.println(); 26 | System.out.println("What does it mean in practice?"); 27 | System.out.println("- Code using reflection or `setAccessible(true)` to access internal packages (like `sun.*`, `jdk.internal.*`) will fail by default."); 28 | System.out.println("- Examples of internal APIs include classes within packages like `sun.misc`."); 29 | System.out.println("- If access is truly needed (discouraged), command-line flags like `--add-opens` must be used."); 30 | System.out.println(); 31 | System.out.println("This demo doesn't execute restricted code, as that would require specific (and discouraged) JVM configurations."); 32 | System.out.println("The goal is to understand the *concept* of encapsulation enforcement.");*/ 33 | 34 | // You could add an example comment block showing code that *would* fail: 35 | /* 36 | // Example of code that would likely fail by default under JEP 403: 37 | try { 38 | // Attempting to access an internal class via reflection 39 | Class unsafeClass = Class.forName("sun.misc.Unsafe"); 40 | // ... further operations would likely throw InaccessibleObjectException ... 41 | } catch (Exception e) { 42 | System.out.println("Access to internal API sun.misc.Unsafe is restricted: " + e.getMessage()); 43 | } 44 | */ 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java18/jep421/DeprecateFinalization.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java18.jep421; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for Java 18 feature JEP 421 - Deprecate Finalization for Removal. 6 | /// 7 | /// This JEP deprecates the finalization mechanism for removal in a future release. Finalization, 8 | /// using the `finalize()` method, has been a problematic and dangerous feature since Java 1.0. 9 | /// It is unpredictable, slow, and can lead to security vulnerabilities and resource leaks. 10 | /// 11 | /// JEP history: 12 | /// - [JEP 421: Deprecate Finalization for Removal](https://openjdk.org/jeps/421) 13 | /// 14 | /// @author mayankvyas1306 15 | public class DeprecateFinalization implements IDemo { 16 | 17 | @Override 18 | public void demo() { 19 | info(421); 20 | 21 | /* 22 | System.out.println(""" 23 | JEP 421 officially deprecates finalization for removal. The `finalize()` method, 24 | intended to clean up resources before an object is garbage collected, is fundamentally flawed. 25 | 26 | --- Why Finalization is Deprecated --- 27 | 28 | 1. **Unpredictable:** There's no guarantee *when* or even *if* a finalizer will run. 29 | 2. **Performance Penalty:** The mere presence of a `finalize()` method slows down garbage collection. 30 | 3. **Security Risks:** Finalizers can "resurrect" objects from partially initialized 31 | constructors, leading to unstable and insecure states. 32 | 4. **Difficult to Use Correctly:** It's hard to write correct, thread-safe finalizers. 33 | 34 | --- Key Changes in JDK 18 --- 35 | 36 | 1. **Deprecation for Removal:** The `Object.finalize()` method is now marked with 37 | `@Deprecated(forRemoval=true)`. Compiling a class with a `finalize()` method 38 | will now generate a warning. 39 | 40 | 2. **New Command-Line Option:** A new flag, `--finalization=disabled`, was added to 41 | completely disable finalization at runtime. This is for testing how an application 42 | will behave when finalization is eventually removed. 43 | 44 | --- Modern Alternatives --- 45 | 46 | Developers should use superior, more reliable alternatives for resource management: 47 | - **`try-with-resources`:** For resources that have a clear lexical scope. 48 | - **`java.lang.ref.Cleaner`:** For managing the cleanup of objects when they become unreachable, 49 | without the flaws of finalization. 50 | """); 51 | */ 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep515/AheadOfTimeMethodProfilingDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep515; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | /// Demo for JDK 25 feature JEP 515 - Ahead-of-Time Method Profiling. 9 | /// 10 | /// JEP history: 11 | /// - JDK 25: [JEP 515 - Ahead-of-Time Method Profiling](https://openjdk.org/jeps/515) 12 | /// - JDK 24: [JEP 483 - Ahead-of-Time Class Loading & Linking](https://openjdk.org/jeps/483) 13 | /// 14 | /// Further reading: 15 | /// - [What's New in Project Leyden - JEP 514 and JEP 515 Explained](https://softwaremill.com/whats-new-in-project-leyden-jep-514-and-jep-515-explained/) 16 | /// 17 | /// @author Shivansh @Shivansh-22866 18 | public class AheadOfTimeMethodProfilingDemo implements IDemo { 19 | 20 | 21 | @Override 22 | public void demo() { 23 | info(515); 24 | 25 | System.out.println("Starting JEP 515 - AOT Method Profiling Demo..."); 26 | System.out.println("This demo simulates a warmup phase using Stream API to demonstrate profiling benefits.\n"); 27 | 28 | long coldStart = runAndMeasure(); 29 | System.out.printf("Cold run duration: %d ms%n", coldStart); 30 | 31 | System.out.println("\nSimulating training run (this would be profiled in real AOT scenario)..."); 32 | 33 | long trainingRun = runAndMeasure(); 34 | System.out.printf("Training run duration: %d ms%n", trainingRun); 35 | 36 | System.out.println("\nSimulating production run using cached profiles (JEP 515 feature)..."); 37 | 38 | long cachedProfileRun = runAndMeasure(); 39 | System.out.printf("Production run with cached profiles duration: %d ms%n", cachedProfileRun); 40 | 41 | System.out.println("\nNOTE: In real scenarios, profiling would be persisted in the AOT cache and reused automatically."); 42 | } 43 | 44 | /** 45 | * Simulates the workload described in the JEP (stream-based CPU load). 46 | * @return Time in milliseconds to execute the workload 47 | */ 48 | private long runAndMeasure() { 49 | long start = System.currentTimeMillis(); 50 | 51 | for (int i = 0; i < 100_000; i++) { 52 | greeting(i); 53 | } 54 | 55 | System.out.println(greeting(0)); 56 | 57 | long end = System.currentTimeMillis(); 58 | return end - start; 59 | } 60 | 61 | private String greeting(int n) { 62 | List words = List.of("Hello", String.valueOf(n), "world!"); 63 | return words.stream() 64 | .filter(w -> !w.contains("0")) 65 | .collect(Collectors.joining(", ")); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep382/MacosRenderingPipelineDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep382; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 382 - New macOS Rendering Pipeline. 6 | /// 7 | /// JEP history: 8 | /// - JDK 17: [JEP 382 - New macOS Rendering Pipeline](https://openjdk.org/jeps/382) 9 | /// 10 | /// Further reading: 11 | /// - [JEP 382: New macOS Rendering Pipeline](https://openjdk.org/jeps/382) 12 | /// - [Apple Developer: Metal](https://developer.apple.com/metal/) 13 | /// 14 | /// @author Shuvam00032 15 | public class MacosRenderingPipelineDemo implements IDemo { 16 | 17 | @Override 18 | public void demo() { 19 | info(382); 20 | 21 | // JEP 382 replaced the internal rendering pipeline used by the Java 2D API on macOS. 22 | // The old pipeline used Apple's OpenGL API, which was deprecated by Apple in macOS 10.14 Mojave. 23 | // The new pipeline uses Apple's modern Metal API. 24 | 25 | // --- Why was this change needed? --- 26 | // 1. Deprecation: Apple deprecated OpenGL, signaling its eventual removal. Staying on OpenGL 27 | // risked future incompatibility with macOS updates. 28 | // 2. Performance & Features: Metal is Apple's modern graphics API, offering better performance 29 | // and access to newer GPU features compared to the older OpenGL. 30 | // 3. Consistency: Aligns Java's rendering on macOS with the direction of the platform. 31 | 32 | // --- What does it mean for developers? --- 33 | // - This is an INTERNAL change to the JDK. 34 | // - Ideally, Java applications using Swing/AWT (Java 2D) on macOS should continue to work 35 | // without any code changes. 36 | // - Users might observe performance improvements or changes in rendering behavior on macOS. 37 | // - The public Java 2D API itself did not change. 38 | 39 | // --- How to observe the effect? --- 40 | // - Run Java applications using Swing/AWT on macOS with JDK 17+ and compare performance 41 | // or visual fidelity against older JDK versions (if possible). 42 | // - Check system properties or logs (if available) related to rendering pipelines, though 43 | // this might require deeper JVM introspection. The system property `sun.java2d.opengl` 44 | // might have been relevant previously, but the new pipeline uses Metal. 45 | 46 | // Since this is an internal implementation detail, there's no specific Java code 47 | // to demonstrate the switch from OpenGL to Metal directly. The effect is primarily 48 | // on runtime behavior and compatibility on macOS. 49 | 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/resources/JDK18Info.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "jep": 400, 4 | "jdk": 18, 5 | "name": "JEP 400 - UTF-8 by Default", 6 | "dscr": "Sets the default charset to UTF-8 for Java applications, improving compatibility and reducing bugs related to character encoding.", 7 | "link": false, 8 | "code": true 9 | }, 10 | { 11 | "jep": 408, 12 | "jdk": 18, 13 | "name": "JEP 408 - Simple Web Server", 14 | "dscr": "Command-line tool and API to start a minimal HTTP server for serving static files. Useful for prototyping, testing, and educational purposes.", 15 | "link": false, 16 | "code": true 17 | }, 18 | { 19 | "jep": 413, 20 | "jdk": 18, 21 | "name": "JEP 413 - Code Snippets in Java API Documentation", 22 | "dscr": "Introduces the @snippet tag for JavaDoc to simplify the inclusion of example source code in API documentation.", 23 | "link": false, 24 | "code": false 25 | }, 26 | { 27 | "jep": 416, 28 | "jdk": 18, 29 | "name": "JEP 416 - Reimplement Core Reflection with Method Handles", 30 | "dscr": "An internal reimplementation of Core Reflection to use method handles, unifying the platform's reflective mechanisms. This change improves performance for constant-folded reflection calls and reduces JDK maintenance costs.", 31 | "link": false, 32 | "code": true 33 | }, 34 | { 35 | "jep": 417, 36 | "jdk": 18, 37 | "name": "JEP 417 - Vector API (Third Incubator)", 38 | "dscr": "Up-to-date demo in `org.javademos.java25.jep508.VectorAPIDemo`.", 39 | "link": true, 40 | "code": false 41 | }, 42 | { 43 | "jep": 418, 44 | "jdk": 18, 45 | "name": "JEP 418 - Internet-Address Resolution SPI", 46 | "dscr": "Defines a service-provider interface (SPI) for host name and address resolution, allowing `java.net.InetAddress` to use custom resolvers.", 47 | "link": false, 48 | "code": true 49 | }, 50 | { 51 | "jep": 419, 52 | "jdk": 18, 53 | "name": "JEP 419 - Foreign Function & Memory API (Second Incubator)", 54 | "dscr": "Up-to-date demo in `org.javademos.java22.jep454.ForeignFunctionMemoryDemo`.", 55 | "link": true, 56 | "code": false 57 | }, 58 | { 59 | "jep": 420, 60 | "jdk": 18, 61 | "name": "JEP 420 - Pattern Matching for switch (Second Preview)", 62 | "dscr": "Up-to-date demo in `org.javademos.java21.jep441.PatternMatchingForSwitchDemo`.", 63 | "link": true, 64 | "code": false 65 | }, 66 | { 67 | "jep": 421, 68 | "jdk": 18, 69 | "name": "JEP 421 - Deprecate Finalization for Removal", 70 | "dscr": "Deprecates the finalization mechanism for removal in a future release due to its inherent flaws.", 71 | "link": false, 72 | "code": false 73 | } 74 | ] -------------------------------------------------------------------------------- /src/main/java/org/javademos/java17/jep407/RemoveRmiActivationDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java17.jep407; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | /// Demo for JDK 17 feature JEP 407 - Remove RMI Activation. 6 | /// 7 | /// JEP history: 8 | /// - JDK 17: [JEP 407 - Remove RMI Activation](https://openjdk.org/jeps/407) 9 | /// - JDK 15: [JEP 385 - Deprecate RMI Activation for Removal](https://openjdk.org/jeps/385) 10 | /// 11 | /// Further reading: 12 | /// - [Oracle: RMI Activation Removed](https://docs.oracle.com/en/java/javase/17/migrate/removed-apis.html#GUID-4BAD9F56-54CA-4C41-AD0F-974F87483B46) 13 | /// 14 | /// @author Shuvam00032 15 | public class RemoveRmiActivationDemo implements IDemo { 16 | 17 | @Override 18 | public void demo() { 19 | info(407); 20 | 21 | // JEP 407 removed the RMI Activation mechanism from Java 17. 22 | // RMI Activation was an older part of RMI (Remote Method Invocation) that allowed 23 | // objects to be automatically activated (started) on demand when a remote method call arrived. 24 | 25 | // Why was it removed? 26 | // - Obsolete Technology: RMI Activation was rarely used in modern applications. 27 | // - Complexity and Maintenance: It added significant complexity to the RMI system and was hard to maintain. 28 | // - Security Concerns: Activation mechanisms can introduce security vulnerabilities if not managed carefully. 29 | // - Alternatives Exist: Modern distributed systems use different approaches for service lifecycle management (e.g., containers, service discovery). 30 | 31 | // What was actually removed? 32 | // - The `java.rmi.activation` package and all its classes (like ActivationSystem, Activatable, etc.). 33 | // - The `rmid` tool, which was the activation system daemon. 34 | 35 | // IMPORTANT: Core RMI functionality (remote object interfaces, registry, remote calls) was NOT removed and still works. 36 | // This JEP only removed the *Activation* part. 37 | 38 | // Since the relevant classes and tools are gone, there's no runnable code to demonstrate. 39 | // Attempting to import or use classes from `java.rmi.activation` will result in a compile-time error in JDK 17+. 40 | 41 | /* 42 | // Example code that would FAIL to compile in JDK 17+: 43 | import java.rmi.activation.*; // <-- This import fails 44 | 45 | public class ActivationExample { 46 | // Using Activatable or ActivationSystem would cause compile errors 47 | // public static void main(String[] args) throws Exception { 48 | // ActivationSystem system = ActivationGroup.getSystem(); // <-- Class not found 49 | // } 50 | } 51 | */ 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java16/jep396/EncapsulationDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java16.jep396; 2 | 3 | import org.javademos.commons.IDemo; 4 | import java.lang.reflect.Field; 5 | import java.lang.reflect.InaccessibleObjectException; // The key exception 6 | 7 | /// ## JEP 396: Strongly Encapsulate JDK Internals by Default 8 | /// 9 | /// ### History 10 | /// Before Java 16, it was possible (though discouraged) to use Reflection to 11 | /// access internal, private parts of the JDK. This JEP changed the default 12 | /// behavior to block such access unless specifically permitted via command-line flags. 13 | /// 14 | /// ### Links 15 | /// - [Official JEP 396](https://openjdk.org/jeps/396) 16 | /// 17 | /// @since Java 16 18 | public class EncapsulationDemo implements IDemo { 19 | 20 | @Override 21 | public void demo() { 22 | //Call the info helper 23 | info(396); 24 | 25 | // The Demo: Attempt to access an internal field 26 | System.out.println("Attempting to access the private 'value' field of java.lang.String using Reflection..."); 27 | 28 | try { 29 | // Get the private 'value' field (which holds the string's bytes) 30 | Field stringValueField = String.class.getDeclaredField("value"); 31 | 32 | // Try to make it accessible (this is what JEP 396 blocks by default) 33 | stringValueField.setAccessible(true); 34 | 35 | // If we reached here without an exception, the encapsulation is not strong (e.g., older Java or --illegal-access used) 36 | System.out.println("WARN: Access was granted. This might happen on older Java versions or if illegal access is permitted."); 37 | // Example of accessing it if allowed: 38 | // byte[] bytes = (byte[]) stringValueField.get("hello"); 39 | // System.out.println("Accessed internal bytes (length): " + bytes.length); 40 | 41 | } catch (NoSuchFieldException e) { 42 | System.err.println("Error: Could not find the 'value' field. Internal structure might have changed."); 43 | e.printStackTrace(); 44 | } catch (InaccessibleObjectException e) { 45 | // SUCCESS! Catching this exception is the expected outcome in Java 16+ 46 | System.out.println("SUCCESS: Caught InaccessibleObjectException as expected!"); 47 | System.out.println("Message: " + e.getMessage()); 48 | System.out.println("This demonstrates that JDK internals are strongly encapsulated by default."); 49 | } catch (Exception e) { 50 | // Catch any other unexpected exceptions 51 | System.err.println("An unexpected error occurred during reflection:"); 52 | e.printStackTrace(); 53 | } 54 | System.out.println("Demo complete."); 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java24/jep497/QuantumResistantModuleLatticeBasedDigitalSignature.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java24.jep497; 2 | 3 | import java.security.KeyFactory; 4 | import java.security.KeyPair; 5 | import java.security.KeyPairGenerator; 6 | import java.security.PrivateKey; 7 | import java.security.spec.NamedParameterSpec; 8 | import java.security.spec.PKCS8EncodedKeySpec; 9 | import java.security.Signature; 10 | 11 | import org.javademos.commons.IDemo; 12 | 13 | /// Demo for JDK 24 feature **Quantum Resistant Module - Lattice-based Digital Signature** (JEP 497) 14 | /// 15 | /// JEP history: - JDK 24 (preview): [JEP 497 - Quantum Resistant Module - Lattice-based Digital Signature](https://openjdk.org/jeps/497) 16 | /// 17 | /// Further reading: 18 | /// [JEP 497](https://openjdk.org/jeps/497) 19 | /// 20 | /// @author Ashutosh Singh @Rossville 21 | public class QuantumResistantModuleLatticeBasedDigitalSignature implements IDemo { 22 | @Override 23 | public void demo() { 24 | try { 25 | // We are KeyPairGenerator API to generate ML-DSA key pairs 26 | // of the Signature API to sign and verify ML-DSA signatures, 27 | // and of the KeyFactory API to convert ML-DSA keys to and from their encodings 28 | KeyPairGenerator g = KeyPairGenerator.getInstance("ML-DSA"); 29 | g.initialize(NamedParameterSpec.ML_DSA_44); 30 | KeyPair kp = g.generateKeyPair(); // an ML-DSA-44 key pair 31 | 32 | byte[] msg = "Hello, Quantum!".getBytes(); 33 | Signature ss = Signature.getInstance("ML-DSA"); 34 | ss.initSign(kp.getPrivate()); 35 | ss.update(msg); 36 | byte[] sig = ss.sign(); 37 | 38 | // Verification step of the digital signature 39 | Signature verifier = Signature.getInstance("ML-DSA"); 40 | verifier.initVerify(kp.getPublic()); 41 | verifier.update(msg); 42 | boolean isValid = verifier.verify(sig); 43 | System.out.println("Signature valid: " + isValid); 44 | 45 | // Converting a ML-DSA private key to its PKCS #8 encoding, and vice-versa 46 | KeyFactory f = KeyFactory.getInstance("ML-DSA"); 47 | PKCS8EncodedKeySpec p8spec = f.getKeySpec(kp.getPrivate(), 48 | PKCS8EncodedKeySpec.class); 49 | PrivateKey sk2 = f.generatePrivate(p8spec); 50 | 51 | System.out.println("Original and reconstructed private keys are equal: " 52 | + java.util.Arrays.equals(kp.getPrivate().getEncoded(), sk2.getEncoded())); 53 | } catch (java.security.NoSuchAlgorithmException | java.security.InvalidAlgorithmParameterException 54 | | java.security.InvalidKeyException | java.security.SignatureException 55 | | java.security.spec.InvalidKeySpecException e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/org/javademos/java22/jep454/ForeignFunctionMemoryDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java22.jep454; 2 | 3 | import org.javademos.commons.IDemo; 4 | import java.lang.foreign.MemorySegment; 5 | import java.lang.foreign.Arena; 6 | import java.lang.foreign.ValueLayout; 7 | import java.lang.foreign.SymbolLookup; 8 | import java.lang.foreign.FunctionDescriptor; 9 | import java.lang.foreign.Linker; 10 | import java.lang.invoke.MethodHandle; 11 | 12 | /// Demo for JDK 22 feature JEP 454 - Foreign Function & Memory API. 13 | /// 14 | /// JEP history: 15 | /// - JDK 22: [JEP 454 - Foreign Function & Memory API](https://openjdk.org/jeps/454) 16 | /// - JDK 21: [JEP 442 - Foreign Function & Memory API (Third Preview)](https://openjdk.org/jeps/442) 17 | /// - JDK 20: [JEP 434 - Foreign Function & Memory API (Second Preview)](https://openjdk.org/jeps/434) 18 | /// - JDK 19: [JEP 424 - Foreign Function & Memory API (Preview)](https://openjdk.org/jeps/424) 19 | /// - JDK 18: [JEP 419 - Foreign Function & Memory API (Second Incubator)](https://openjdk.org/jeps/419) 20 | /// - JDK 17: [JEP 412 - Foreign Function & Memory API (Incubator)](https://openjdk.org/jeps/412) 21 | /// - JDK 16: [JEP 393 - Foreign-Memory Access API (Third Incubator)](https://openjdk.org/jeps/393) 22 | /// - JDK 16: [JEP 389 - Foreign Linker API (Incubator)](https://openjdk.org/jeps/389) 23 | /// - JDK 15: [JEP 383 - Foreign-Memory Access API (Second Incubator)](https://openjdk.org/jeps/383) 24 | /// - JDK 14: [JEP 370 - Foreign-Memory Access API (Incubator)](https://openjdk.org/jeps/370) 25 | /// 26 | /// Further reading: 27 | /// - [Inside Java: Foreign Function & Memory API](https://inside.java/2024/02/foreign-function-memory-api/) 28 | /// - [Baeldung: Guide to Foreign Function & Memory API](https://www.baeldung.com/java-foreign-function-memory-api) 29 | /// 30 | /// @author kishansingh956196@example.com 31 | public class ForeignFunctionMemoryDemo implements IDemo { 32 | @Override 33 | public void demo() { 34 | info(454); 35 | // Demo: Call C standard library 'strlen' using Foreign Function & Memory API 36 | try (Arena arena = Arena.ofConfined()) { 37 | String str = "Hello, JEP 454!"; 38 | byte[] utf8Bytes = (str + "\0").getBytes(java.nio.charset.StandardCharsets.UTF_8); 39 | MemorySegment cStr = arena.allocate(utf8Bytes.length, 1); 40 | cStr.asByteBuffer().put(utf8Bytes); 41 | SymbolLookup stdlib = SymbolLookup.libraryLookup("c", arena); 42 | Linker linker = Linker.nativeLinker(); 43 | MethodHandle strlen = linker.downcallHandle( 44 | stdlib.find("strlen").get(), 45 | FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS) 46 | ); 47 | long len = (long) strlen.invoke(cStr.address()); 48 | System.out.printf("C strlen('%s') = %d\n", str, len); 49 | } catch (Throwable t) { 50 | System.out.println("Foreign Function demo failed: " + t); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/javademos/java25/jep519/CompactObjectHeaderDemo.java: -------------------------------------------------------------------------------- 1 | package org.javademos.java25.jep519; 2 | 3 | import org.javademos.commons.IDemo; 4 | 5 | import org.openjdk.jol.info.ClassLayout; 6 | 7 | /// Demo for JDK 25 feature JEP 519 - Compact Object Headers. 8 | /// 9 | /// JEP history: 10 | /// - JDK 25: [JEP 519 - Compact Object Headers](https://openjdk.org/jeps/519) 11 | /// 12 | /// Further reading: 13 | /// - [Inside Java - JEP Café: Compact Object Headers](https://inside.java/2024/06/18/jepcafe-compactobjectheaders/) 14 | /// 15 | /// @see java.lang.Object 16 | /// 17 | /// @author @CodeSakshamY 18 | public class CompactObjectHeaderDemo implements IDemo { 19 | 20 | private static final int SAMPLE_COUNT = 5_000_000; 21 | 22 | @Override 23 | public void demo() { 24 | info(519); 25 | 26 | System.out.println("=== Minimal Example Objects ===\n"); 27 | 28 | Object obj1 = new Object(); 29 | Object obj2 = new Object(); 30 | 31 | System.out.println("Created two Objects:"); 32 | System.out.println("obj1 hash: " + obj1.hashCode()); 33 | System.out.println("obj2 hash: " + obj2.hashCode()); 34 | 35 | System.out.println("\nExplanation:"); 36 | System.out.println("- In JDK 24 and older, object headers are usually 128 bits (16 bytes)."); 37 | System.out.println("- In JDK 25 with JEP 519, most objects use compact 64-bit headers (8 bytes)."); 38 | System.out.println("- This reduces memory overhead, especially when many objects exist."); 39 | 40 | // ------------------------------------------------- 41 | // Part 1: Measure memory usage in pure Java 42 | System.out.println("\n=== Approximate Memory Usage Demo ==="); 43 | Runtime runtime = Runtime.getRuntime(); 44 | 45 | long before = runtime.totalMemory() - runtime.freeMemory(); 46 | 47 | Object[] objs = new Object[SAMPLE_COUNT]; 48 | for (int i = 0; i < SAMPLE_COUNT; i++) { 49 | objs[i] = new Object(); 50 | } 51 | 52 | long after = runtime.totalMemory() - runtime.freeMemory(); 53 | System.out.printf("Created %,d objects, approx memory used: %.2f MB%n", 54 | SAMPLE_COUNT, (after - before) / (1024.0 * 1024.0)); 55 | 56 | System.out.println("- Compare running this on JDK 21 vs JDK 25 to see memory savings."); 57 | 58 | // ------------------------------------------------- 59 | // Part 2: Optional JOL object header inspectio 60 | 61 | System.out.println("\n=== Object Header Layout (JOL) ==="); 62 | System.out.println("Object 1 layout:\n" + ClassLayout.parseInstance(obj1).toPrintable()); 63 | System.out.println("Object 2 layout:\n" + ClassLayout.parseInstance(obj2).toPrintable()); 64 | System.out.println("- Observe header size reduction in JDK 25 vs older versions."); 65 | 66 | 67 | System.out.println("\nTip: Use tools like jol-cli or jmap for more precise memory/layout measurements."); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/resources/JDK15Info.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "jep": 339, 4 | "jdk": 15, 5 | "name": "JEP 339 - Edwards-Curve Digital Signature Algorithm (EdDSA)", 6 | "dscr": "Implements cryptographic signatures using the Edwards-Curve Digital Signature Algorithm (EdDSA) as described in RFC 8032.", 7 | "link": false, 8 | "code": true 9 | }, 10 | { 11 | "jep": 360, 12 | "jdk": 15, 13 | "name": "JEP 360 - Sealed Classes (Preview)", 14 | "dscr": "Up-to-date demo in `org.javademos.java17.jep409.SealedDemo`.", 15 | "link": true, 16 | "code": false 17 | }, 18 | { 19 | "jep": 371, 20 | "jdk": 15, 21 | "name": "JEP 371 - Hidden Classes", 22 | "dscr": "Introduces hidden classes that cannot be used directly by bytecode of other classes and can be unloaded independently.", 23 | "link": false, 24 | "code": true 25 | }, 26 | { 27 | "jep": 372, 28 | "jdk": 15, 29 | "name": "JEP 372 - Remove the Nashorn JavaScript Engine", 30 | "dscr": "Remove the Nashorn JavaScript script engine, APIs, and the jjs tool.", 31 | "link": false, 32 | "code": false 33 | }, 34 | { 35 | "jep": 373, 36 | "jdk": 15, 37 | "name": "JEP 373 - Reimplement the Legacy DatagramSocket API", 38 | "dscr": "Modern reimplementation of DatagramSocket and DatagramSocketImpl using java.nio for improved maintainability and performance.", 39 | "link": false, 40 | "code": true 41 | }, 42 | { 43 | "jep": 375, 44 | "jdk": 15, 45 | "name": "JEP 375 - Pattern Matching for instanceof (Second Preview)", 46 | "dscr": "Up-to-date demo in `org.javademos.java16.jep394.InstanceofPatternMatchingDemo`.", 47 | "link": true, 48 | "code": false 49 | }, 50 | { 51 | "jep": 377, 52 | "jdk": 15, 53 | "name": "JEP 377 - ZGC: A Scalable Low-Latency Garbage Collector", 54 | "dscr": "Production-ready low-latency garbage collector maintaining sub-10ms pause times for large heaps.", 55 | "link": false, 56 | "code": false 57 | }, 58 | { 59 | "jep": 378, 60 | "jdk": 15, 61 | "name": "JEP 378 - Text Blocks", 62 | "dscr": "Demonstrates adding text blocks to the Java language.", 63 | "link": false, 64 | "code": true 65 | }, 66 | { 67 | "jep": 381, 68 | "jdk": 15, 69 | "name": "JEP 381 - Remove the Solaris and SPARC Ports", 70 | "dscr": "Removed the source code and build support for Solaris/SPARC, Solaris/x64, and Linux/SPARC ports. No code demo applicable.", 71 | "link": false, 72 | "code": false 73 | }, 74 | { 75 | "jep": 383, 76 | "jdk": 15, 77 | "name": "JEP 383 - Foreign-Memory Access API (Second Incubator)", 78 | "dscr": "Up-to-date demo in `org.javademos.java22.jep454.ForeignFunctionMemoryDemo`.", 79 | "link": true, 80 | "code": false 81 | }, 82 | { 83 | "jep": 384, 84 | "jdk": 15, 85 | "name": "JEP 384 - Records (Second Preview)", 86 | "dscr": "Up-to-date demo in `org.javademos.java16.jep395.RecordDemo`.", 87 | "link": true, 88 | "code": false 89 | } 90 | ] --------------------------------------------------------------------------------