Slide 1

Slide 1 text

Java 24 Overview 2025-04-11 Javaコミュ@福岡 Naoki Kishida

Slide 2

Slide 2 text

2 Java 24 ● Released March 18th ● Non LTS(Long Term Support) ● next LTS will be Java 25 on Sept. ● 24JEPs

Slide 3

Slide 3 text

3 see Qiita ● Search “Java 24”

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

The most since Java 10

Slide 6

Slide 6 text

Contributions

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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)

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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); } }

Slide 12

Slide 12 text

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!”); }

Slide 13

Slide 13 text

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); } } }

Slide 14

Slide 14 text

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)

Slide 15

Slide 15 text

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)

Slide 16

Slide 16 text

Small changes ● Reader.of(String) ● Unicode 16 ● External Specifications in Document ● https://docs.oracle.com/en/java/javase/24/docs/api/external-specs.html

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

404: Generational Shenandoah (Exper) ● Shenandoah GCに世代別アルゴリズムを導入 ● 非世代別アルゴリズムもそのまま維持される

Slide 23

Slide 23 text

450: Compact Object Headers (Exper) ● オブジェクトヘッダーに現状は12-16バイト使っているのを8バイ トに削減 ● 今後、デフォルト有効にしたあと現在のヘッダー用のコードを削 除する方向 ● メリット ● ヒープサイズが減る ● メモリ局所性があがる

Slide 24

Slide 24 text

475: Late Barrier Expansion for G1 ● G1GCでオブジェクトの整合性を保つためのバリアを効率化する

Slide 25

Slide 25 text

479: Remove the Windows 32-bit x86 Port ● Windows x86 32-bit向けのコードを削除

Slide 26

Slide 26 text

483: Ahead-of-Time Class Loading & Linking ● クラスを読み込んだ状態を保存して使い回すことでJVMの起動や ピークパフォーマンスまでの時間を短縮 ● Spring BootはDIが重いのであまり効果がない・・・ ● CRaCだとメモリ状態を保持するので有効 ● Linuxの仕組みを使うのでLinuxのみ

Slide 27

Slide 27 text

490: ZGC: Remove the Non-Generational Mode ● Java 21でZGCに世代別アルゴリズムが導入 ● Java 23で世代別ZGCがデフォルト ● ZGCで非世代別アルゴリズムを削除

Slide 28

Slide 28 text

491: Synchronize Virtual Threads without Pinning ● 仮想スレッドでsynchronizedブロックを動かすときにプラット フォームスレッドにピン留めしていた ● これがプラットフォームスレッドの枯渇やデッドロックの原因に なっていた ● ピン留めしないように変更

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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