Top Banner
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 1 祝 Java SE 8 祝祝祝祝祝祝 Yoshio Terada Java Evangelist http://yoshio3.com Twitter : @yoshioterada
107

Java SE 8 New Features

May 08, 2015

Download

Technology

Java SE 8 explanation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved1

祝 Java SE 8 正式リリース

Yoshio TeradaJava Evangelisthttpyoshio3comTwitter yoshioterada

Copyright copy 2014 Oracle andor its affiliates All rights reserved2

以下の事項は弊社の一般的な製品の方向性に関する概要を説明するものですまた情報提供を唯一の目的とするものでありいかなる契約にも組み込むことはできません以下の事項はマテリアルやコード機能を提供することをコミットメント(確約)するものではないため購買決定を行う際の判断材料になさらないで下さいオラクル製品に関して記載されている機能の開発リリースおよび時期については弊社の裁量により決定されます

Oracle は米国オラクルコーポレーション及びその子会社関連会社の米国及びその他の国における登録商標です文中の社名商品名等は各社の商標または登録商標である場合があります

Copyright copy 2014 Oracle andor its affiliates All rights reserved3

Java SE 6 Java SE 7 Java SE 8 Java SE 9

2006 年 12 月 2011 年 07 月 2014 年 03 月 2016 年

Java リリースの歴史

Copyright copy 2014 Oracle andor its affiliates All rights reserved4

Java SE 6

2006 年 12 月

Java SE 6 の新機能

2006 年 12 月 11 日

Java SE 5 を改良したバージョン  Web サービス  JavaScript エンジン Rhino を組み込み  AWTSwing ライブラリの改善  Java DB の統合  JDBC の改善  など 

Copyright copy 2014 Oracle andor its affiliates All rights reserved5

Java SE 7

2011 年 07 月

Java SE 7 がリリースされるまで

2010 年 9 月 8 日タイトル Re-thinking JDK 7

Plan A JDK 7 (as currently defined) Mid 2012

Plan B JDK 7 Mid 2011 (minus Lambda Jigsaw and part of Coin) JDK 8 Late 2012 (Lambda Jigsaw the rest of Coin ++)

Plan B 早く実装が可能な一部機能を先にリリース

Copyright copy 2014 Oracle andor its affiliates All rights reserved6

Java SE 7

2011 年 07 月

Java SE 7 の新機能

開発生産性向上と Java SE 8 の準備

  Project Coin  Java NIO2   ForkJoin Framework  InvokeDynamic バイトコード命令

Copyright copy 2014 Oracle andor its affiliates All rights reserved7

Java SE 8

2014 年 03 月

Java SE 8 リリースまでの道のり 1

2012 年 7 月 17 日タイトル Project Jigsaw Late for the train

I think the best choice is to defer Project Jigsaw to Java 9 and to aim for a two-year release cycle going forward

On this plan Java 8 will ship on time around September 2013

Jigsaw の検討実装検証に時間が足りないため次の Java SE 9 へ持ち越し

Java SE 8

2013 年 9 月

Copyright copy 2014 Oracle andor its affiliates All rights reserved8

Java SE 8 リリースまでの道のり 2

2013 年 4 月 18 日タイトル Java 8 Secure the train

As a consequence of this renewed focus on security the Java 8 schedule with a GA release in early September is no longer achievable

then resume a regular two-year release cadence with Java 8 due in early 2014 and Java 9 in early 2016Java 開発者がセキュリティ脆弱性対応に集中しリリース日を 2013 年 9 月から 2014 年初旬に変更

Java SE 8

2014 年初旬

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 2: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved2

以下の事項は弊社の一般的な製品の方向性に関する概要を説明するものですまた情報提供を唯一の目的とするものでありいかなる契約にも組み込むことはできません以下の事項はマテリアルやコード機能を提供することをコミットメント(確約)するものではないため購買決定を行う際の判断材料になさらないで下さいオラクル製品に関して記載されている機能の開発リリースおよび時期については弊社の裁量により決定されます

Oracle は米国オラクルコーポレーション及びその子会社関連会社の米国及びその他の国における登録商標です文中の社名商品名等は各社の商標または登録商標である場合があります

Copyright copy 2014 Oracle andor its affiliates All rights reserved3

Java SE 6 Java SE 7 Java SE 8 Java SE 9

2006 年 12 月 2011 年 07 月 2014 年 03 月 2016 年

Java リリースの歴史

Copyright copy 2014 Oracle andor its affiliates All rights reserved4

Java SE 6

2006 年 12 月

Java SE 6 の新機能

2006 年 12 月 11 日

Java SE 5 を改良したバージョン  Web サービス  JavaScript エンジン Rhino を組み込み  AWTSwing ライブラリの改善  Java DB の統合  JDBC の改善  など 

Copyright copy 2014 Oracle andor its affiliates All rights reserved5

Java SE 7

2011 年 07 月

Java SE 7 がリリースされるまで

2010 年 9 月 8 日タイトル Re-thinking JDK 7

Plan A JDK 7 (as currently defined) Mid 2012

Plan B JDK 7 Mid 2011 (minus Lambda Jigsaw and part of Coin) JDK 8 Late 2012 (Lambda Jigsaw the rest of Coin ++)

Plan B 早く実装が可能な一部機能を先にリリース

Copyright copy 2014 Oracle andor its affiliates All rights reserved6

Java SE 7

2011 年 07 月

Java SE 7 の新機能

開発生産性向上と Java SE 8 の準備

  Project Coin  Java NIO2   ForkJoin Framework  InvokeDynamic バイトコード命令

Copyright copy 2014 Oracle andor its affiliates All rights reserved7

Java SE 8

2014 年 03 月

