Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Java 24まとめ / Java 24 summary

Java 24まとめ / Java 24 summary

2025年4月11日に開催のJavaコミュ@福岡での登壇資料です。
https://javaq.connpass.com/event/348733/

Naoki Kishida

April 11, 2025
Tweet

More Decks by Naoki Kishida

Other Decks in Programming

Transcript

  1. 2 Java 24 • Released March 18th • Non LTS(Long

    Term Support) • next LTS will be Java 25 on Sept. • 24JEPs
  2. JEPs • Language • 488: Primitive Types in Patterns, instanceof,

    and switch (Second Preview) • 492: Flexible Constructor Bodies (Third Preview) • 494: Module Import Declarations (Second Preview) • 495: Simple Source Files and Instance Main Methods (Fourth Preview) • API • 472: Prepare to Restrict the Use of JNI • 484: Class-File API • 485: Stream Gatherers • 487: Scoped Values (Fourth Preview) • 489: Vector API (Ninth Incubator) • 498: Warn upon Use of Memory-Access Methods in sun.misc.Unsafe • 499: Structured Concurrency (Fourth Preview) • Tool • 493: Linking Run-Time Images without JMODs • JVM • 404: Generational Shenandoah (Experimental) • 450: Compact Object Headers (Experimental) • 475: Late Barrier Expansion for G1 • 479: Remove the Windows 32-bit x86 Port • 483: Ahead-of-Time Class Loading & Linking • 490: ZGC: Remove the Non-Generational Mode • 491: Synchronize Virtual Threads without Pinning • Security • 478: Key Derivation Function API (Preview) • 486: Permanently Disable the Security Manager • 496: Quantum-Resistant Module-Lattice-Based Key Encapsulation Mechanism • 497: Quantum-Resistant Module-Lattice-Based Digital Signature Algorithm • JDK • 501: Deprecate the 32-bit x86 Port for Removal
  3. Tool & JDK • Small changes • jar command option

    • -dir, -C to specify dir, -keep-old-files to suppress overwrite • java some command option removed • -verbosegc, -noclassgc, -verify, -verifyremote, -ss, -ms, -mx • 493: Linking Run-Time Images without JMODs • 501: Deprecate the 32-bit x86 Port for Removal
  4. Language • 488: Primitive Types in Patterns, instanceof, and switch

    (Second Preview) • 492: Flexible Constructor Bodies (Third Preview) • 494: Module Import Declarations (Second Preview) • 495: Simple Source Files and Instance Main Methods (Fourth Preview)
  5. primitive types in pattern(preview) • primitive types are available in

    patten matching such as instanceof or switch • will not be standard in Java 25 • range check for primitive • like if expression
  6. 492: Flexible Constructor Bodies • `this`を使わないステートメントを`super`呼び出しの前に書ける • will be standard

    in Java 25 class Foo { Foo(List l1, List l2) { } } class Bar extends Foo { Bar() { // need same list? super(List.of("abc", "def"), List.of("abc", "def")); } } class Bar extends Foo { // need another constructor? private Bar(List l) { super(l, l); } Bar() { this(List.of("abc", "def")); } } class Bar extends Foo { Bar() { // flexible constructor body var param = List.of("abc", "def"); super(param, param); } } 同じリストをふたつの引数に渡すような処理が書きにくかった in Java 24 in Java 21
  7. Module Import Declarations(2nd preview) • import module java.base covers almost

    all • transitively require dependent modules • import module java.se covers all Java SE API • will be standard in Java 25 import module java.base; public class Main { public static void main(Stiring[] args) { var data = List.of(“apple”, “grape”); data.forEach(IO::println); } }
  8. Simple Source File and instance main method(4th prev.) • Java

    hello world will be more simple • currently we need to know many keywords, class, static, public,,, • main method can be package private, protected • main method can be instance method • main method does not require any argument • no class needed! • will be standard as Compact Source File and... in Java 25 void main() { System.out.println(“Hello world!”); }
  9. java.util.IO(preview) • since println is defined in IO class, System.out

    is not required import module java.base; import static java.lang.IO.*; public class Main { public static void main(Stiring[] args) { var data = List.of(“apple”, “grape”); for (var str : data) { println(str); } } }
  10. Simple sample code • when omit the class definition, java.base

    and java.util.IO will be imported automatically • (in java 25, IO will not be imported automatically)
  11. API • Small changes • 472: Prepare to Restrict the

    Use of JNI • 484: Class-File API • 485: Stream Gatherers • 487: Scoped Values (Fourth Preview) • 489: Vector API (Ninth Incubator) • 498: Warn upon Use of Memory-Access Methods in sun.misc.Unsafe • 499: Structured Concurrency (Fourth Preview)
  12. Small changes • Reader.of(String) • Unicode 16 • External Specifications

    in Document • https://docs.oracle.com/en/java/javase/24/docs/api/external-specs.html
  13. Prepare to Restrict the Use of JNI • Restrict native

    access as same as FFM • java –enable-native-access=ALL-UNNAMED • --illegal-native-access=allow / warn / deny
  14. Stream Gatherers • Streamでは、他のデータを参照する処理ができなかった • スライディングウィンドウなど • Stream Gathererで可能に •

    Gatherersは`collect`に対するCollectorsのように典型処理を まとめている jshell> IntStream.range(0, 10).boxed() .gather(Gatherers.windowFixed(3)) .toList() $1 ==> [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] jshell> IntStream.range(0, 10).boxed() .gather(Gatherers.windowSliding(3)) .toList() $2 ==> [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9]] windowFixed windowSliding
  15. Class-File API • API for parsing, modifying, and generating Java

    class file • external library such as ASM and Javassist • new feature support will be available after the new feature is released • the new feature cannot be used inside Java on development
  16. Vector API(9th Incubator) • invoke SIMD instructions like AVX from

    Java • planned to depend on the value class of Project Valhalla • stay an incubator until the related JEP is released
  17. JVM • 404: Generational Shenandoah (Experimental) • 450: Compact Object

    Headers (Experimental) • 475: Late Barrier Expansion for G1 • 479: Remove the Windows 32-bit x86 Port • 483: Ahead-of-Time Class Loading & Linking • 490: ZGC: Remove the Non-Generational Mode • 491: Synchronize Virtual Threads without Pinning
  18. 483: Ahead-of-Time Class Loading & Linking • クラスを読み込んだ状態を保存して使い回すことでJVMの起動や ピークパフォーマンスまでの時間を短縮 •

    Spring BootはDIが重いのであまり効果がない・・・ • CRaCだとメモリ状態を保持するので有効 • Linuxの仕組みを使うのでLinuxのみ
  19. 490: ZGC: Remove the Non-Generational Mode • Java 21でZGCに世代別アルゴリズムが導入 •

    Java 23で世代別ZGCがデフォルト • ZGCで非世代別アルゴリズムを削除
  20. 491: Synchronize Virtual Threads without Pinning • 仮想スレッドでsynchronizedブロックを動かすときにプラット フォームスレッドにピン留めしていた •

    これがプラットフォームスレッドの枯渇やデッドロックの原因に なっていた • ピン留めしないように変更
  21. Security • 478: Key Derivation Function API (Preview) • 486:

    Permanently Disable the Security Manager • 496: Quantum-Resistant Module-Lattice-Based Key Encapsulation Mechanism • 497: Quantum-Resistant Module-Lattice-Based Digital Signature Algorithm
  22. Quantum Resistant Algorithm • 496: Quantum-Resistant Module-Lattice-Based Key Encapsulation Mechanism

    • 497: Quantum-Resistant Module-Lattice-Based Digital Signature Algorithm • will back-port to LTS