• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Novidades do Java SE 8
 

Novidades do Java SE 8

on

  • 2,484 views

 

Statistics

Views

Total Views
2,484
Views on SlideShare
2,455
Embed Views
29

Actions

Likes
5
Downloads
36
Comments
0

1 Embed 29

https://twitter.com 29

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

Novidades do Java SE 8 Novidades do Java SE 8 Presentation Transcript

  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 132Lambda, Nashorn,Metaspace: algumasnovidades do Java SE 8Bruno BorgesOracle Product ManagerJava Evangelist@brunoborges
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 133Bruno BorgesOracle Product Manager / EvangelistDesenvolvedor, Gamer, Beer SommelierEntusiasta em Java Embedded e JavaFXTwitter: @brunoborges
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 134Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16Agenda História Scene Graph Java API Properties Bindings Controls CSS WebView JFXPanel Charts
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 135SE8
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 136Um pouco da históriaGreen Team, C++ ++ –, Oak - 1990Java 1.0 / 1.1 – 1996 / 1997Java 2 “J2SE” 1.2 – 1998Java 1.3 ”J2SE 1.3” – 2000Java 1.4 ”J2SE 1.4” – 2002Java 1.5 “Java SE 5” - 2004Java 1.6 “Java SE 6” - 2006Java 1.7 “Java SE 7” - 2011
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 137E o futuro...
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 138E o JavaFX?É o sucessor doJava Swing
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 139Disponível para...Windows, Linux, Mac OS XE em Preview...ARM*Apple iOS*Android*JavaFX 2.2 vem junto com JDK 7u6+Standalone para Java 6
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1310OpenJFXJavaFX open sourced!http://openjdk.java.net/projects/openjfx/
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1311Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16JavaSE 8 Melhorias em interfaces
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1312Java SE 8 – Melhorias em InterfacesStatic methodsMétodos com implementação defaultFunctional Interfacestoda interface que define apenas 1 método abstrato (sem corpo)@FunctionalInterface: similar a @Override, para garantiapublic default void forEach(Consumer<? super T> action) {Objects.requireNonNull(action);for (T t : this) {action.accept(t);}}
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1313Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16JavaSE 8 Melhorias em interfaces Lambdas
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1314Java SE 8 – LambdasLista de inputs tipados à esquerda, bloco com retorno à direitaInput à esquerda, void à direitaMétodos estáticos e de objetos como funções lambda(int x, int y) -> { return x + y; }(x, y) -> x + yx -> x * x() -> xx -> { System.out.println(x); }String::valueOf x -> String.valueOf(x)Object::toString x -> x.toString()x::toString () -> x.toString()ArrayList::new () -> new ArrayList<>()
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1315Java SE 8 – Lambdas (cont.)Em busca de um match para saber qual construtor/método chamarO método compare precisa de dois parâmetros, e deve retornarint. A expressão lambda condiz com esta assinatura, logo aexpressão é válidaExpressões não devem modificar variáveis definidas fora do corpolambdaComparator<String> c = (a, b) -> Integer.compare(a.length(),b.length());int count = 0;List<String> strings = Arrays.asList("a", "b", "c");strings.forEach(s -> {count++; // error: cant modify the value of count});
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1316Java SE 8 – Lambdas (cont.)Classes abstratas não podem ser instanciadas com lambdapoderia esconder código (construtor por exemplo)elimina possibilidade de otimizações futurasSolução: factory methodsOrdering<String> order = (a, b) -> ...;CacheLoader<String, String> loader = (key) -> ...;Ordering<String> order = Ordering.from((a, b) -> ...);CacheLoader<String, String> loader =CacheLoader.from((key) -> ...);
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1317Java SE 8 – Lambdas (cont.)Novos pacotes:java.util.stream: suporta operações em valores de stream, comexpressões lambdajava.util.function: interfaces funcionais utilitárias do JDKint sumOfWeights = blocks.stream().filter(b -> b.getColor() == RED).mapToInt(b -> b.getWeight()).sum();// In Java 7:foo(Utility.<Type>bar());Utility.<Type>foo().bar();// In Java 8:foo(Utility.bar());Utility.foo().bar();
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1318Java SE 8 – Lambdas: Antes e Depoispublic void emailDraftees(List<Person> pl) {for(Person p : pl){if (p.getAge() >= 18 &&p.getAge() <= 25 &&p.getGender() == Gender.MALE) {roboEmail(p);}}}
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1319Java SE 8 – Lambdas: Antes e Depoispublic void emailDraftees(List<Person> pl) {for(Person p : pl) {if (isDraftee(p)) {roboEmail(p);}}}public boolean isDraftee(Person p){return p.getAge() >= 18&& p.getAge() <= 25&& p.getGender() == Gender.MALE;}
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1320Java SE 8 – Lambdas: Antes e DepoisPredicate<Person> draftees;draftees = p -> p.getAge() >= 18 &&p.getAge() <= 25 &&p.getGender() == Gender.MALE;robo.emailContacts(pl, allDraftees);public void emailContacts(List<Person> pl, Predicate<Person> pred) {for(Person p : pl)if (pred.test(p))roboEmail(p);}
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1321Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16JavaSE 8 Melhorias em interfaces Lambdas Generics
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1322Java SE 8 – GenericsInferência de tipos genéricos// In Java 7:foo(Utility.<Type>bar());Utility.<Type>foo().bar();// In Java 8:foo(Utility.bar());Utility.foo().bar();
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1323Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16JavaSE 8 Melhorias em interfaces Lambdas Generics Date and Time API
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1324Java SE 8 – Date and TimeMudança total da API para lidar com data, hora, calendárioBaseado no JodaTime – JSR 310Novas classes:LocalDateTime, LocalDate, LocalTimeYear, YearMonth, Month, MonthDay, DayOfWeekInstant, ZonedDateTime, OffsetTime, Duration, Period
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1325Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16JavaSE 8 Melhorias em interfaces Lambdas Generics Date and Time API Outras APIs
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1326Java SE 8 – Outras mudanças de APIReflection APIManipular lambdas, anotações, etcAnnotationsPermite definir anotação no tipo genéricoNovos métodos em IO/NIO (busca recursiva de arquivo/diretorio)Concurrency APICollections APIList<@Nullable String>
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1327DEMOAntes e depois do Java SE 8
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1328NashornJavascriptthe right way
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1329Oracle Nashorn?É o sucessor doMozilla Rhino
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1330NashornEngine de processamento da linguagem JavascriptEscrito do zeroSeguindo boas práticasNovas técnicas e algoritmosAtento às otimizações da JVM (ex: invokedynamic)Projeto mantido pela Oracle, e Open SourceIncluído no OpenJDK em 21/12/12
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1331Nashorn – Diferenciais?Maior integração com a camada JavaIntegração com aplicações JavaFXUtilizado nos componentes WebView e HTML5Maior performanceMenor footprint de memória
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1332DEMOJavaFX usando Nashorn
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1333MetaspaceSay goodbye toOutOfMemoryError
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1334MetaspaceSubstitui a PermGenModelo já utilizado pela JVM Oracle JRockitPor padrão, o tamanho é variável – ótimo para desenvolvimentoEm produção, deve ser limitado– novo parâmetro: -XX:MaxMetaspaceSize– parâmetros *PermGen ignorados pela VMDados armazenados “off-heap”Limitado ao tamanho de memória disponível na máquina
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1335Perguntas?
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1336OBRIGADO!@brunoborgesblogs.oracle.com/brunoborges
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1337The preceding is intended to outline our general product direction. It is intendedfor information purposes only, and may not be incorporated into any contract.It is not a commitment to deliver any material, code, or functionality, and shouldnot be relied upon in making purchasing decisions. The development, release,and timing of any features or functionality described for Oracle’s productsremains at the sole discretion of Oracle.
  • Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1338