Java SE 8 リリースまでの道のり 1

2012 年 7 月 17 日タイトル Project Jigsaw Late for the train

I think the best choice is to defer Project Jigsaw to Java 9 and to aim for a two-year release cycle going forward

On this plan Java 8 will ship on time around September 2013

Jigsaw の検討実装検証に時間が足りないため次の Java SE 9 へ持ち越し

Java SE 8

2013 年 9 月

Copyright copy 2014 Oracle andor its affiliates All rights reserved8

Java SE 8 リリースまでの道のり 2

2013 年 4 月 18 日タイトル Java 8 Secure the train

As a consequence of this renewed focus on security the Java 8 schedule with a GA release in early September is no longer achievable

then resume a regular two-year release cadence with Java 8 due in early 2014 and Java 9 in early 2016Java 開発者がセキュリティ脆弱性対応に集中しリリース日を 2013 年 9 月から 2014 年初旬に変更

Java SE 8

2014 年初旬

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 3: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved3

Java SE 6 Java SE 7 Java SE 8 Java SE 9

2006 年 12 月 2011 年 07 月 2014 年 03 月 2016 年

Java リリースの歴史

Copyright copy 2014 Oracle andor its affiliates All rights reserved4

Java SE 6

2006 年 12 月

Java SE 6 の新機能

2006 年 12 月 11 日

Java SE 5 を改良したバージョン  Web サービス  JavaScript エンジン Rhino を組み込み  AWTSwing ライブラリの改善  Java DB の統合  JDBC の改善  など 

Copyright copy 2014 Oracle andor its affiliates All rights reserved5

Java SE 7

2011 年 07 月

Java SE 7 がリリースされるまで

2010 年 9 月 8 日タイトル Re-thinking JDK 7

Plan A JDK 7 (as currently defined) Mid 2012

Plan B JDK 7 Mid 2011 (minus Lambda Jigsaw and part of Coin) JDK 8 Late 2012 (Lambda Jigsaw the rest of Coin ++)

Plan B 早く実装が可能な一部機能を先にリリース

Copyright copy 2014 Oracle andor its affiliates All rights reserved6

Java SE 7

2011 年 07 月

Java SE 7 の新機能

開発生産性向上と Java SE 8 の準備

  Project Coin  Java NIO2   ForkJoin Framework  InvokeDynamic バイトコード命令

Copyright copy 2014 Oracle andor its affiliates All rights reserved7

Java SE 8

2014 年 03 月

Java SE 8 リリースまでの道のり 1

2012 年 7 月 17 日タイトル Project Jigsaw Late for the train

I think the best choice is to defer Project Jigsaw to Java 9 and to aim for a two-year release cycle going forward

On this plan Java 8 will ship on time around September 2013

Jigsaw の検討実装検証に時間が足りないため次の Java SE 9 へ持ち越し

Java SE 8

2013 年 9 月

Copyright copy 2014 Oracle andor its affiliates All rights reserved8

Java SE 8 リリースまでの道のり 2

2013 年 4 月 18 日タイトル Java 8 Secure the train

As a consequence of this renewed focus on security the Java 8 schedule with a GA release in early September is no longer achievable

then resume a regular two-year release cadence with Java 8 due in early 2014 and Java 9 in early 2016Java 開発者がセキュリティ脆弱性対応に集中しリリース日を 2013 年 9 月から 2014 年初旬に変更

Java SE 8

2014 年初旬

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 4: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved4

Java SE 6

2006 年 12 月

Java SE 6 の新機能

2006 年 12 月 11 日

Java SE 5 を改良したバージョン  Web サービス  JavaScript エンジン Rhino を組み込み  AWTSwing ライブラリの改善  Java DB の統合  JDBC の改善  など 

Copyright copy 2014 Oracle andor its affiliates All rights reserved5

Java SE 7

2011 年 07 月

Java SE 7 がリリースされるまで

2010 年 9 月 8 日タイトル Re-thinking JDK 7

Plan A JDK 7 (as currently defined) Mid 2012

Plan B JDK 7 Mid 2011 (minus Lambda Jigsaw and part of Coin) JDK 8 Late 2012 (Lambda Jigsaw the rest of Coin ++)

Plan B 早く実装が可能な一部機能を先にリリース

Copyright copy 2014 Oracle andor its affiliates All rights reserved6

Java SE 7

2011 年 07 月

Java SE 7 の新機能

開発生産性向上と Java SE 8 の準備

  Project Coin  Java NIO2   ForkJoin Framework  InvokeDynamic バイトコード命令

Copyright copy 2014 Oracle andor its affiliates All rights reserved7

Java SE 8

2014 年 03 月

Java SE 8 リリースまでの道のり 1

2012 年 7 月 17 日タイトル Project Jigsaw Late for the train

I think the best choice is to defer Project Jigsaw to Java 9 and to aim for a two-year release cycle going forward

On this plan Java 8 will ship on time around September 2013

Jigsaw の検討実装検証に時間が足りないため次の Java SE 9 へ持ち越し

Java SE 8

2013 年 9 月

Copyright copy 2014 Oracle andor its affiliates All rights reserved8

Java SE 8 リリースまでの道のり 2

2013 年 4 月 18 日タイトル Java 8 Secure the train

As a consequence of this renewed focus on security the Java 8 schedule with a GA release in early September is no longer achievable

then resume a regular two-year release cadence with Java 8 due in early 2014 and Java 9 in early 2016Java 開発者がセキュリティ脆弱性対応に集中しリリース日を 2013 年 9 月から 2014 年初旬に変更

Java SE 8

2014 年初旬

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 5: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved5

Java SE 7

2011 年 07 月

Java SE 7 がリリースされるまで

