Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Latest java

247 visualizaciones

Publicado el

Do you still write code on Java 8 or probably older!? If “Yes” then you definitely have to visit this talk. We will explore the most popular features and use cases from the latest Java Version and will discover how complicated migration is.

  • Sé el primero en comentar

  • Sé el primero en recomendar esto

Latest java

  1. 1. Latest Java Why? How?
  2. 2. About me 2 andriyrav@gmail.com @AndriyRymarAndriy Rymar
  3. 3. Agenda 3 Why? How?
  4. 4. What means «Latest Java» ? 4
  5. 5. Many many years ago… 5
  6. 6. Green Team 6 1991 Patrick Naughton Mike Sheridan James Gosling
  7. 7. JDK 1.0 7 January 23, 1996
  8. 8. Evolution 8 • JDK 1.0 (23rd Jan 1996) • JDK 1.1 (19th Feb 1997) • J2SE 1.2 (8th Dec 1998) • J2SE 1.3 (8th May 2000) • J2SE 1.4 (6th Feb 2002) • J2SE 5.0 (30th Sep 2004) • Java SE 6 (11th Dec 2006) • Java SE 7 (28th July 2011) • Java SE 8 (18th March 2014) • Java SE 9 (21st Sep 2017)
  9. 9. 9
  10. 10. 6 months release 10
  11. 11. Evolution 11 • JDK 1.0 (23rd Jan 1996) • JDK 1.1 (19th Feb 1997) • J2SE 1.2 (8th Dec 1998) • J2SE 1.3 (8th May 2000) • J2SE 1.4 (6th Feb 2002) • J2SE 5.0 (30th Sep 2004) • Java SE 6 (11th Dec 2006) • Java SE 7 (28th July 2011) • Java SE 8 (18th March 2014) • Java SE 9 (21st Sep 2017) • Java SE 10 (20th March 2018) • Java SE 11 (25th Sep 2019)
  12. 12. Latest Java 12 Java SE 12 19th March 2019
  13. 13. 13
  14. 14. Major changes 14
  15. 15. Licenses 15 Commerce Since JDK 11
  16. 16. Commerce? 16 Development Free for Production Paid for
  17. 17. OpenJDK 17
  18. 18. 18 No more updates
  19. 19. 6 months release 19
  20. 20. Azul OracleIBM Red Hat Checkpoint 1 https://img.wallpapersafari.com/desktop/1600/900/31/29/WBGxlY.jpg
  21. 21. Why? 21
  22. 22. 22 JDK 11 JDK 12JDK 8
  23. 23. 23 JDK 11 JDK 12JDK 8
  24. 24. Development features 24
  25. 25. 25 Optional Optional<Value> result = … if(result.isPresent()) { Value value = result.get(); //DO SOMETHING } else { //DO SOMETHING ELSE } jdk<9
  26. 26. 26 Optional ifPresentOrElse jdk9
  27. 27. 27 Optional Optional<Value> result = … result.ifPresentOrElse((value) -> { //DO SOMETHING },{ //DO SOMETHING ELSE }); jdk9
  28. 28. 28 Optional orElseThrow() jdk10
  29. 29. 29 Local-variables var x = new HashMap<String, String>(); jdk10
  30. 30. 30 Local-variables (var s1, var s2) -> s1 + s2 jdk11
  31. 31. 31 Local-variables (@NotNull var s1, @Nullable var s2) -> s1 + s2 jdk11
  32. 32. 32 Shebang #! jdk11 Unix-like OS
  33. 33. 33 Shebang #!/bin/sh jdk11
  34. 34. 34 Shebang DEMO jdk11
  35. 35. 35 HTTP HttpClient httpClient = HttpClient .newBuilder() .version(Version.HTTP_2) .build(); HttpRequest mainRequest = HttpRequest .newBuilder() .uri(URI.create("https:www.example.com")) .POST(BodyPublishers.ofString(data)) .build(); jdk11
  36. 36. 36 HTTP HttpClient httpClient = HttpClient .newBuilder() .version(Version.HTTP_2) .build(); HttpRequest mainRequest = HttpRequest .newBuilder() .uri(URI.create("https:www.example.com")) .POST(BodyPublishers.ofString(data)) .build(); jdk11
  37. 37. 37 HTTP HttpResponse<String> response = httpClient .send(request, BodyHandlers.ofString()); response.statusCode(); response.headers(); response.body(); jdk11
  38. 38. 38 HTTP httpClient .sendAsync(request, BodyHandlers.ofString()) .thenAccept(response -> { //DO SOMETHING }); jdk11
  39. 39. 39
  40. 40. 40 New API java.io.ByteArrayOutputStream java.io.FileWriter java.io.InputStream java.io.OutputStream java.io.Reader java.io.Writer java.lang.Character java.lang.CharSequence java.lang.ref.Reference java.lang.Runtime java.lang.System java.lang.String java.lang.StringBuffer java.lang.StringBuilder java.lang.Thread java.nio.ByteBuffer java.nio.CharBuffer java.nio.DoubleBuffer java.nio.FloatBuffer java.nio.LongBuffer java.nio.ShortBuffer java.nio.channels.SelectionKey java.nio.channels.Selector java.nio.file.Files java.nio.file.Path java.util.Collection java.util.concurrent.PriorityBlockingQueue java.util.PriorityQueue java.util.concurrent.TimeUnit java.util.function.Predicate java.util.Optional java.util.OptionalInt java.util.OptionalDouble java.util.OptionalLong java.util.regex.Pattern etc. jdk11
  41. 41. 41 New API boolean isBlank(); Stream lines(); String repeat(int); String jdk11
  42. 42. JDK features 42
  43. 43. 43 Nested-base access control public class Outer { private int intVal; class Inner { public void printOuterInt(){ System.out.println(intVal + 1); } } } jdk<11
  44. 44. 44 Nested-base access control public class Outer { private int intVal; public int access$000() { return intVal; } } class Inner$Outer { Outer outer; public void printOuterInt() { System.out.println(outer.access$000()); } } jdk<11
  45. 45. 45 Nested-base access control jdk11 getNestHost(); getNestMembers(); isNestmateOf(Class);
  46. 46. public class Outer { private int intVal; } class Inner$Outer { Outer outer; public void printOuterInt() { System.out.println(outer.intVal); } } 46 Nested-base access control jdk11
  47. 47. 47 Epsilon - garbage collector It does not collect any garbage jdk11
  48. 48. 48 Epsilon - garbage collector jdk11 short-life tasks low-latency tasks Benchmarks
  49. 49. 49 Epsilon - garbage collector OutOfMemory Heap dump Fail JVM and perform another task jdk11
  50. 50. 50 Flight recorder Low-overhead data collection framework https://www.baeldung.com/java- flight-recorder-monitoring jdk11
  51. 51. 51 jdk11
  52. 52. 52 JDK 11 Much more About 17 JEPs
  53. 53. 53 JDK 11 JDK 12JDK 8
  54. 54. 54 JDK 11 JDK 12JDK 8
  55. 55. Development features 55
  56. 56. 56 Switch expressions int salary; String level = "D1"; switch(level){ case "D0": case "D1": case "D2": salary = 500; break; case "D3": case "D4": case "D5": salary = 750; break; case "D6": case "D7": salary = 1000; break; default: salary = 750; } jdk<12
  57. 57. 57 Switch expressions String level = "D1"; int salary = switch(level){ case "D0", "D1", "D2" -> 500; case "D3", "D4", "D5" -> 750; case "D6", "D7" -> 1000; default -> 750; } jdk12
  58. 58. 58 Switch expressions String level = "D1"; var salary = switch(level){ case "D0", "D1", "D2" -> 500; case "D3", "D4", "D5" -> 750; case "D6", "D7" -> "Тобі вже досить!"; default -> "Йди гуляй!"; } jdk12
  59. 59. 59 Switch expressions Preview javac --release 12 --enable-preview -Xlint:preview <class-filename>.java jdk12
  60. 60. 60 Microbenchmark suite public class MyClass { @Benchmark @Fork(value = 1, warmups = 2) @BenchmarkMode(Mode.Throughput) public void method() { // Your code } } jdk12
  61. 61. 61 Microbenchmark suite # Run complete. Total time: 00:06:47 Benchmark (iterations) Mode Cnt Score Error Units MyClass.method 100 thrpt 20 92463.622 ± 1672.227 ops/s MyClass.method 200 thrpt 20 39737.532 ± 5294.200 ops/s MyClass.method 300 thrpt 20 30381.144 ± 614.500 ops/s MyClass.method 500 thrpt 20 18315.211 ± 222.534 ops/s MyClass.method 1000 thrpt 20 8960.008 ± 658.524 ops/s jdk12
  62. 62. 62 Collectors.teeing() jdk12
  63. 63. 63 Collectors.teeing() static <T, R1, R2, R> Collector<T, ?, R> teeing( Collector<? super T, ?, R1> downstream1, Collector<? super T, ?, R2> downstream2, BiFunction<? super R1, ? super R2, R> merger) jdk12
  64. 64. 64 Collectors.teeing() carStream.collect( Id: 1 8000$ 8500$ 7500$ 7000$ 8500$ Id: 2 Id: 3 Id: 4 Id: 5 teeing( filtering(Car::isSold(), summingInt(Car::getPrice)), new AccountancyReport::new)); filtering(Car::isNotSold(), mapping(o -> o.id, Collectors.toList())), jdk12
  65. 65. 65 Collectors.teeing() carStream.collect( Id: 1 8000$ 8500$ 7500$ 7000$ 8500$ Id: 2 Id: 3 Id: 4 Id: 5 {leftCarIds:[2, 4, 5], soldCarAmount = 15500} Collectors.teeing( Collectors.filtering(Car::isSold(), Collectors.summingInt(Car::getPrice)), (soldCarAmount, leftCarIds) -> new AccountancyReport(soldCarAmount, leftCarIds))); Collectors.filtering(Car::isNotSold(), Collectors.mapping(o -> o.id, Collectors.toList())), jdk12
  66. 66. JDK features 66
  67. 67. 67 Shenandoah Low-Pause-Time GC Mark Evacuation Update Reference Cleanup jdk12
  68. 68. 68 JDK 12 Much more About 8 JEPs
  69. 69. JDK 13 69
  70. 70. 70 JDK 13 JEP 350: Dynamic CDS Archives JEP 351: ZGC: Uncommit Unused Memory
  71. 71. Checkpoint 2 Developer Java
  72. 72. Checkpoint 2
  73. 73. How? 73
  74. 74. Easy 74 From the scratch https://ui-ex.com/images/yoda-vector-master-2.png
  75. 75. 75
  76. 76. 76 Migration • JEE Support • Update Libraries • Access to Internal API • Removed API
  77. 77. 77 Update Libraries Lombok
  78. 78. 78 Update Libraries Issues • Not supported • Not supported Lates JDK yet
  79. 79. XML WS 79 No JEE
  80. 80. 80 No JEE <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-runtime</artifactId> <version>2.4.0-b180830.0438</version> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>2.3.1</version> <type>pom</type> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>rt</artifactId> <version>2.3.1</version> </dependency>
  81. 81. 81 XML WS
  82. 82. 82 Access to Internal API package <CLASS> is declared in module <PACKAGE>, which does not export it --add-exports module/package=ALL-UNNAMED
  83. 83. java.lang.Runtime.getLocalizedInputStream() 83 Removed API javax.security.auth.Policy java.lang.Thread.stop(java.lang.Throwable) sun.misc.Base64 java.lang.SecurityManager java.lang.Runtime.getLocalizedOutputStream()
  84. 84. 84 Checkpoint 3
  85. 85. http://thenerdygiftcompany.co.uk/shop/clothing/cool-yoda/ Summary 85
  86. 86. Resources 86 https://www.javatpoint.com/history-of-java Java 11: • https://blog.jetbrains.com/idea/2018/09/using-java-11-in-production-important-things-to-know/ • https://medium.com/@javachampions/java-is-still-free-c02aef8c9e04 • https://dzone.com/articles/jdk-11-general-availability?fromrel=true • https://gunnarmorling.github.io/jdk-api-diff/jdk10-jdk11-api-diff.html Features: • https://dzone.com/articles/90-new-features-and-apis-in-jdk-11 • https://dzone.com/articles/90-new-features-and-apis-in-jdk-11-part-2?fromrel=true • https://www.journaldev.com/24601/java-11-features Migration : • https://blog.codefx.org/java/java-11-migration-guide/ • https://medium.com/criciumadev/its-time-migrating-to-java-11-5eb3868354f9 Java 12: • https://medium.com/@rajeshontech/new-features-in-java-12-b40c00f3bda5?sk=b4e07c36761d33e9bbbbb507958c8092 • https://dzone.com/articles/jdk-12-news-13-september-2018?fromrel=true • https://dzone.com/articles/a-new-jdk12-stream-api-collection-collectorsteeing
  87. 87. Thanks | Q. & A. 87 andriyrav@gmail.com @AndriyRymar

×