1 / 17

Java 7

Java 7. Änderungen in der neuen Version. Thomas Nagel 17. Juni 2012. Übersicht. Syntax und Sprachelemente JDK Framework und UI JRE und VM Java Web-Start. Syntax und Sprachelemente. Binäre Literale, Unterstriche in Zahlen Strings in Switch-Labels Diamond-Operator

mada
Download Presentation

Java 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java 7 Änderungen in der neuen Version Thomas Nagel 17. Juni 2012

  2. Übersicht • Syntax und Sprachelemente • JDK Framework und UI • JRE und VM • Java Web-Start Java 7

  3. Syntax und Sprachelemente • Binäre Literale, Unterstriche in Zahlen • Strings in Switch-Labels • Diamond-Operator • Ressourcen in try-catch (u.a. mit JDBC) • mehrere Exceptions in catch-Klauseln Java 7

  4. Binäre Literale, Unterstriche • Binäre Literale:int x = 0b1001101; • Unterstriche in Literalen:int summe = 1_345_998; Java 7

  5. Strings in Switch-Labels • Vermeidet If-Else-Ketten • alt: if(dto.getStatus().equals('beauftragt')) { } else if(dto.getStatus().equals('erledigt')) { } else if(dto.getStatus().equals('storniert')) { } • neu: switch(dto.getStatus()) { case 'beauftragt': doA(); break; case 'erledigt': doB(); break; case 'storniert': doC(); break; } Java 7

  6. Diamond-Operator • Vermeidet Wiederholungen • alt:Map<String, List<Trade>> trades = new TreeMap<String, List<Trade>> (); • neu:Map<String, List<Trade>> trades = new TreeMap <> (); Java 7

  7. Ressourcen in try-catch • Sicheres Freigeben von Ressourcen auch im Fehlerfall. • alt:public void oldTry() {try { fos = new FileOutputStream("movies.txt"); dos = new DataOutputStream(fos); dos.writeUTF("Java 7 Block Buster"); } catch (IOException e) {e.printStackTrace(); } finally { try { fos.close(); dos.close(); } catch (IOException e) { /*ignore*/} }} Java 7

  8. Ressourcen in try-catch /2 • neu:public void newTry() { try ( fos = new FileOutputStream("movies.txt"); dos = new DataOutputStream(fos); ) { dos.writeUTF("Java 7 Block Buster"); } catch (IOException e) {e.printStackTrace(); }} • Resourcen müssen das Interface java.lang.AutoCloseable implementieren durch die Methode close(). Java 7

  9. Multi-catch • neue kürzere Form: • public void multiCatch() { try { methodeDie3AusnahmenWirft(); } catch (ExceptionOne | ExceptionTwo | ExceptionThree e) { // log and deal with all Exceptions }} Java 7

  10. JDK Framework • NIO2: Dateien kopieren und verschieben, Dateiänderungen beobachten • Fork-Join-Framework, Phaser-Synchronisation • JDBC 4.1 • Unicode 6.0 Java 7

  11. NIO2 • Verbesserungen bei Dateisystemen, Verzeichnissen, Pfaden, Links • Kopieren und Verschieben enthalten • Änderungsüberwachung Java 7

  12. Fork-Join-Framework • Parallelisierung aufwendiger Vorgänge • Steuerung durch ForkJoinPool • Ausführung durch n ForkJoinTasks • Arten: RecursiveAction ohne Ergebnis, RecursiveTask mit Ergebnis • Automatische Verteilung und Synchronisation durch den ForkJoinPool Java 7

  13. UI • verbesserte Font-API • neue Swing-Klasse JLayer • Transparenz • Fenster die nicht rechteckig sind • JavaFX als Swing-Ersatz und -Update Java 7

  14. JRE und VM • G1 Garbage Collector • Large heap (64 bit konform) • improved JMX Agent Java 7

  15. Java Web-Start und Plugin • Windows-Version in os-Selektor • Installation per JWS • JNLP-File im Applet-Tag in HTML • Kommunikation Java <-> JavaScript Java 7

  16. Nützlich für uns • String in Switch-Labels • Catch mit Ressourcen • NIO Datei-Operationen • Fork-Join-Tasks • G1 Heap • Font-API, Transparenz, JavaFX • JMX-Improvements Java 7

  17. Weitere Informationen • Oracle OTN • Oracle Tutorials • Java7 Doku auf dem Server Java 7

More Related