2010 年 9 月 8 日タイトル Re-thinking JDK 7

Plan A JDK 7 (as currently defined) Mid 2012

Plan B JDK 7 Mid 2011 (minus Lambda Jigsaw and part of Coin) JDK 8 Late 2012 (Lambda Jigsaw the rest of Coin ++)

Plan B 早く実装が可能な一部機能を先にリリース

Copyright copy 2014 Oracle andor its affiliates All rights reserved6

Java SE 7

2011 年 07 月

Java SE 7 の新機能

開発生産性向上と Java SE 8 の準備

  Project Coin  Java NIO2   ForkJoin Framework  InvokeDynamic バイトコード命令

Copyright copy 2014 Oracle andor its affiliates All rights reserved7

Java SE 8

2014 年 03 月

Java SE 8 リリースまでの道のり 1

2012 年 7 月 17 日タイトル Project Jigsaw Late for the train

I think the best choice is to defer Project Jigsaw to Java 9 and to aim for a two-year release cycle going forward

On this plan Java 8 will ship on time around September 2013

Jigsaw の検討実装検証に時間が足りないため次の Java SE 9 へ持ち越し

Java SE 8

2013 年 9 月

Copyright copy 2014 Oracle andor its affiliates All rights reserved8

Java SE 8 リリースまでの道のり 2

2013 年 4 月 18 日タイトル Java 8 Secure the train

As a consequence of this renewed focus on security the Java 8 schedule with a GA release in early September is no longer achievable

then resume a regular two-year release cadence with Java 8 due in early 2014 and Java 9 in early 2016Java 開発者がセキュリティ脆弱性対応に集中しリリース日を 2013 年 9 月から 2014 年初旬に変更

Java SE 8

2014 年初旬

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 6: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved6

Java SE 7

2011 年 07 月

Java SE 7 の新機能

開発生産性向上と Java SE 8 の準備

  Project Coin  Java NIO2   ForkJoin Framework  InvokeDynamic バイトコード命令

Copyright copy 2014 Oracle andor its affiliates All rights reserved7

Java SE 8

2014 年 03 月

Java SE 8 リリースまでの道のり 1

2012 年 7 月 17 日タイトル Project Jigsaw Late for the train

I think the best choice is to defer Project Jigsaw to Java 9 and to aim for a two-year release cycle going forward

On this plan Java 8 will ship on time around September 2013

Jigsaw の検討実装検証に時間が足りないため次の Java SE 9 へ持ち越し

Java SE 8

2013 年 9 月

Copyright copy 2014 Oracle andor its affiliates All rights reserved8

Java SE 8 リリースまでの道のり 2

2013 年 4 月 18 日タイトル Java 8 Secure the train

As a consequence of this renewed focus on security the Java 8 schedule with a GA release in early September is no longer achievable

then resume a regular two-year release cadence with Java 8 due in early 2014 and Java 9 in early 2016Java 開発者がセキュリティ脆弱性対応に集中しリリース日を 2013 年 9 月から 2014 年初旬に変更

Java SE 8

2014 年初旬

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 7: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved7

Java SE 8

2014 年 03 月

Java SE 8 リリースまでの道のり 1

2012 年 7 月 17 日タイトル Project Jigsaw Late for the train

I think the best choice is to defer Project Jigsaw to Java 9 and to aim for a two-year release cycle going forward

On this plan Java 8 will ship on time around September 2013

Jigsaw の検討実装検証に時間が足りないため次の Java SE 9 へ持ち越し

Java SE 8

2013 年 9 月

Copyright copy 2014 Oracle andor its affiliates All rights reserved8

Java SE 8 リリースまでの道のり 2

2013 年 4 月 18 日タイトル Java 8 Secure the train

As a consequence of this renewed focus on security the Java 8 schedule with a GA release in early September is no longer achievable

then resume a regular two-year release cadence with Java 8 due in early 2014 and Java 9 in early 2016Java 開発者がセキュリティ脆弱性対応に集中しリリース日を 2013 年 9 月から 2014 年初旬に変更

Java SE 8

2014 年初旬

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 8: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved8

Java SE 8 リリースまでの道のり 2

2013 年 4 月 18 日タイトル Java 8 Secure the train

As a consequence of this renewed focus on security the Java 8 schedule with a GA release in early September is no longer achievable

then resume a regular two-year release cadence with Java 8 due in early 2014 and Java 9 in early 2016Java 開発者がセキュリティ脆弱性対応に集中しリリース日を 2013 年 9 月から 2014 年初旬に変更

Java SE 8

2014 年初旬

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 9: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved9

Java SE 8 リリースまでの道のり 3

2013 年 4 月 26 日タイトル Java 8 Hold the train

The target release date for Java 8 is now 2014318

Java SE 8

2014 年 03月

最終的なリリース予定日を 318 に決定

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 10: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved10

祝 Java SE 8 正式リリース2014 年 03 月 18 日

>

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 11: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved11

JSR- 337 Java SE 8

Compact Profile

JavaScript JSR-308 Type AnnotationJSR-310 Date and Time

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 12: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved12

Java SE 7 と Java SE 8 の関係

Java SE 7 の主要な新機能

Project CoinJava NIO2

ForkJoin FrameworkInvokeDynamic

Java SE 8 の主要な新機能

Lambda 式Stream APINashorn (JavaScript)

利用と改善

Date amp Time APIType AnnotationCompact ProfileJavaFX の統合Java VM の統合

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 13: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved13

Project Lambda

Lambda 式

Streaming API

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 14: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved14

SPARC T1 (2005年 )8 x 4 =

32SPARC T2 (2007年 )8 x 8 =

64SPARC T3 (2011年 )16 x 8 =

128

マルチコア時代

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 15: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved15

