明日から使える
                  Java SE 7

Java in the Box
 櫻庭 祐一
祝
7/28
JavaSE7
リリース
ほんとは

2008 年
リリース
 予定
だったけど
なぜ遅れた
          Project Lambda
       機能 Project Jigsaw
 買収

           移行 JDK OpenJDK

 JavaFX?
Java SE 7 Themes

  Compatibility
  Productivity    Project Coin
  Performance     G1GC JSR166y
  Universality    InvokeDynamic
  Integration     NIO2
Try-with-resources
Multi Catch/Precise Rethrow




+1
NIO2

Upgrade ClassLoader
try-with-resources




           +1
 try (InputStream in = new FileInputStream(src);
      OutputStream out = new FileOutputStream(dest)) {

     byte[] buf = new byte[1024];
     int n;
     while((n = in.read(buf)) >= 0) {
         out.write(buf, 0, n);
     }
 } catch (IOException ex) {
     // 例外処理
 }
Multi Catch/Precise Rethrow




            +1
   try {
       DocumentBuilderFactory factory
           = DocumentBuilderFactory.newInstance();
       DocumentBuilder builder
           = factory.newDocumentBuilder();
       Document doc = builder.parse(stream);

       // パース

   } catch (final    IOException
                 |   IllegalArgumentException
                 |   ParserConfigurationException
                 |   SAXException ex) {
       log(ex);
       throw ex;
   }
NIO2       FileVisitor を使ったファイルの検索




               +1
Path start = ...;
String regex = ...;

Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
    public FileVisitResult visitFile(Path path,
             BasicFileAttributes attrs) throws IOException {
        if (Pattern.matches(regex,
                            path.getFileName().toString()) {
            System.out.println("File: " + path);
        }
        return FileVisitResult.CONTINUE;
    }
});
+0.5
 Diamond Operator   <>
 数値リテラル

明日から使える Java SE 7

  • 1.
    明日から使える Java SE 7 Java in the Box 櫻庭 祐一
  • 2.
  • 3.
  • 4.
    なぜ遅れた Project Lambda 機能 Project Jigsaw 買収 移行 JDK OpenJDK JavaFX?
  • 5.
    Java SE 7Themes Compatibility Productivity Project Coin Performance G1GC JSR166y Universality InvokeDynamic Integration NIO2
  • 6.
  • 7.
    try-with-resources +1 try (InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest)) { byte[] buf = new byte[1024]; int n; while((n = in.read(buf)) >= 0) { out.write(buf, 0, n); } } catch (IOException ex) { // 例外処理 }
  • 8.
    Multi Catch/Precise Rethrow +1 try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(stream); // パース } catch (final IOException | IllegalArgumentException | ParserConfigurationException | SAXException ex) { log(ex); throw ex; }
  • 9.
    NIO2 FileVisitor を使ったファイルの検索 +1 Path start = ...; String regex = ...; Files.walkFileTree(start, new SimpleFileVisitor<Path>() { public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (Pattern.matches(regex, path.getFileName().toString()) { System.out.println("File: " + path); } return FileVisitResult.CONTINUE; } });
  • 10.
    +0.5 Diamond Operator <> 数値リテラル