$30 off During Our Annual Pro Sale. View Details »

Javaは今どこに向かっているのか

 Javaは今どこに向かっているのか

2023-04-26 Java on Azure Day 2023

Yuichi.Sakuraba

April 26, 2023
Tweet

More Decks by Yuichi.Sakuraba

Other Decks in Programming

Transcript

  1. Javaは今どこに向かっているのか
    櫻庭 祐一

    View Slide

  2. OpenJDK JDK Project
    Project Amber
    Java によるデータ指向プログラミング
    の主要な新機能
    Java 17 21
    から

    View Slide

  3. Java 17 21
    から の主要な新機能
    OpenJDK JDK Project

    View Slide

  4. OpenJDK JDK Project
    https://openjdk.org/projects/jdk/
    のサブプロジェクト
    JDK Project: OpenJDK
    JDK 21 2023-09-19
    JDK 20 2023-03-21
    半年ごとのリリース
    JDK
    他のサブプロジェクトをまとめて を開発
    Oracle Java 21
    は から 2 年周期
    LTS Oracle
    は などのディストリビュータによる
    Note: OpenJDK LTS LTS
    には と非 の区別はない

    View Slide

  5. JEP: JDK Enhancement Proposal
    の機能を規定
    JDK
    新機能だけでなく、実装改善、機能の削除も含む
    Preview
    Standard 正式な機能
    の種類
    JEP
    Incubator
    Experimental
    プレビュー機能
    実験的な機能
    新しいモジュール
    ex. Records
    ex. HTTP Client
    ex. ZGC
    Note: Preview, Experimental, Incubator は最低 2 回

    View Slide

  6. JEP: JDK Enhancement Proposal
    の機能を規定
    JDK
    新機能だけでなく、実装改善、機能の削除も含む
    Preview
    Standard 正式な機能
    の種類
    JEP
    Incubator
    Experimental
    プレビュー機能
    実験的な機能
    新しいモジュール
    ex. Records
    ex. HTTP Client
    ex. ZGC
    Note: Preview, Experimental, Incubator は最低 2 回

    View Slide

  7. JEP: JDK Enhancement Proposal
    Java 18
    400: UTF-8 by Default
    408: Simple Web Server
    413: Code Snippets in Java API Documentation
    416: Reimplement Core Re ection with Method Handles
    417: Vector API (Third Incubator)
    418: Internet-Address Resolution SPI
    419: Foreign Function & Memory API (Second Incubator)
    420: Pattern Matching for switch (Second Preview)
    421: Deprecate Finalization for Removal
    Java 19
    405: Record Patterns (Preview)
    422: Linux/RISC-V Port
    424: Foreign Function & Memory API (Preview)
    425: Virtual Threads (Preview)
    426: Vector API (Fourth Incubator)
    427: Pattern Matching for switch (Third Preview)
    428: Structured Concurrency (Incubator)
    Java 20
    429: Scoped Values (Incubator)
    432: Record Patterns (Second Preview)
    433: Pattern Matching for switch (Fourth Preview)
    434: Foreign Function & Memory API (Second Preview)
    436: Virtual Threads (Second Preview)
    437: Structured Concurrency (Second Incubator)
    438: Vector API (Fifth Incubator)
    Java 21
    430: String Templates (Preview)
    431: Sequenced Collections
    442: Foreign Function & Memory API (Third Preview)
    444: Virtual Threads
    . . .

    View Slide

  8. JEP: JDK Enhancement Proposal
    Java 18
    400: UTF-8 by Default
    408: Simple Web Server
    413: Code Snippets in Java API Documentation
    416: Reimplement Core Re ection with Method Handles
    417: Vector API (Third Incubator)
    418: Internet-Address Resolution SPI
    419: Foreign Function & Memory API (Second Incubator)
    420: Pattern Matching for switch (Second Preview)
    421: Deprecate Finalization for Removal
    Java 19
    405: Record Patterns (Preview)
    422: Linux/RISC-V Port
    424: Foreign Function & Memory API (Preview)
    425: Virtual Threads (Preview)
    426: Vector API (Fourth Incubator)
    427: Pattern Matching for switch (Third Preview)
    428: Structured Concurrency (Incubator)
    Java 20
    429: Scoped Values (Incubator)
    432: Record Patterns (Second Preview)
    433: Pattern Matching for switch (Fourth Preview)
    434: Foreign Function & Memory API (Second Preview)
    436: Virtual Threads (Second Preview)
    437: Structured Concurrency (Second Incubator)
    438: Vector API (Fifth Incubator)
    Java 21
    430: String Templates (Preview)
    431: Sequenced Collections
    442: Foreign Function & Memory API (Third Preview)
    444: Virtual Threads
    . . .

    View Slide

  9. JEP 400: UTF-8 by default
    デフォルトファイルエンコーディングを に統一
    UTF-8
    java.io
    InputStreamReader, FileReader, OutputStreamWriter, FileWriter, PrintStream
    java.util
    Formatter, Scanner
    java.net
    URLEncoder, URLDecoder
    影響をうけるクラス
    でデフォルトエンコーディングで を
    使用している場合、要注意
    Windows Windows-31J
    -D le.encoding =COMPAT
    従来通りのファイルエンコーディングを使用するには
    起動オプション

    View Slide

  10. JEP 431: Sequenced Collections
    最初と最後の要素にアクセスできるインタフェース
    SequencedCollection
    SequencedSet
    SequencedMap

    View Slide

  11. JEP 444: Virtual Threads
    by Project Loom
    が管理する軽量スレッド
    JVM
    待ち時間を活用することでスループット向上
    I/O
    アプリケーションなど通信を多用するシステムに効果的
    Web
    使い方は従来の とほぼ同じ
    Thread
    への対応
    Virtual Treads
    なども対応予定
    Spring Framework
    Helidon Nima
    Oracle JDBC Driver

    View Slide

  12. Javaによるデータ指向プログラミング
    Project Amber

    View Slide

  13. Project Amber
    言語仕様の改良と拡張を行うプロジェクト
    286: Local-Variable Type Inference (var) (10)
    323: Local-Variable Syntax for Lambda Parameters (11)
    361: Switch Expressions (14)
    378: Text Blocks (15)
    394: Pattern Matching for instanceof (16)
    395: Records (16)
    409: Sealed Classes (17)
    仕様策定完了
    仕様策定中
    430: String Templates (Preview)
    440: Record Patterns
    441: Pattern Matching for switch
    443: Unnamed Patterns and Variables (Preview)
    445: Flexible Main Methods and Anonymous Main Classes (Preview)
    447: Statements before super()

    View Slide

  14. Project Amber

    395: Records
    409: Sealed Classes
    447: Statements before super()
    361: Switch Expressions
    394: Pattern Matching for instanceof
    440: Record Patterns
    441: Pattern Matching for switch
    443: Unnamed Patterns and Variables (Preview)
    パターンマッチング
    286: Local-Variable Type Inference (var)
    323: Local-Variable Syntax for Lambda Parameters
    378: Text Blocks
    430: String Templates (Preview)
    445: Flexible Main Methods and Anonymous Main Classes (Preview)
    その他

    View Slide

  15. Records
    イミュータブルなデータを表す専用のクラス
    例 座標を表すクラス Boilerplate

    View Slide

  16. Records
    イミュータブルなデータを表す専用のクラス
    例 座標を表すクラス

    View Slide

  17. Records
    イミュータブルなデータを表す専用のクラス
    例 座標を表すクラス
    クラス
    nal
    インタフェースは実装できるが、他のクラスから継承はできない
    メソッドの追加も可能

    View Slide

  18. Sealed Class
    継承を制限したクラス
    例 図形を表すクラス

    View Slide

  19. Sealed Class
    継承を制限したクラス
    例 図形を表すクラス
    で定義
    sealed permitsでサブクラスを制限
    サブクラスは同モジュールもしくは同パッケージ
    サブクラスは以下のいずれかで定義
    nal
    sealed
    non-sealed
    使用時
    switch default句を省略できる

    View Slide

  20. Switch Expression
    文から
    switch 式へ
    switch

    View Slide

  21. Switch Expression
    文から
    switch 式へ
    switch
    矢印で記述

    View Slide

  22. Switch Expression
    文から
    switch 式へ
    switch
    処理が 1 行であればカッコ省略可

    View Slide

  23. Switch Expression
    文から
    switch 式へ
    switch
    であればdefault
    enum, selaed class 句省略可

    View Slide

  24. Switch Expression
    文から
    switch 式へ
    switch
    式 値が返せる
    switch

    View Slide

  25. Switch Expression
    文から
    switch 式へ
    switch
    処理をカッコでくくる時は
    で値を返す
    yield

    View Slide

  26. Pattern Matching
    パターンマッチング 入力に対し特定のパターンと照合すること
    適合した場合、その要素を取りだすこと
    パターンとして型を使用
    JEP 394, 440, 441

    View Slide

  27. Pattern Matching

    View Slide

  28. Pattern Matching
    Boilerplate!

    View Slide

  29. Pattern Matching

    View Slide

  30. Pattern Matching

    View Slide

  31. Pattern Matching

    View Slide

  32. Data Oriented Programming
    ドメインモデルの実装では ...
    データ
    業務ルール

    View Slide

  33. Data Oriented Programming
    ドメインモデルの実装では ...
    データ
    業務ルール
    データ指向プログラミングの原則 #1 は、
    コードをデータから切り離すことである
    “データ指向プログラミング” より引用

    View Slide

  34. Data Oriented Programming
    ドメインモデルの実装では ...
    データ
    業務ルール
    リソース
    値オブジェクト
    イベント
    ...
    ステートレスな処理
    型として表現する
    モジュールとして表現する
    ( 型として扱う必要はない )
    イミュータブルであることが重要

    View Slide

  35. 映画のチケットで考えてみる
    映画のチケットは席の種類と、
    チケットの区分によって値段が異なるとする
    席はプレミア席と一般席
    チケットの区分は一般、学生、シニアの 3 種類

    View Slide

  36. 映画のチケットで考えてみる
    料金を計算する

    View Slide

  37. 映画のチケットで考えてみる
    式で記述
    switch

    View Slide

  38. 映画のチケットで考えてみる
    のパターンマッチングを利用
    Recordのパターンマッチングを利用
    Record

    View Slide

  39. 映画のチケットで考えてみる
    をさらに分解
    Record

    View Slide

  40. 映画のチケットで考えてみる
    をさらに分解
    Record 式で処理を分けるより
    switch
    テンプレートメソッドパターンで記述すればいいのでは?
    業務ルールが複数のクラスに分散してしまい、
    見通しが悪くなる
    データ間の関係 ( 関連、コンポジッション ) と
    処理間の関係 ( 使用 ) が混在しまい、複雑になりがち
    業務ルールは処理によって必要とするデータも変化する

    View Slide

  41. DOP OOP
    適材適所
    : DOP
    ドメインモデル
    : OOP
    バウンダリー
    バウンダリーのフレームワークに則った記述

    View Slide

  42. Conclusion
    月リリース予定
    Java 21 LTS 9
    Virtual Threads などが導入予定
    パターンマッチングなどデータ指向プログラミングに向けた機能
    Project Amber
    Java 21 String Templateが
    パターンマッチングはさらに拡張される予定
    で Preview

    View Slide