Java SE 7 で導入ForkJoin フレームワークの概念 ( 粒度小 )

大きな問題を細かい問題に分割し分割した問題を個別に解決した後最後に結果を集計

大きな問題

細かい

問題

細かい

問題

細かい

問題

個別

処理

個別

処理

個別

処理

結合結果

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 16: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved16

ここで登場 Lambda

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 17: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved17

Lambda 式とは

後から実行するコードブロックの実装を簡潔に記述するための手法

( 匿名インナークラスの簡易記法+ α)

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 18: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved18

Functional( 関数型 ) インタフェース

FunctionalInterfacepublic interface Runnable public abstract void run()

実装すべきメソッドが一つのインタフェースLambda 式 ( メソッド参照)のターゲット型

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 19: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved19

Functional( 関数型 ) インタフェース

javalangRunnablejavaniofilePathMatcherjavautilComparatorjavautilconcurrentCallablejavautilloggingFilter

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 20: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved20

javautilfunction パッケージ

httpdocsoraclecomjavasejp8apijavalangclass-useFunctionalInterfacehtml

Java SE 8 より追加 43 個の関数型インタフェースを含む

インタフェース名 引数 返り値 説明PredicateltTgt T boolean 1 つの引数を受け取り boolean を返すConsumerltTgt T void 1つの引数を受け取り結果を返さないFunctionltTRgt T R 1 つの引数を受け取り結果を生成するSupplierltTgt 無し T 完了結果の取得UnaryOperationltTgt T T 単項演算(引数と返り値が同じ)BinaryOperationltTgt (T T) T 2項演算(引数を2つ取り返り値が同

じ)

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 21: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved21

これは関数型インタフェース

FunctionalInterfacepublic interface SomeFunctionalInterface public boolean equals(Object object)

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 22: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved22Copyright copy 2014 Oracle andor its affiliates All rights reserved22

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

1 匿名インナークラスとして実装

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 23: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved23Copyright copy 2014 Oracle andor its affiliates All rights reserved23

ExecutorService service = servicesubmit(new Runnable() Override public void run() 非同期に処理するタスク doSomething() )

-gt

2 インナークラス名メソッド名を削除 メソッドの引数とメソッドボディの間に -gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 24: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved24Copyright copy 2014 Oracle andor its affiliates All rights reserved24

ExecutorService service =

servicesubmit(() -gt doSomething())

単一の abstract メドッドを持つ関数型インタフェースを書き換え可能

Java SE 8 ラムダ式

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 25: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved25Copyright copy 2014 Oracle andor its affiliates All rights reserved25

このコードはどこが問題 (JavaSE7)

int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

エラー ローカル変数 a は内部クラスからアクセスされます final で宣言される必要があります

final int a = 0

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 26: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved26Copyright copy 2014 Oracle andor its affiliates All rights reserved26

Java SE 8 は実質的に final ならば可 int a = 0 Runnable run = new Runnable() Override public void run() Systemoutprintln(a) ExecutorService exec =        ExecutorsnewSingleThreadExecutor() execsubmit(run)

更新されない値 ( 実質的に final) の参照ならばコンパイルエラーにはなりません

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 27: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved27

Stream API

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 28: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved28Copyright copy 2014 Oracle andor its affiliates All rights reserved28

拡張 for 文による操作 (JavaSE7) ListltStringgt list = ArraysasList(aaa bbb ccc abc)

for (String data list) if (datastartsWith(a)) Systemoutprintln(data)

先頭が a で始まる文字列を出力

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 29: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved29

Stream API とは

コレクションに対するバルク ( 一括 ) 処理が可能

Lambda 式を使用し可読性向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 30: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved30

Stream API による実装 ( パイプライン処理 )終端操作が呼び出されるまで処理は未実行

Stream の生成

Streamof()Streamempty()Streamgenerate()liststream()

中間操作

filtermapmapToIntflatMapdistinctsortedlimitskip など

終端操作

forEachforEachOrderedtoArrayreducecollectminmaxcountなど

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 31: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved31Copyright copy 2014 Oracle andor its affiliates All rights reserved31

Stream の生成

Stream stream =      Streamof(aaa bbb cccrdquo rdquoabcrdquo)

ListltStringgt list = ArraysasList(aaa bbb ccc ldquoabcrdquo)Stream listStream = liststream()

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 32: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved32Copyright copy 2014 Oracle andor its affiliates All rights reserved32

Stream API による操作 (JavaSE8)

ListltStringgt list = ArraysasList(aaa bbb ccc abc)

liststream() filter(Predicatelt super Tgt predicate) forEach(Consumerlt super Tgt action)

if 文を filter で置き換えfor 文を forEach で置き換え

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 33: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved33Copyright copy 2014 Oracle andor its affiliates All rights reserved33

PredicateConsumer インタフェース

FunctionalInterfacepublic interface PredicateltTgt boolean test(T t)

FunctionalInterfacepublic interface ConsumerltTgt void accept(T t)

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 34: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved34Copyright copy 2014 Oracle andor its affiliates All rights reserved34

Stream によるコレクション操作匿名インナークラスで実装 ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 35: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved35Copyright copy 2014 Oracle andor its affiliates All rights reserved35

Lambda 式に変換メソッドの引数とボディを残し間に矢印 -gt を挿入

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 36: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved36Copyright copy 2014 Oracle andor its affiliates All rights reserved36

型推論の改善型情報 (String) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 37: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved37Copyright copy 2014 Oracle andor its affiliates All rights reserved37

メソッド引数部分の括弧 () の省略単一引数の場合 () を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 38: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved38Copyright copy 2014 Oracle andor its affiliates All rights reserved38

