Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

2017 java9-spring-days

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Prochain SlideShare
Welcome to Java 9
Welcome to Java 9
Chargement dans…3
×

Consultez-les par la suite

1 sur 25 Publicité
Publicité

Plus De Contenu Connexe

Diaporamas pour vous (18)

Similaire à 2017 java9-spring-days (20)

Publicité

Plus par Jeanne Boyarsky (20)

Plus récents (20)

Publicité

2017 java9-spring-days

  1. 1. Welcome to Java 9 Spring Days – 6/20/17 Jeanne Boyarsky https://www.slideshare.net/ boyarsky/2017-java9springdays Twitter @jeanneboyarsky Blog: http://www.selikoff.net
  2. 2. Modules (Jigsaw) Problem • Jar hell • Solution – Maven/Gradle? • No closed/private packages Java 9 • Modules! Twitter: @jeanneboyarsky
  3. 3. Jigsaw – flux • You can use a command line flag. • The flag might or might not be the default. Twitter: @jeanneboyarsky Do you •use sun.* internal APIs? •use a jar that does?
  4. 4. • 2011 – Maybe part of Java 7. Nope Plan B • 2012 - Part of Java 8. No wait • 2014 - Part of Java 9 • Sept 2016 • May 2017 • July 2017 • Sept 2017? The Saga of Jigsaw Twitter: @jeanneboyarsky
  5. 5. Moving on That was nerve wracking. We clearly need sugar! Twitter: @jeanneboyarsky
  6. 6. Creating a non-empty Set Set<String> set = new HashSet<>( Arrays.asList("1","2", "3")); Set<String> set = Stream.of("1", "2”, "3") .collect(Collectors.toSet()); Set<String> set = Set.of("1", "2", "3"); Twitter: @jeanneboyarsky
  7. 7. For consistency Map<String, String> map = Map.of("k", "v"); Up to 10 params, then varargs List<String> list = List.of("1", "2", "3"); Up to 20 params, then varargs Twitter: @jeanneboyarsky
  8. 8. Better Map Twitter: @jeanneboyarsky Map<Integer, Integer> map = Map.ofEntries( Map.entry(1, 10), Map.entry(2, 20) );
  9. 9. JavaDoc Search Upgrade Twitter: @jeanneboyarsky (to 2017)
  10. 10. Try with Resources Path path = Paths.get("test.txt"); try (BufferedReader reader = Files.newBufferedReader(path)) { System.out.println(reader.readLine()); } Effectively final resources Twitter: @jeanneboyarsky BufferedReader reader = Files.newBufferedReader(path); try (reader) { System.out.println(reader.readLine()); }
  11. 11. What’s wrong here? Connection con = DriverManager.getConnection(url); PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); try (con; ps; rs) { while (rs.next()) { // process result set } } Twitter: @jeanneboyarsky Resource leak!
  12. 12. @Deprecated “Very few deprecated APIs were actually removed, leading some people to believe that nothing would ever be removed. On the other hand, other people believed that everything that was deprecated might eventually be removed, which was never the intent either.” From JEP 277 Twitter: @jeanneboyarsky
  13. 13. @Deprecated New Attributes Attribute Type Description forRemoval boolean Is the intent to remove API from Java at some point? since String Version of Java when API first became deprecated (not populated for all pre-Java 9 APIs) Twitter: @jeanneboyarsky Only had for new APIs before
  14. 14. Twitter: @jeanneboyarsky
  15. 15. @Deprecated Warning types • Ordinary Deprecation • Removal @SuppressWarnings("deprecation”) @SuppressWarnings("removal”) @SuppressWarnings({"deprecation", "removal"}) Twitter: @jeanneboyarsky
  16. 16. What is deprecated for removal? • Unused code in AWT • Some old security APIs • Some thread and runtime APIs • Some Jigsaw transition modules (but not classes) • And… Twitter: @jeanneboyarsky
  17. 17. Applets Finally deprecated! But… forRemoval=false Applet Twitter: @jeanneboyarsky
  18. 18. Streams - takeWhile Stream.iterate(entry(1,1), e -> entry(e.getValue(), e.getKey()+e.getValue())) .map(Entry::getValue) .takeWhile(n -> n < 30) .forEach(System.out::println); How print all Fibonacci #s less than 30? Assumes ordered stream. Takes all elements until one doesn’t match. Twitter: @jeanneboyarsky
  19. 19. Streams - dropWhile Stream.iterate(entry(1,1), e -> entry(e.getValue(), e.getKey()+e.getValue())) .map(Entry::getValue) .dropWhile(n -> n < 30) .forEach(System.out::println); How print all Fibonacci #s greater than 30? Note: This doesn’t work. takeWhile and dropWhile aren’t always opposites. See why? Twitter: @jeanneboyarsky
  20. 20. Streams - iterate Stream.iterate(10, i-> i-1) .limit(10) .forEach(System.out::println); Stream.iterate(10, i-> i>0, i-> i-1) .forEach(System.out::println); Twitter: @jeanneboyarsky
  21. 21. Streams - ofNullable stream = dubiousObj == null ? Stream.empty() : Stream.of(dubiousObj); stream = Stream.ofNullable(dubiousObj); Twitter: @jeanneboyarsky
  22. 22. JShell • REPL for Java • Now with tab and up arrow • More packages known than Nashorn Twitter: @jeanneboyarsky
  23. 23. Random other changes • Can now have private methods in interfaces • _ is no longer a legal identifier. Still ok to have vars like _temp • sun.misc.Unsafe was replaced by VarHandle. I can’t imagine needing to do either. Maybe for low level APIs • Could use @SafeVarargs on static methods or final instance methods. Now can do the same for private instance methods Twitter: @jeanneboyarsky
  24. 24. More new APIs APIs for reactive programming: •Flow.Processor •Flow.Publisher •Flow.Subscriber •Flow.Subscription (new class Flow) Process APIs Process.pid() supportsNormalTermination() CompletableFuture<Process> onExit() info() descendants() children() Twitter: @jeanneboyarsky
  25. 25. Questions ? Twitter: @jeanneboyarsky

Notes de l'éditeur

  • https://pixabay.com/p-313586/?no_redirect
  • https://en.wikipedia.org/wiki/Java_Platform_Module_System
  • https://pixabay.com/p-485050/?no_redirect
  • http://openjdk.java.net/jeps/269
    https://pixabay.com/p-485050/?no_redirect
  • http://openjdk.java.net/jeps/269
    https://pixabay.com/p-485050/?no_redirect
  • http://openjdk.java.net/jeps/269
    https://pixabay.com/p-485050/?no_redirect
    https://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Map_of_USA_with_state_names.svg/2000px-Map_of_USA_with_state_names.svg.png
  • http://openjdk.java.net/jeps/225
    https://c1.staticflickr.com/3/2588/3781549100_6e6fbcd184_b.jpg
  • http://openjdk.java.net/jeps/225
  • http://openjdk.java.net/jeps/225
  • http://openjdk.java.net/jeps/277
  • http://openjdk.java.net/jeps/277
  • http://openjdk.java.net/jeps/277
  • http://openjdk.java.net/jeps/277
  • http://download.java.net/java/jdk9/docs/api/deprecated-list.html
    https://pixabay.com/p-1111448/?no_redirect
  • http://openjdk.java.net/jeps/289
    https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Argentina_-_NO_symbol.svg/2000px-Argentina_-_NO_symbol.svg.png
  • http://openjdk.java.net/jeps/222
    http://openjdk.java.net/jeps/236
    http://openjdk.java.net/jeps/292
    https://www.selikoff.net/2017/05/13/using-java-9s-jshell-for-experimenting/
  • http://openjdk.java.net/jeps/213
  • http://openjdk.java.net/jeps/266

×