java se 7、そしてjava se 8

28
Java SE 7, そして Java SE 8 Java in the Box 櫻庭 祐一

Upload: yuichi-sakuraba

Post on 10-May-2015

1.941 views

Category:

Technology


5 download

DESCRIPTION

2012/05/26 JavaQne(じゃばきゅん) Fukuoka 2012 発表資料 「Java SE 7、そしてJava SE 8」

TRANSCRIPT

Page 1: Java SE 7、そしてJava SE 8

Java SE 7,そして Java SE 8

Java in the Box櫻庭 祐一

Page 2: Java SE 7、そしてJava SE 8

Agenda HistoryJava SE 7Java SE 8

Conclusion

Page 3: Java SE 7、そしてJava SE 8

History

Page 4: Java SE 7、そしてJava SE 8

General

04 05 06

Modularity

Parallel

EoD

Misc

6 と 7 は一緒に計画

G.Hamiltion

JSR121Isolation

JAR の拡張

J2SE5.0

リリース

07 08 09 10

XML リテラル

BeanShell

NewPackaging

friend

NewBytecode

Closure

NIO2

JSR292

JSR294Superpackage

JSR277JAM

JSR296SAFJSR295BeansBinding

BGGA

Java SE6

リリース

N.Gafter

OpenJDK

JavaFX 発表M.Reinhold

JSR308AnnotationJSR303BeanValidation

BeanShell

JSR292

JSR296SAFJSR295BeansBinding

Closure

JSR310DateTime

NIO2

JSR277Module

SmallChanges

Closure

JMX2.0

Jigsaw

SE6u10リリース

NIO2

JSR292

JSR166yNIO2

Coin

JSR308Annotation

Lambda

JSR292JSR310DateTime

Sun 買収 Plan APlan B

M.Reinhold

Page 5: Java SE 7、そしてJava SE 8

7 planAProject CoinNIO.2InvokeDynamicFork/Join FrameworkProject LambdaProject Jigsaw

Mid 2012

7 planB 8Project LambdaProject Jigsaw

Project CoinNIO.2InvokeDynamicFork/Join Framework

Mid 2011

Late 2012

Page 6: Java SE 7、そしてJava SE 8

7 planAProject CoinNIO.2InvokeDynamicFork/Join FrameworkProject LambdaProject Jigsaw

Mid 2012

7 planB 8Project LambdaProject Jigsaw

Project CoinNIO.2InvokeDynamicFork/Join Framework

Mid 2011

Late 2012Mid 2013

Page 7: Java SE 7、そしてJava SE 8

Project Coin

switch 文で文字列2 進数と区切り文字例外の multi catch と safe rethrowジェネリクスの省略記法try-with-resources簡潔な可変長引数メソッド

Page 8: Java SE 7、そしてJava SE 8

Project Coin 従来の記述

InputStream in = null; OutputStream out = null;

try {

in = new FileInputStream(src);

out = new FileOutputStream(src);

byte[] buf = new byte[1024]; int n;

while((n = in.read(buf)) >= 0) out.write(buf, 0, n);

} catch (IOException ex) {

} finally {

try {

if (in != null) in.close();

if (out != null) out.close();

} catch (IOException ex) {}

}

InputStream in = null; OutputStream out = null;

try {

in = new FileInputStream(src);

out = new FileOutputStream(src);

byte[] buf = new byte[1024]; int n;

while((n = in.read(buf)) >= 0) out.write(buf, 0, n);

} catch (IOException ex) {

} finally {

try {

if (in != null) in.close();

if (out != null) out.close();

} catch (IOException ex) {}

}

Page 9: Java SE 7、そしてJava SE 8

Project Cointry-with-resources

try (InputStream in = new FileInputStream(src);

OutputStream out = new FileOutputStream(src)) {

byte[] buf = new byte[1024];

int n;

while((n = in.read(buf)) >= 0) {

out.write(buf, 0, n);

}

} catch (IOException ex) {

System.err.println(ex.getMessage());

}

Page 10: Java SE 7、そしてJava SE 8

NIO.2

New Filesystem API非同期 I/O

SocketChannel のマルチキャスト

Page 11: Java SE 7、そしてJava SE 8

FileSystem fileSystem.getDefault();

Path src = fileSystem.getPath(”foo.txt”);

Path dest = fileSystem.getPath(”bar.txt”);

FileSystem fileSystem.getDefault();

Path src = fileSystem.getPath(”foo.txt”);

Path dest = fileSystem.getPath(”bar.txt”);

// ファイル操作

Files.copy(src, dest);

Files.move(src, dest);

FileSystem fileSystem.getDefault();

Path src = fileSystem.getPath(”foo.txt”);

Path dest = fileSystem.getPath(”bar.txt”);