単一行のブロックを省略単一行の場合ブロック (return) を省略可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 39: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved39

メソッド参照コンストラクタ参照

Lambda 式で単に既存のメソッドを呼び出す場合メソッド参照の記法で簡易的に記述可能

(String data) -gt Systemoutprintln(data)

Systemoutprintln

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 40: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved40

メソッド参照コンストラクタ参照

ラムダ式 メソッド参照 メソッド参照の種類() -gt ClassstaticMethod()

ClassstaticMethod

クラスの static メソッドへの参照

() -gt objectmethod() objectmethod オブジェクトのインスタンスメソッドへの参照

t -gt tmethod() Classmethod 同一クラス任意オブジェクトのインスタンスメソッドへの参照

() -gt new Class() Classnew コンストラクタへの参照

引数が存在する場合宣言順に渡される

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 41: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved41Copyright copy 2014 Oracle andor its affiliates All rights reserved41

メソッド参照による書き換え

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(new PredicateltStringgt() public boolean test(String data)   return datastartsWith(a) ) forEach(new ConsumerltStringgt() public void accept(String data) Systemoutprintln(data) )

-gt

-gt

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 42: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved42Copyright copy 2014 Oracle andor its affiliates All rights reserved42

Lambda 式 と Stream API 最終形式 Lambda 式により簡潔に記述可能

ListltStringgt list =    ArraysasList(aaa bbb ccc abc) liststream()   filter(data -gt datastartsWith(ardquo)) forEach(Systemoutprintln)

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 43: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved43Copyright copy 2014 Oracle andor its affiliates All rights reserved43

例題俳優のフィルタリング

public class Actor Integer id ID String firstName 名前 String lastName 名字 Integer age 年齢 String prefecture 出身の都道府県名 hellip コンストラクタ Setter Getter は省略

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 44: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved44Copyright copy 2014 Oracle andor its affiliates All rights reserved44

例題大河ドラマ(官兵衛)出演俳優

ListltActorgt users = ArraysasList( new Actor(1 ldquo岡田rdquo ldquo准一rdquo 33 ldquo 大阪府rdquo ) new Actor(2 ldquo柴田rdquo ldquo恭兵rdquo 62 ldquo静岡県rdquo ) new Actor(3 ldquo江口rdquo ldquo洋介rdquo 46 ldquo東京都rdquo ) new Actor(4 ldquo竹中rdquo ldquo直人rdquo 58 ldquo神奈川県rdquo ) new Actor(5 谷原 章介rdquo 41 ldquo神奈川県rdquo ) new Actor(6 春風亭 小朝rdquo 59 ldquo東京都rdquo ) new Actor(7 寺尾 聰rdquo 67 ldquo神奈川県rdquo ) new Actor(8 速水 もこみちrdquo 29 ldquo東京都rdquo ) new Actor(9 片岡 鶴太郎rdquo 59 ldquo東京都rdquo ) new Actor(10 ldquo金子 ノブアキrdquo 33 ldquo東京都rdquo ))

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 45: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved45Copyright copy 2014 Oracle andor its affiliates All rights reserved45

例題年齢順にソートusersstream() sorted( 年齢順にソート (act1 act2) -gtact1agecompareTo(act2age)) forEach(Systemoutprintln)

8 速水 もこみち 29 東京都1 岡田 准一 33 大阪府10 金子 ノブアキ 33 東京都5 谷原 章介 41 神奈川県3 江口 洋介 46 東京都4 竹中 直人 58 神奈川県6 春風亭 小朝 59 東京都9 片岡 鶴太郎 59 東京都2 柴田 恭兵 62 静岡県7 寺尾 聰 67 神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 46: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved46Copyright copy 2014 Oracle andor its affiliates All rights reserved46

例題出身県名一覧の表示

usersstream() map(actor -gt actorgetPrefecture()) distinct() 重複文字列を削除 forEach(Systemoutprintln)

map () Actor から String オブジェクト (出身地の県名 ) を取得し新たな Stream を生成

大阪府静岡県東京都神奈川県

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 47: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved47Copyright copy 2014 Oracle andor its affiliates All rights reserved47

例題出身県名一覧の取得 (List)

ListltStringgt prefectures = user2stream() map(actor -gt actorgetPrefecture()) distinct() collect(CollectorstoList())

collect () Stream の処理結果別のオブジェクト (List Set Map など ) で値を取得したい場合 collect() を使用

ユーティリティファクトリクラス Collectors

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 48: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved48Copyright copy 2014 Oracle andor its affiliates All rights reserved48

例題 40歳以上の人数を取得

long count = user2stream()  filter(actor -gt actorage gt 40)  count()Systemoutprintln(40歳以上はrdquo + count+ 名 )

40 歳以上は 7 名

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 49: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved49

Lambda 式ご利用時のご注意

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 50: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved50

Lambda ご使用時の注意

Lambda 式は匿名インナークラスの書き方を単に書きかえた物ではありません

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 51: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved51

1 匿名インナークラスを実装したクラス

import javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier supplier = new Supplier() Override public String get() return Hello

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 52: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved52

1 匿名インナークラスを含むクラスを  コンパイルgt javac Testjavagt lsTest$1classTestclassTestjava

匿名インナークラスを含むクラスをコンパイルするとクラス名 $class を生成

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 53: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved53

1 匿名インナークラスを使用した場合

gt javap -c Test

public static void main(javalangString) Code 0 new 2 class Test$1 3 dup 4 invokespecial 3 Method Test$1ltinitgt()V 7 astore_1 8 return

実行時インスタンスを生成して呼び出す

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 54: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved54

