Slide 1

Slide 1 text

Bonjour à tous, Java 23 ! NISHIKAWA, Akihiro

Slide 2

Slide 2 text

Agenda  Java 23  Java 23に含まれるJEPについて簡単に  その他

Slide 3

Slide 3 text

Java 23 Reference Implementation of version 23 of the Java SE Platform, as specified by JSR 398 in the Java Community Process.

Slide 4

Slide 4 text

Schedule 2024/06/06 Rampdown Phase One (branch from main line) 2024/07/18 Rampdown Phase Two 2024/08/08 Initial Release Candidate 2024/08/22 Final Release Candidate 2024/09/17 General Availability

Slide 5

Slide 5 text

Contributorの分布は、US時間2024/09/17の Sharat Chanderのブログエントリで発表されるはず

Slide 6

Slide 6 text

LTS or non-LTS ?  ほとんどのDistributorがnon-LTSに位置付けている  Oracleのポリシーを例にすると、LTSは2年ごと(次期LTSはJDK 25)  JDK 17  JDK 21  JDK 25  JDK 29 …  Distributorによっては、 non-LTSをリリースしないことがある  Microsoftは原則LTSのみリリース

Slide 7

Slide 7 text

LTSのサポート ライセンスは正しく読んで、正しく利用しましょう  JDK 17 approaches end-of-permissive license (oracle.com)  Oracle No-Fee Terms and Conditions (NFTC) からOTNライセンスに移行(2024/10/01)  Oracle Java SE、GraalVM EnterpriseのJDK 17を特定の環境以外で継続利用する場合は、サポート契約 が必要  特定の環境とは  Oracle Java SE License  Oracle Technology Network License Agreement for Oracle Java SEのCertain Useとは – Logico Inside (logico-jp.io)

Slide 8

Slide 8 text

【参考】 JDK 8のサポート期間は? Oracle Java SE 2030/12 (要サポート契約、Extended Support) Red Hat OpenJDK 2026/11 Eclipse Temurin 2026/11 Amazon Corretto 2026/7 Azul Zulu 2030/12

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

非公式(!) JDKアップグレードガイド Choosing the Right JDK Version: An Unofficial Guide (oracle.com)

Slide 11

Slide 11 text

JDK 23に含まれるJEP

Slide 12

Slide 12 text

Java 23に含まれるJEPは12個 Preview : 8 / Incubator : 1 / Removal : 1 specification 455 Primitive Types in Patterns, instanceof, and switch (Preview) 476 Module Import Declarations (Preview) 477 Implicitly Declared Classes and Instance Main Methods (Third Preview) 482 Flexible Constructor Bodies (Second Preview) core-libs 466 Class-File API (Second Preview) 469 Vector API (Eighth Incubator) 471 Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal 473 Stream Gatherers (Second Preview) 480 Structured Concurrency (Third Preview) 481 Scoped Values (Third Preview) hotspot 474 ZGC: Generational Mode by Default tools 467 Markdown Documentation Comments

Slide 13

Slide 13 text

