Your SlideShare is downloading. ×
Novedades de Java 8 por PERU JUG
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Novedades de Java 8 por PERU JUG

131
views

Published on

Presentación para miembros de PERU JUG (itpjava). …

Presentación para miembros de PERU JUG (itpjava).
El video del hangout disponible en itpjava.org o en el canal de youtube.com/joedayzperu

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
131
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Java 8Java 8 PERU JUGPERU JUG JoseJose DiazDiaz @joeday@joeday zz
  • 2. Nuevos TemasNuevos Temas Lambda expressionsLambda expressions Nashorn y JavaScriptNashorn y JavaScript Compact ProfilesCompact Profiles Date and Time APIDate and Time API Java FX 8Java FX 8 Participación de la ComunidadParticipación de la Comunidad Java ME 8Java ME 8 Java SE 8 y la JVMJava SE 8 y la JVM
  • 3. LambdaLambda ExpressionsExpressions
  • 4. Lambda ExpressionsLambda Expressions Collection<Person> people = ..;Collection<Person> people = ..; Iterator<Person> it =Iterator<Person> it = people.iterator();people.iterator(); while (it.hasNext()) {while (it.hasNext()) { Person p = it.next();Person p = it.next(); if (p.getAge()>18)if (p.getAge()>18) it.remove();it.remove(); }}
  • 5. Abstracción sobreAbstracción sobre comportamientocomportamiento interface Predicate<T> {interface Predicate<T> { boolean test(T t);boolean test(T t); }} class Collections {class Collections { public static<T>public static<T> void removeAll(Collection<T>void removeAll(Collection<T> coll,coll, Predicate<T> pred){Predicate<T> pred){ ...... }} }}
  • 6. Abstracción sobreAbstracción sobre comportamientocomportamiento Collections.removeAll(people,Collections.removeAll(people, new Predicate<Person>() {new Predicate<Person>() { public boolean testpublic boolean test (Person p){(Person p){ return p.getAge() > 18;return p.getAge() > 18; }} }} });});
  • 7. Abstracción sobreAbstracción sobre comportamientocomportamiento Collections.removeAllCollections.removeAll (people,(people, p -> p.getAge() > 18);p -> p.getAge() > 18);
  • 8. Otro EjemploOtro Ejemplo int highestWeight = 0;int highestWeight = 0; for (Person p: people) {for (Person p: people) { if (p.getGender() ==if (p.getGender() == MALE){MALE){ int weight =int weight = p.getWeight();p.getWeight(); highestWeight =highestWeight = maxmax (highestWeight,(highestWeight, weight);weight); }} }}
  • 9. Otro EjemploOtro Ejemplo int highestWeigh =int highestWeigh = people.stream()people.stream() .filter( p -> p.getGender() ==.filter( p -> p.getGender() == MALE)MALE) .mapToInt(p -> p.getWeight()).mapToInt(p -> p.getWeight()) .max();.max();
  • 10. En paraleloEn paralelo int highestWeigh =int highestWeigh = people.people.parallelStream()parallelStream() .filter( p -> p.getGender() ==.filter( p -> p.getGender() == MALE)MALE) .mapToInt(p -> p.getWeight()).mapToInt(p -> p.getWeight()) .max();.max();
  • 11. Agregar operacionesAgregar operaciones Set<Seller> sellers = new HashSet<>();Set<Seller> sellers = new HashSet<>(); for(Txn t: txns){for(Txn t: txns){ if(t.getBuyer().getAge() >= 65)if(t.getBuyer().getAge() >= 65) sellers.add(t.getSeller());sellers.add(t.getSeller()); }} List<Seller> sorted = new ArrayList<>(sellers);List<Seller> sorted = new ArrayList<>(sellers); Collections.sort(sorted,Collections.sort(sorted, new Comparator<Group>() {new Comparator<Group>() { public int compare(Seller a, Seller b){public int compare(Seller a, Seller b){ returnreturn a.getName().compareTo(b.getName());a.getName().compareTo(b.getName()); }} });}); for(Seller s: sorted)for(Seller s: sorted) System.out.println(s.getName());System.out.println(s.getName());
  • 12. Agregar operacionesAgregar operaciones txns.stream()txns.stream() .filter(t -> t.getBuyer().getAge() >= 65).filter(t -> t.getBuyer().getAge() >= 65) .map (t -> t.getSeller).map (t -> t.getSeller) .distinct().distinct() .sort (comparing(s -> s.getName())).sort (comparing(s -> s.getName())) .forEach(s -> System.out.println.forEach(s -> System.out.println (s.getName());(s.getName());
  • 13. Default methodsDefault methods Sabemos que no podemos agregar nuevosSabemos que no podemos agregar nuevos métodos a interfaces. Rompe lasmétodos a interfaces. Rompe las implementaciones existentes.implementaciones existentes. Es un gran problema si tu core API tiene mas deEs un gran problema si tu core API tiene mas de 15 años15 años Los default methods te permiten agregarLos default methods te permiten agregar nuevos métodos a interfaces existentesnuevos métodos a interfaces existentes
  • 14. Default methodsDefault methodsCollection<Person> peopleCollection<Person> people = ..;= ..; int highestWeigh =int highestWeigh = people.stream()people.stream() ...... interface Collection<T> {interface Collection<T> { ...... default Stream<T>default Stream<T> stream() {stream() { ...... }}
  • 15. AbstraerAbstraer comportamientocomportamiento Los default methods son necesarios porque yaLos default methods son necesarios porque ya existen core library classes como Collections,existen core library classes como Collections, con mas de 15 años.con mas de 15 años. Sin default methods no se podría soportarSin default methods no se podría soportar lambdas en core library classes.lambdas en core library classes.
  • 16. Otro ejemploOtro ejemplo ““Buscar artistas con albums que tienen menosBuscar artistas con albums que tienen menos de 8 tracks”de 8 tracks”
  • 17. Otro ejemploOtro ejemplo Set<Artists> artists =Set<Artists> artists = albums.stream()albums.stream() .filter(album ->.filter(album -> album.getTracks().size() < 8)album.getTracks().size() < 8) .map(album -> album.getArtist()).map(album -> album.getArtist()) .collect(toSet());.collect(toSet()); ““Aquí decimos que dados los elementos de album,Aquí decimos que dados los elementos de album, selecciona uno que tenga 8 tracks, y por cada uno de ellosselecciona uno que tenga 8 tracks, y por cada uno de ellos obtén el artista y luego colecciona ellos en un set”.obtén el artista y luego colecciona ellos en un set”.
  • 18. NashornNashorn JavaScriptJavaScript
  • 19. CompactCompact ProfilesProfiles
  • 20. Date andDate and TimeTime APIAPI
  • 21. Java FXJava FX 88
  • 22. ParticipacióParticipació nn De la ComunidadDe la Comunidad
  • 23. Java MEJava ME 88
  • 24. Java SE 8 yJava SE 8 y JVMJVM
  • 25. Descargar Java 8Descargar Java 8 http://www.oracle.com/technetwork/java/javase/downloads/index.http://www.oracle.com/technetwork/java/javase/downloads/index.
  • 26. LibrosLibros
  • 27. LibrosLibros
  • 28. VideosVideos http://www.oracle.com/events/us/en/java8/index.hhttp://www.oracle.com/events/us/en/java8/index.h http://www.jfokus.se/jfokus/video.jsphttp://www.jfokus.se/jfokus/video.jsp
  • 29. Java MagazineJava Magazine http://bit.ly/1hblvXWhttp://bit.ly/1hblvXW
  • 30. http://java.dzone.com/articles/java-8-released-http://java.dzone.com/articles/java-8-released- lambdaslambdas http://java.dzone.com/articles/5-features-java-8-http://java.dzone.com/articles/5-features-java-8- will-changewill-change http://java.dzone.com/articles/interface-default-http://java.dzone.com/articles/interface-default- methods-javamethods-java http://java.dzone.com/articles/java-8-will-http://java.dzone.com/articles/java-8-will- revolutionize#.UzHHrHWa4yc.twitterrevolutionize#.UzHHrHWa4yc.twitter http://bit.ly/1fkT2http://bit.ly/1fkT2 KZKZ
  • 31. Presentaciones de JUGsPresentaciones de JUGs http://www.slideshare.net/ktoso/javaone-http://www.slideshare.net/ktoso/javaone- 2013-java-82013-java-8 http://www.slideshare.net/mitemitreski1/state-of-http://www.slideshare.net/mitemitreski1/state-of- the-lambdathe-lambda http://www.slideshare.net/ramonypp/java-8-http://www.slideshare.net/ramonypp/java-8- project-lambdaproject-lambda
  • 32. Documentación Java 8Documentación Java 8 http://docs.oracle.com/javase/8/http://docs.oracle.com/javase/8/ docs/docs/
  • 33. PreguntasPreguntas
  • 34. GraciasGracias
  • 35. PERU JUGPERU JUG http://itpjava.http://itpjava. orgorg JoseJose DiazDiaz @joeday@joeday zz