1 Lambda 式を含むクラスを  コンパイルimport javautilfunctionSupplierpublic class Test public static void main(String argv) Supplier s = () -gt Hello

gt javac Testjavagt lsTestclassTestjava   Test$1class クラスは未作成

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 55: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved55

gt javap -p Test

Compiled from Testjavapublic class Test public Test() public static void main(javalangString) private static javalangObject lambda$main$0()

1 生成されたクラスを確認

Lambda 式を使用すると同一クラス内にプライベートメソッドを追加

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 56: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved56

1 内部的に InvokeDyanamic を使用

gt javap -c Test

public static void main(javalangString) Code 0 invokedynamic 2 0 InvokeDynamic 0get()LjavautilfunctionSupplier 5 astore_1 6 return

Lambda 式を使用すると内部的に Java SE 7 で追加された InvokeDynamic バイトコード命令を実行

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 57: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved57

2 ボディ内で this スコープの違い

SupplierltStringgt anInner = new SupplierltStringgt() Override public String get() return thisgetClass()toString() CompletableFuturesupplyAsync(anInner)thenAccept(Systemoutprintln)

SupplierltStringgt lambda = () -gt thisgetClass()toString()CompletableFuturesupplyAsync(lambda)thenAccept(Systemoutprintln)

Test$1 を返す

Test を返す

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 58: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved58

Java SE 8 CompletableFuture

Java SE 8 で導入されたCompletableFuture

+Java EE 7 で導入されたConcurrency Utilities

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 59: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved59

その他本資料で説明していない項目

bull プリミティブ型の Stream (IntStream など )

bull Parallel Stream (Parallel Aray)bull Stream の全機能bull Optional Typebull 例外ハンドリングbull デフォルトメソッドbull インタフェース内の static メソッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 60: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved60

参考情報

bull IT Pro 連載記事「詳解 Java SE 8」をご参照httpitpronikkeibpcojparticleCOLUMN20140212536246

bull JJUG 「祝 Java 8 Launch」httpwwwjava-usersjpp=917

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 61: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved61

JSR- 310 Date amp Time API

日付処理の開発容易性が向上

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 62: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved62

Date amp Time API の目的

javautilDatejavautilCalendarjavautilTimeZonejavatextDateFormat

これらの API の置き換え用の新しい API を定義イミュータブルスレッドセーフISO-8601 の国際標準規格に準拠

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 63: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved63

Date amp Time API の主要なクラス

LocalDateTime

LocalDate LocalTime

人間的 ( 日時 )

ZonedDateTime

Instantシステム的 (瞬間 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 64: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved64

プログラムでどのような時間処理が必要

どれを利用するかは処理内容によって選ぶ必要があり

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 65: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved65

LocalDateタイムゾーン時間情報は無し LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

警告

3週間前

新しいカード送信

3週間前の午前2時

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 66: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved66

LocalDate現在の年月日を取得 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日LocalDate regDate = LocalDatenow()

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 67: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved67

LocalDate年月日の加減処理 (plus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 68: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved68

LocalDate年月日の前後比較 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

作成

2014 年 6 月 14日

有効期間

2017 年 6 月 14日

有効期間 3 年間期限切れ

2018 年 1 月 1 日

LocalDate regDate = LocalDatenow()LocalDate expireDate = regDateplusYears(3)LocalDate afterDate = LocalDateof(2018 1 1)if (expireDateisBefore(afterDate)) hellip

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 69: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved69

LocalDate年月日の加減処理 (minus) LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

有効期間

2017 年 6 月 14日

警告

3週間前

LocalDate expireDate = regDateplusYears(3)LocalDate warnDate = expireDateminusWeeks(3)

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 70: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved70

LocalDate年月日の調整 TemporalAdjuster

import static javatimetemporalTemporalAdjusterslastDayOfMonthhellipLocalDate regDate = LocalDatenow()LocalDate lastDay = regDatewith(TemporalAdjusterslastDayOfMonth)LocalDate lastDay = regDatewith(lastDayOfMonth) スッキリ

import static javatimetemporalTemporalAdjustersnextimport static javatimeDayOfWeekMONDAYhellipLocalDate regDate = LocalDatenow()LocalDate nextMonDay = regDatewith(TemporalAdjustersnext(DayOfWeekMONDAY))LocalDate nextMonDay2 = regDatewith(next(DayOfWeekMONDAY))LocalDate nextMonDay3 = regDatewith(next(MONDAY)) スッキリ

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 71: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved71

LocalDate年月日に時間情報を付加 LocalDateTime

LocalDate LocalTime

日本で使用するクレジットカードの作成から有効期限まで

警告日付

3週間前

新しいカード送信

3週間前の午前2時

LocalDate warnDate = expireDateminusWeeks(3)LocalDateTime sendCardDateTime = warnDateatTime(2 0)

LocalDate から LocalDateTime への変換

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 72: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved72

LocalDatePeriod 日付間の差を取得 LocalDateTime

LocalDate LocalTime

Period period = Periodbetween(regDate warnDate)Long days = ChronoUnitDAYSbetween(regDate warnDate)Systemoutprintln( 警告送信まで + periodgetYears() + 年 + periodgetMonths() + ヶ月 + periodgetDays() + 日 ( + days + 日 ))

警告送信まで 2 年 11ヶ月 10 日 (1075 日 )

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 73: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved73

LocalTime時間処理タイムゾーン日付無し LocalDateTime

LocalDate LocalTime

LocalTime lTime = LocalTimenow()LocalTime noon = LocalTimeof(12 00)if (lTimeisAfter(noon)) LocalTime dinnerTime = noonplusHours(8)minusMinutes(30)withNano(0)LocalTime trunTime = lTimetruncatedTo(ChronoUnitMINUTES)LocalDateTime ldateTime = lTimeatDate(LocalDatenow())

タイムゾーン日付の情報が不要なナノ秒単位の時間操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 74: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved74

LocalDateTimeタイムゾーン情報無し LocalDateTime

LocalDate LocalTime

タイムゾーンが不要な日時処理

2014 年 06 月 25 日午後 6 時

2015 年 01 月 01 日午前 0 時

正月まで 6ヶ月+6日+6時間

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 75: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved75

LocalDateTimeLocalDate + LocalTime LocalDateTime

LocalDate LocalTime

LocalDateTime today = LocalDateTimenow() LocalDateTime today = LocalDateTimeof(2014 MonthJUNE 25 18 0)2014-06-25T180000LocalDateTime nextNewYear   =       todayplusMonths(6)plusDays(6)plusHours(6)2015-01-01T0000LocalDateTime firstMonday = newYear2with(next(MONDAY))2015-01-05T0000

タイムゾーン情報が不要な日時操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 76: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved76

Instant

Instant start = Instantnow()bar()Instant end = Instantnow()

Instant の比較には Duration を使用Duration dur = Durationbetween(start end)long mills = durtoMillis()Systemoutprintln( メソッドの実行時間 + mills)

ある瞬間における時間を扱う

Instant瞬間の時間を操作

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 77: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved77

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)ZoneId jap = ZoneIdof(AsiaTokyo)ZonedDateTime jpTimeZone = ZonedDateTimeof(startJUG jap)2014-07-25T1800+0900[AsiaTokyo]String format = DateTimeFormatter ofPattern(yyyyMMdd(E) a HHmm)format(jpTimeZone)20140725( 金 ) 午後 1800ZoneId los = ZoneIdof(AmericaLos_Angeles) ZonedDateTime losTimeZone = jpTimeZonewithZoneSameInstant(los)2014-07-25T0200-0700[AmericaLos_Angeles]

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 78: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved78

ZonedDateTime

LocalDateTime startJUG = LocalDateTimeof(2014 MonthJULY 25 18 00)

String formatter2 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日 (E) a HHmm)format(jpStartDateTime)