JEPの機能フェーズ Incubator (JEP 11) Java APIの試験モジュール (jdk.incubator) フィードバックを受けて変更しやすくするための特別なモジュール -[add-modules jdk.incubator.xxxを指定して有効化 Preview (JEP 12) Java言語の試験機能 -[enable-previewを指定して有効化 コンパイル時にはJavaバージョンを指定 (-[source XXや-[release XX) Experimental GCやコンパイラなどのランタイム試験機能 機能ごとのオプション以外に、 -XX:+UnlockExperimentalVMOptionsを指定して有効化 Standard 上記試験フェーズを通じて標準機能に昇格した機能

Slide 14

Slide 14 text

Preview機能実行時のオプション設定 コンパイル時 javac --release 23 --enable-preview Main.java 実行時 java --enable-preview Main java --enable-preview Main.java Jshell実行時 jshell --enable-preview

Slide 15

Slide 15 text

JSR 398 (Java SE 23) JEP Dashboard - Java Bug System (openjdk.org)

Slide 16

Slide 16 text

JEP 465: String Templates (Third Preview) は取り下げ  設計が煮詰まっていないので、JDK 23ではPreviewとしてリリースしない  JDK 22のPreviewに対するフィードバックはいつでも歓迎 “The time has come for us to decide what to do about this feature with respect to JDK 23. Given that there is support for a change in the design but a lack of clear consensus on what that new design might look like, the prudent course of action is to (i) NOT ship the current design as a preview feature in JDK 23, and (ii) take our time continuing the design process. We all agree that our favourite language deserves us taking whatever time is needed to perfect our design! Preview features are exactly intended for this - for trying out mature designs before we commit to them for all time. Sometimes we are going to want to change our minds. So, to be clear: there will be no string template feature, even with --enable-preview, in JDK 23. For those of you experimenting with string templates in JDK 22 - please continue to do so, and share your experiences with us. This is the best form of feedback! (We really don’t need, for example, reminders of what other languages do - we have done all that extensive research already. But we don’t know about your application; kick the tires and maybe you’ll unearth something. Play around and send us your feedback - good or bad.)” Update on String Templates (JEP 459) (openjdk.org)

Slide 17

Slide 17 text

Specification related

Slide 18

Slide 18 text

Specification related (4) specification 455 Primitive Types in Patterns, instanceof, and switch (Preview) 476 Module Import Declarations (Preview) 477 Implicitly Declared Classes and Instance Main Methods (Third Preview) 482 Flexible Constructor Bodies (Second Preview) core-libs 466 Class-File API (Second Preview) 469 Vector API (Eighth Incubator) 471 Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal 473 Stream Gatherers (Second Preview) 480 Structured Concurrency (Third Preview) 481 Scoped Values (Third Preview) hotspot 474 ZGC: Generational Mode by Default tools 467 Markdown Documentation Comments

Slide 19

Slide 19 text

455 Primitive Types in Patterns, instanceof, and switch (Preview) 目的 すべてのパターン・コンテキストでプリミティブ型のパターンを許可、パターン・マッチ ングを強化 instanceofとswitchを拡張し、すべてのプリミティブ型で動作するように (Project Amber) int、byte、floatなどの異なるプリミティブ型間のテストや変換がシンプルに これまで switchおよびinstanceofでは、プリミティブ型に対するパターンマッチングは 非サポート Recordパターンでのプリミティブ型のサポートに制限あり

Slide 20

Slide 20 text

switch、instanceofでプリミティブ型をサポート long[] l ={1L, 2L, 10_000_000_000L, 10L}; for(long v: l) { switch (v) { case 1L -> System.out.println("いち"); case 2L -> System.out.println("にぃ"); case 10_000_000_000L -> System.out.println("たくさん"); default -> System.out.println("あやしいやつ"); } } int[] i = {1, 129}; for(int v: i) { if( v instanceof byte b ) System.out.println(v + "はbyteの範囲 / " + b); else System.out.println(v + "はbyteの範囲にはない"); }

Slide 21

Slide 21 text

パターンマッチング float[] f={0f,1f,2f,0}; for(float v:f) { float ff = switch (v) { // caseでは、0fではなく、0にしてしまうとエラー case 0 -> 5f; case float x when x == 1f -> 6f + x; case float x -> 7f + x; }; System.out.printf("ff=[%f]\n",ff); }

Slide 22

Slide 22 text

476 Module Import Declarations (Preview) 目的 モジュールがエクスポートするすべてのパッケージを簡潔にインポートする 開発者、特に初心者がライブラリや標準クラスを利用しやすくできる 複数のimportの必要性が減り、パッケージ階層を知る必要がなくなる 注意 モジュール全体インポート時の注意 複数のパッケージに同じ単純な名前のクラスが含まれている場合、名前が曖昧 になる危険性があるため、目的の型を明示的にインポートする必要がある import module M;

Slide 23

Slide 23 text

モジュールインポート時の注意点 /[ Error import module java.base; /[ java.util.Listをエクスポート import module java.desktop; /[ java.awt.Listをエクスポート List l = .[[ /[ どちらを指すかわからないのでエラー /[ Good import java.sql.Date; /[ 明示的に指定(java.util.Dateではなく) Date d = .[[ /[ java.sql.Date

Slide 24

Slide 24 text

477 Implicitly Declared Classes and Instance Main Methods (Third Preview) 目的 Java言語を進化させて、初学生が最初のプログラムを心折られずに書けるよう にする 後々大規模プログラム向けに設計された言語機能を理解していけばよいように モジュールがエクスポートするすべてのパッケージを簡潔にインポートする JEP 445、 JEP 463 からの変更 新たなjava.io.IOクラスから、以下の3静的メソッドを自動的にインポート ͩ JEP 476と関連ͪ !java.baseモジュールからすべてのpublicのトップレベル・ クラスとインターフェイスを自動的にインポート(java.util.Listのような一 般的に使用されるAPIに対する明示的なインポート文が不要に) public static void println(Object obj); public static void print(Object obj); public static String readln(String prompt);

Slide 25

Slide 25 text

Implicit declared classesの例 /[ Implicit declared classes void main() { println("Hello World!"); } /[ Traditional public class Main { public static void main(String.[[ args) { System.out.println("Hello World!"); } }

Slide 26

Slide 26 text

JEP 476との合わせ技 /[ JEP 476+477 void main() { var authors = List.of("James", "Bill", "Guy", "Alex", "Dan", "Gavin"); for (var name : authors) { println(name + ": " + name.length()); } } /[ Traditional import java.util.List; public class Main { void main() { var authors = List.of("James", "Bill", "Guy", "Alex", "Dan", "Gavin"); for (var name : authors) { System.out.println(name + ": " + name.length()); } } }

Slide 27

Slide 27 text

482 Flexible Constructor Bodies (Second Preview) 目的 開発者がコンストラクタの動作をより自由に表現できるように これまで 補助staticメソッド、補助中間コンストラクタ、またはコンストラクタ引数に組み 込む必要があった JEP 447: Statements before super(...) (Preview) のアップデート Head toward Java 22 and Java 23 - Speaker Deck 変更点 (機能追加) コンストラクタを明示的に呼び出す前に、コンストラクタ本体が同クラスのフィール ドを初期化できるようにする クラスのインスタンス化時に、コンストラクタがトップダウンの順序で実行されると いう既存の保証は維持する

Slide 28

Slide 28 text

[Q] new Sub(42)の呼び出しでどんな挙動を示す? class Super { Super() { overriddenMethod(); } void overriddenMethod() { System.out.println("hello"); } } class Sub extends Super { final int x; Sub(int x) { /* super(); 暗黙の呼び出し */ this.x = x; } @Override void overriddenMethod() { System.out.println(x); } } class JEP482 { public static void main(String... args) { Sub sub = new Sub(42); } }

Slide 29

Slide 29 text

[Q] new Sub(42)の呼び出しでどんな挙動を示す? class Super { Super() { overriddenMethod(); } void overriddenMethod() { System.out.println("hello"); } } class Sub extends Super { final int x; Sub(int x) { /* super(); 暗黙の呼び出し */ this.x = x; } @Override void overriddenMethod() { System.out.println(x); } } class JEP482 { public static void main(String... args) { Sub sub = new Sub(42); } }

Slide 30

Slide 30 text

JEP 482:フィールド初期化後、明示的にコンストラクタを呼ぶ class Super { Super() { overriddenMethod(); } void overriddenMethod() { System.out.println("hello"); } } class Sub extends Super { final int x; Sub(int x) { this.x = x; // フィールド初期化 super(); // Superのコンストラクタ } @Override void overriddenMethod() { System.out.println(x); } } class JEP482 { public static void main(String... args) { Sub sub = new Sub(42); } }

Slide 31

Slide 31 text

Core-libs related

Slide 32

Slide 32 text

Core-libs related (6) specification 455 Primitive Types in Patterns, instanceof, and switch (Preview) 476 Module Import Declarations (Preview) 477 Implicitly Declared Classes and Instance Main Methods (Third Preview) 482 Flexible Constructor Bodies (Second Preview) core-libs 466 Class-File API (Second Preview) 469 Vector API (Eighth Incubator) 471 Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal 473 Stream Gatherers (Second Preview) 480 Structured Concurrency (Third Preview) 481 Scoped Values (Third Preview) hotspot 474 ZGC: Generational Mode by Default tools 467 Markdown Documentation Comments

Slide 33

Slide 33 text

466 Class-File API (Second Preview) 目的 3rdパーティのASM ライブラリから脱却できるよう、JVM仕様が定義するクラス ファイルの解析・生成・変換のための標準APIを用意する(JDKコンポーネントが 標準APIに移行) 変更点 (機能追加) JEP 457: Class-File API (Preview) のフィードバックを受けたアップデート • CodeBuilderクラスを整理 • AttributesのAttributeMapperインスタンスにstaticメソッドでアクセス可能に • Signature.TypeArgを代数的データ型に変更 • 型を意識する、ClassReader.readEntryOrNullと ConstantPool.entryByIndexを追加 • インデックスにあるエントリが目的の型でない場合に、ClassCastExceptionの代わ りにConstantPoolExceptionをスロー • その他改良や修正など

Slide 34

Slide 34 text

469 Vector API (Eighth Incubator) 目的 Single Instruction Multiple Data (SIMD) 演算のサポート • ベクトル演算のサポート • ベクトル演算を最適なハードウェアレジスタとベクトル命令にコンパイルするC2コンパイラ 変更 JEP 460: Vector API (Seventh Incubator) からのAPI変更はない 注意 Project Valhallaの必要機能がプレビュー機能として利用可能になるまで、 Vector APIはIncubatorのまま • Valhallaの機能がプレビューになる時点で、Vector APIとその実装を適応させ、Vector APIが インキュベーションからプレビューに昇格する予定

Slide 35

Slide 35 text

471 Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal 目的 sun.misc.Unsafeのメモリアクセスメソッドを廃止・削除対象に 移行先 VarHandle API (JEP 193) : オンヒープメモリの操作 Foreign Function & Memory API (JEP 454) : オフヒープメモリの操作 今後の 予定 Phase 1 : イマココ Phase 2 : 遅くともJDK 25までには、対象のメソッドを利用している場合、実行 時に警告 Phase 3 : JDK 26以後で、デフォルトで例外をスロー Phase 4/5 : JDK 26より先でメソッドを削除

Slide 36

Slide 36 text

473 Stream Gatherers (Second Preview) 目的 ストリーム・パイプラインの柔軟性と表現力を高めたい 可能な限り、カスタム中間演算で無限サイズのストリームを操作できるようにし たい 変更 JEP 461: Stream Gatherers (Preview) からの変更はない 詳細はJava 22リリース記念のスライドを参照 • Head toward Java 22 and Java 23 - Speaker Deck

Slide 37

Slide 37 text

480 Structured Concurrency (Third Preview) 目的 スレッドリークやキャンセル遅延など、キャンセルやシャットダウンに起因する一般 的なリスクを排除できる並列・並行プログラミングのスタイルを確立したい 並列コードのObservabilityを向上させたい 変更 JEP 462: Structured Concurrency (Second Preview) からの変更はない 詳細はJava 22リリース記念のスライドを参照 • Head toward Java 22 and Java 23 - Speaker Deck

Slide 38

Slide 38 text

481 Scoped Values (Third Preview) 目的 スレッド内の呼び出し元と子スレッドの両方でImmutableデータを共有できるよ うにしたい 共有データのライフサイクルを推論しやすくしたい 変更 JEP 464: Scoped Values (Second Preview) からのアップデート • ScopedValue.callWhereメソッドのoperationパラメータの型が関数インターフェースに • Javaコンパイラがチェック例外がスローする可能性があるかどうかを推測できるように • ScopedValue.getWhereメソッドの削除

Slide 39

Slide 39 text

Hotspot related

Slide 40

Slide 40 text

Hotspot related (1) specification 455 Primitive Types in Patterns, instanceof, and switch (Preview) 476 Module Import Declarations (Preview) 477 Implicitly Declared Classes and Instance Main Methods (Third Preview) 482 Flexible Constructor Bodies (Second Preview) core-libs 466 Class-File API (Second Preview) 469 Vector API (Eighth Incubator) 471 Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal 473 Stream Gatherers (Second Preview) 480 Structured Concurrency (Third Preview) 481 Scoped Values (Third Preview) hotspot 474 ZGC: Generational Mode by Default tools 467 Markdown Documentation Comments

Slide 41

Slide 41 text

474 ZGC: Generational Mode by Default  JEP 439で導入されたGenerational ZGCがZGCのデフォルトに  これまでのデフォルト(非世代別ZGC)は今後廃止・削除予定 -XX:+UseZGC • 世代別ZGCを利用(デフォルト) -XX:+UseZGC -XX:+ZGenerational • 世代別ZGCを利用 • ZGenerationalは廃止対象なので、 警告メッセージが出る -XX:+UseZGC -XX:-ZGenerational • 世代別ZGCを利用しない • ZGenerationalは廃止対象、非世 代別ZGCも廃止・削除予定なので、警 告メッセージが出る

Slide 42

Slide 42 text

Tools related

Slide 43

Slide 43 text

Tools related (1) specification 455 Primitive Types in Patterns, instanceof, and switch (Preview) 476 Module Import Declarations (Preview) 477 Implicitly Declared Classes and Instance Main Methods (Third Preview) 482 Flexible Constructor Bodies (Second Preview) core-libs 466 Class-File API (Second Preview) 469 Vector API (Eighth Incubator) 471 Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal 473 Stream Gatherers (Second Preview) 480 Structured Concurrency (Third Preview) 481 Scoped Values (Third Preview) hotspot 474 ZGC: Generational Mode by Default tools 467 Markdown Documentation Comments

Slide 44

Slide 44 text

467 Markdown Documentation Comments  JavaDocドキュメントのコメントを、Markdownで書けるようにする  より書きやすく、読みやすいソース形式のドキュメントコメントを実現  これまで、 HTMLとJavaDocの@タグの混合で記載していた 旧来 Markdown コメント /** .[[ *[ /[[ 改行

1行あける 箇条書きの行頭文字

  • - Codeタグ {@code .[[} `.[[` (backticks) Link {@link .[[} 参照リンクの拡張 [equals][#equals(Object)]

Slide 45

Slide 45 text

JEP 467: Markdown Documentation Comments (openjdk.org)

Slide 46

Slide 46 text

その他

Slide 47

Slide 47 text

Compatibility and Specification Review (CSR) Issue Navigator - Java Bug System (openjdk.org)

Slide 48

Slide 48 text

アノテーション処理ポリシーの変更  javacでアノテーション処理を有効にするには、-proc:$policy で明示的 に指定する必要がある  JDK 23からのデフォルト設定は -proc:none [JDK-8321319] Reinstate disabling the compiler's default active annotation processing - Java Bug System (openjdk.org) 意味 ポリシー 備考 アノテーション処理せずにコンパイル none JDK 6 以降から存在 コンパイルせずにアノテーション処理 only JDK 6 以降から存在 アノテーション処理後にコンパイル full JDK 22 以前ではデフォルトの動作だが、この値自体は新規 Quality Outreach Heads-up - JDK 23: Changes Default Annotation Processing Policy – Inside.java

Slide 49

Slide 49 text

COMPATロケールプロバイダーの廃止  Common Locale Data Repository(共通ロケールデータリポジトリ)  Unicode Consortium(Unicodeコンソーシアム)が2003年に作成、ロケールデータを管理 JDK 8 JRE/COMPAT:JDKのレガシーデータコレクション(デフォルト) CLDR:CLDRのデータ システムプロパティ java.locale.providers で選択できる カスタムロケールプロバイダの実装が可能 JDK 9 デフォルトロケールデータプロバイダをCLDRに変更 JDK 21 JRE/COMPAT利用時に警告表示 JDK 23 JRE/COMPATの削除 [JDK-8325568] Remove legacy locale data (COMPAT, JRE) from the JDK - Java Bug System (openjdk.org) JEP 252: Use CLDR Locale Data by Default (openjdk.org) [JDK-8174269] Remove COMPAT locale data provider from JDK - Java Bug System (openjdk.org)

Slide 50

Slide 50 text

Subject.getSubject API  JDK18以降で、Security Manager APIに依存しない、新しいJava認証認可 サービス (JAAS) APIが利用可能なので、置き換えを強く推奨  システムプロパティjava.security.manager設定値による挙動変化 以下のいずれかを設定 • 空の文字列 • クラス名 • allow 以前のリリースと同じ (変更なし) 値を設定していない、もしくは以下を設定 • Disallow Subject.getSubjectを呼び出すと UnsupportedOperationExceptionをスロー [JDK-8296244] Alternate implementation of user-based authorization Subject APIs that doesn’t depend on Security Manager APIs - Java Bug System (openjdk.org)

Slide 51

Slide 51 text

詳細は、Early-Access Release Notesを参照 JDK 23 Early-Access Release Notes (java.net)  [JDK-8303689] javac -Xlint could/should report on "dangling" doc comments - Java Bug System (openjdk.org)  [JDK-8329636] Deprecate -XX:+PreserveAllAnnotations - Java Bug System (openjdk.org)  [JDK-8320786] Remove ThreadGroup.stop - Java Bug System (openjdk.org)  [JDK-8320532] Remove Thread/ThreadGroup suspend/resume - Java Bug System (openjdk.org)  [JDK-8315767] InetAddress: constructing objects from BSD literal addresses - Java Bug System (openjdk.org)  [JDK-8329222] java.text.NumberFormat (and subclasses) spec updates - Java Bug System (openjdk.org)  [JDK-8331202] Support for Duration until another Instant - Java Bug System (openjdk.org)  [JDK-8330276] Console methods with explicit Locale - Java Bug System (openjdk.org)  [JDK-8330005] RandomGeneratorFactory.getDefault() throws exception when the runtime image only has java.base module - Java Bug System (openjdk.org) などなど

Slide 52

Slide 52 text

New APIs in Java 23 - javaalmanac.io

Slide 53

Slide 53 text

Thank you