Upgrade to Pro — share decks privately, control downloads, hide ads and more …

As Velhas Novas do Java 7

As Velhas Novas do Java 7

7ef3cd04888c6d17f34d43e29ec3d46f?s=128

Carlos Alexandro Becker

June 05, 2014
Tweet

Transcript

  1. Java 7 as velhas novas do

  2. Java 6: Dec 2006 Java 7: Jul 2011 Java 8:

    Mar 2014 História
  3. Lambdas, Jigsaw, e parte do Project Coin foram dropados do

    Java 7
  4. Agenda • Diamond Operator • Strings em Switch’s • Automatic

    Resource Management • Numeric Literals com Underscores • Exception Handling (multi-catch) • NIO 2.0 • Fork and Join • invokedynamic
  5. Diamond Operator // java 6 Map<String, List<String>> list6 = 


    new TreeMap<String, List<String>>(); // java 7 Map<String, List<String>> list7 = new TreeMap<>();
  6. String em Switch’s // java 6 AnEnum a = AnEnum.A;

    switch (a) { case A: doSomethingWhenA(); break; // … }
  7. String em Switch’s // java 7 String b = "b";

    switch(b) { case "b": doSomethingWhenB(); break; // … }
  8. Automatic Resource Management // java 6 BlahResource resource; try {

    resource = new BlahResource(); resource.doSomething(); } catch (Exception e) { log.error( “Maoeee”, e ); } finally { try { resource.close(); } catch (BlahResourceException e) { log.error( “Ah haee”, e ); } }
  9. Automatic Resource Management // java 7 try (BlahResource resource =

    new BlahResource()) { resource.doSomething(); } catch (Exception e) { log.error( “Maoeee”, e ); }
  10. Numeric Literals // java 6 int thousand = 1000; //

    java 7 int thousand = 1_000;
  11. Exception Handling // java 6 try { oneThousandCheckedExceptionsLater(); } catch

    (ExceptionOne e) { log.error(“Erro: ", e); } catch (ExceptionTwo e) { log.error(“Erro: ", e); } catch (ExceptionThree e) { log.error(“Erro: ", e); }
  12. Exception Handling // java 7 try { oneThousandCheckedExceptionsLater(); } catch

    (ExceptionOne | ExceptionTwo | ExceptionThree e) { log.error(“Erro:”, e); }
  13. NIO 2.0 • Path & Paths • Files • FileSystems

    • WatchService
  14. Fork and Join • Dividir para conquistar • ForkJoinTask &

    ForkJoinPool
  15. incokedynamic • Recurso da JVM para suportar melhor linguagens com

    tipagem dinâmica • java.lang.invoke
  16. PROTIPS™

  17. None
  18. GRÁTIS NA LOJA KINDLE!

  19. Bom e velho Javadoc ☕️

  20. Dúvidas?

  21. Thanks https://speakerdeck.com/caarlos0/as-velhas-novas-do-java-7