西暦 2014 年 07 月 25 日 ( 月 ) 午後 1800

JapaneseDate jdate = JapaneseDatefrom(startJUG) String formatter3 = DateTimeFormatterofPattern(Gy 年 MM 月 dd 日(E))format(jdate)

平成 26 年 07 月 25 日 ( 水 ) ( ISO-8601 での実装を推奨)

LocalDateTime + ZoneId (UTC からのオフセット )

ZonedDateTimeタイムゾーンを含む日時を扱う

日時の加減演算でサマータイム対応

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 79: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved79

IoT の時代に Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 80: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved80

今後 10 年

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 81: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved81

500億のデバイス

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 82: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved82

全てが繋がる時代へ

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 83: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved83

Java SE 8 Compact プロファイル

各 API にどのプロファイルで利用可能か記載されている

参考 httpsblogsoraclecomjtcentrya_first_look_at_compact

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 84: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved84

デモ

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 85: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved85

IoT with WebSocket

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 86: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved86

LEGO(Java SE Embedded) amp Java EE 7WebSocket デモの構成

GlassFish v401Java SE8EE 7

Java SE8Embedded

LEGO MindStorms の操作命令を送信

LEGO MindStorms の状態情報を送信

WebSocketLEGO

エンドポイント

WebSocketサーバ

エンドポイント

WebSocketブラウザ

エンドポイント

JSON

JSON

JSON

JSON

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 87: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved87

ブラウザから LEGO マインドストームを操作WebSocket でリアムタイム IoT 通信

ブラウザからの命令 前後左右への移動 停止スピードアップダウン

LEGO からの情報 超音波センサーデータの表示

JSON でデータ送受信しRMI に比べ低オーバヘッド

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 88: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved88

Java SE 8EE 7 だけで実現

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 89: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved89

今後 10 年も Java

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 90: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved90

Java SE 8 (JSR 337)新機能

bull JSR-308 Annotations on typesbull JSR-310 Date and Time APIbull JSR-335 Lambda expressions

更新機能bull JSR-114 JDBC Rowsetsbull JSR-160 JMX Remote APIbull JSR-199 Java Compiler APIbull JSR-173 Streaming API for XMLbull JSR-221 JDBC 40bull JSR-269 Pluggable Annotation-Processing API

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 91: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved91

Language

Core Libraries

Virtual machine

Security

Platform

Internationalisation

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 92: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved92

カテゴリ JEP ID 新機能の概要

---- 126 Lambda 式 と 仮想的な拡張メソッド (default method)

---- 138 Autoconf-Based のビルドシステム

---- 160 Lambda-Form Representation for Method Handles

---- 161 コンパクトプロファイル

---- 162 モジュール化への準備

---- 164 AES 暗号化のために CPU 命令の活用

---- 174 Nashorn JavaScript エンジン

---- 176 Mechanical Checking of Caller-Sensitive Methods

---- 179 Document JDK API Support and Stability

vm-- 142 Reduce Cache Contention on Specified Fields

vmgc 122 パーマネント領域の削除

vmgc 173 あまり使用されない GC の組み合わせの禁止

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 93: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved93

カテゴリ JEP ID 新機能の概要

vmrt 136 Enhanced Verification Errors

vmrt 147 Reduce Class Metadata Footprint

vmrt 148 Small VM

vmrt 171 Fence Intrinsics

core-- 153 Launch JavaFX Applications

corelang 101 Generalized Target-Type Inference

corelang 104 Annotations on Java Types

corelang 105 DocTree API