// ファイル操作

Files.copy(src, dest);

Files.move(src, dest);

// シンボリックリンクの生成

Path target = fileSystem.getPath(...);

Path link = fileSystem.getPath(...);

Files.createSymbolicLink(link, target);

Page 12: Java SE 7、そしてJava SE 8

Path startDir = fileSystem.getPath(".");

final String regex = "Test.java";

// ディレクトリツリーの探索

Files.walkFileTree(startDir,

new SimpleFileVisitor<Path>() {

public FileVisitResult visitFile(Path path,

BasicFileAttributes attrs) {

return FileVisitResult.CONTINUE;

}

});

if (Pattern.matches(regex,

path.getFileName().toString())) {

System.out.println("File: " + path);

}

Page 13: Java SE 7、そしてJava SE 8

InvokeDynamic

新しいバイトコードinvokedynamic

動的型付け言語のメソッドコールbootstrap, MethodHandle, CallSite

Page 14: Java SE 7、そしてJava SE 8

Fork/Join Framework

more cores, more tasks

分割統治法 + Work Stealing

Page 15: Java SE 7、そしてJava SE 8

class FibonacciTask extends RecursiveTask<Integer> {

private final Integer n;

FibonacciTask(Integer n) { this.n = n; }

protected Integer compute() {

if (n <= 1) return n;

// n-1 に対してフィボナッチ数を求める

FibonacciTask f1 = new FibonacciTask(n - 1);

f1.fork();

// n-2 に対してフィボナッチ数を求める

FibonacciTask f2 = new FibonacciTask(n - 2);

// 処理結果を足し合せて、nのフィボナッチ数とする

return f2.compute() + f1.join();

}

}

Page 16: Java SE 7、そしてJava SE 8

78Project Lambda

Project Jigsaw

Project CoinNIO.2InvokeDynamicFork/Join FrameworkMid 2011

Mid 2013

Page 17: Java SE 7、そしてJava SE 8

簡単にマルチタスクもちろん細粒度

Internal Iteration+

Lambda Expression

Page 18: Java SE 7、そしてJava SE 8

List<Student> students = ...

double highestScore = 0.0;

for (Student s: students) {

if (s.getGradYear() == 2011) {

if (s.getScore() > highestScore) {

highestScore = s.getScore();

}

}

}

Page 19: Java SE 7、そしてJava SE 8

List<Student> students = ...

double highestScore =

students.filter(new Predicate<Student>() {

public boolean op(Student s) {

return s.getGradYear() == 2011;

}

}).map(new Mapper<Student、Double>() {

public Double extract(Student s) {

return s.getScore();

}

}).max();

Page 20: Java SE 7、そしてJava SE 8

List<Student> students = ...

double highestScore =

students.filter(new Predicate<Student>() {

public boolean op(Student s) {

return s.getGradYear() == 2011;

}

}).map(new Mapper<Student、Double>() {

public Double extract(Student s) {

return s.getScore();

}

}).max();青字の部分が冗長

Page 21: Java SE 7、そしてJava SE 8

List<Student> students = ...

double highestScore =

students.filter(Student s -> s.getGradYear()

== 2011)

.map(Student s -> s.getScore())

.max();

赤字の部分がラムダ式

Page 22: Java SE 7、そしてJava SE 8

List<Student> students = ...

double highestScore =

students.filter(s -> s.getGradYear() == 2011)

.map(s -> s.getScore())

.max();引数の型を省略可

Page 23: Java SE 7、そしてJava SE 8

List<Student> students = ...

double highestScore =

students.parallel()

.filter(s -> s.getGradYear() == 2011)

.map(s -> s.getScore())

.max();

パラレルに処理

Page 24: Java SE 7、そしてJava SE 8

Project Jigsaw

Modularity

Packaging

= Grouping + Dependence + Versioning + Encapsulation + Optional modules + Module aliases

= Module files + Libraries + Repositories + Native packages

Page 25: Java SE 7、そしてJava SE 8

ほかにも ...

JavaFX 3.0

Nashorn

HotRockitDevice SuportAnnotation TypeCoin 2

Page 26: Java SE 7、そしてJava SE 8

Beyond Java SE 8

Iteroperability

Cloud

Ease of Use

Advanced Optimization

Works Everywhere& with Everything

Page 27: Java SE 7、そしてJava SE 8

Conclusion

NIO.2, G1GCJava SE 7u4 java.com で配布

いますぐ使える Java SE 7

あと 1 年で Java SE 8

Lambda, JigsawJavaFX, Nashorn

Page 28: Java SE 7、そしてJava SE 8

Java SE 7,

Java SE 8そして

Java in the Box櫻庭 祐一

Java SE 7,

Java SE 8そして

Java in the Box櫻庭 祐一