corelang 106 Add Javadoc to javaxtools

corelang 117 Remove the Annotation-Processing Tool (apt)

corelang 118 Access to Parameter Names at Runtime

corelang 120 Repeating Annotations

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 94: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved94

カテゴリ JEP ID 新機能の概要

corelnag 139 Enhance javac to Improve Build Speed

corelnag 172 DocLint

corelib 103 Parallel Array Sorting

corelib 107 Bulk Data Operations for Collections

corelib 109 Enhance Core Libraries with Lambda

corelib 112 Charset Implementation Improvements

corelib 119 javaxlangmodel Implementation Backed by Core Reflection

corelib 135 Base64 Encoding amp Decoding

corelib 149 Reduce Core-Library Memory Usage

corelib 150 Date amp Time API

corelib 155 Concurrency Updates

corelib 170 JDBC 42

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 95: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved95

カテゴリ JEP ID 新機能の概要

corelib 177 Optimize javatextDecimalFormatformat

corelib 178 Statically-Linked JNI Libraries

corelib 180 Handle Frequent HashMap Collisions with Balanced Trees

corei18n 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data

corei18n 128 BCP 47 Locale Matching

corei18n 133 Unicode 62

corenet 184 HTTP URL Permissions

coresec 113 MS-SFU Kerberos 5 Extensions

coresec 114 TLS Server Name Indication (SNI) Extension

coresec 115 AEAD CipherSuites

coresec 121 Stronger Algorithms for Password-Based Encryption

coresec 123 Configurable Secure Random-Number Generation

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 96: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved96

カテゴリ JEP ID 新機能の概要

coresec 124 Enhance the Certificate Revocation-Checking API

coresec 129 NSA Suite B Cryptographic Algorithms

coresec 130 SHA-224 Message Digests

coresec 131 PKCS11 Crypto Provider for 64-bit Windows

coresec 140 Limited doPrivileged

coresec 166 Overhaul JKS-JCEKS-PKCS12 Keystores

webjaxp 185 JAXP 15 Restrict Fetching of External Resources

ご参照 httpopenjdkjavanetprojectsjdk8features

JDK 8 JEP に記載される拡張機能 一覧

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 97: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved97

最後に

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 98: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved98

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 99: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved99

Java Platform Standard Edition 8 ドキュメント

httpdocsoraclecomjavasejp8

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 100: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved100

Java リリースノート

httpwwworaclecomtechnetworkjpjavajavaseoverview8train-relnotes-latest-2153846-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 101: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved101

JDK 8 の新機能概要

httpwwworaclecomtechnetworkjpjavajavaseoverview8-whats-new-2157071-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 102: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved102

JDK 8 の互換性非互換性の情報ガイド

httpwwworaclecomtechnetworkjavajavase8-compatibility-guide-2156366html

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 103: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved103

JDK 8 リリース時の既知の問題

httpwwworaclecomtechnetworkjpjavajavase8-known-issues-2157115-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 104: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved104

Java サポートロードマップ

httpwwworaclecomtechnetworkjpjavaeol-135779-jahtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 105: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved105

Java チュートリアル

httpdocsoraclecomjavasetutorialtutorialLearningPathshtml

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 106: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved106

is Back

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107
Page 107: Java SE 8 New Features

Copyright copy 2014 Oracle andor its affiliates All rights reserved107Copyright copy 2014 Oracle andor its affiliates All rights reserved107

Java SE 8是非ご活用ください

  • 祝 Java SE 8 正式リリース
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • JSR- 337 Java SE 8
  • Slide 12
  • Slide 13
  • Slide 14
  • Java SE 7 で導入 ForkJoin フレームワークの概念 (粒度小)
  • Slide 16
  • Lambda 式とは
  • Functional(関数型)インタフェース
  • Functional(関数型)インタフェース (2)
  • javautilfunction パッケージ
  • これは関数型インタフェース
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Stream API とは
  • Slide 30
  • Slide 31
  • Slide 32
  • Slide 33
  • Slide 34
  • Slide 35
  • Slide 36
  • Slide 37
  • Slide 38
  • メソッド参照コンストラクタ参照
  • メソッド参照コンストラクタ参照 (2)
  • Slide 41
  • Slide 42
  • Slide 43
  • Slide 44
  • Slide 45
  • Slide 46
  • Slide 47
  • Slide 48
  • Slide 49
  • Lambda ご使用時の注意
  • 1 匿名インナークラスを実装したクラス
  • 1 匿名インナークラスを含むクラスを   コンパイル
  • Slide 53
  • 1 Lambda 式を含むクラスを   コンパイル
  • Slide 55
  • Slide 56
  • Slide 57
  • Slide 58
  • Slide 59
  • Slide 60
  • JSR- 310 Date amp Time API 日付処理の開発容易性が向上
  • Slide 62
  • Slide 63
  • Slide 64
  • Slide 65
  • Slide 66
  • Slide 67
  • Slide 68
  • Slide 69
  • Slide 70
  • Slide 71
  • Slide 72
  • Slide 73
  • Slide 74
  • Slide 75
  • Slide 76
  • Slide 77
  • Slide 78
  • Slide 79
  • Slide 80
  • Slide 81
  • Slide 82
  • Slide 83
  • Slide 84
  • Slide 85
  • Slide 86
  • Slide 87
  • Slide 88
  • Slide 89
  • Slide 90
  • Slide 91
  • Slide 92
  • Slide 93
  • Slide 94
  • Slide 95
  • Slide 96
  • Slide 97
  • Slide 98
  • Slide 99
  • Slide 100
  • Slide 101
  • Slide 102
  • Slide 103
  • Slide 104
  • Slide 105
  • Slide 106
  • Slide 107