{"id":1112,"date":"2020-07-02T11:06:48","date_gmt":"2020-07-02T09:06:48","guid":{"rendered":"https:\/\/www.loicmathieu.fr\/wordpress\/?p=1112"},"modified":"2020-07-02T11:06:48","modified_gmt":"2020-07-02T09:06:48","slug":"java-15-quoi-de-neuf","status":"publish","type":"post","link":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-15-quoi-de-neuf\/","title":{"rendered":"Java 15 : what&#8217;s new ?"},"content":{"rendered":"<p>Now that Java 15 is features complete (Rampdown Phase One at the day of writing), it\u2019s time to walk throught all it\u2019s functionalities that brings to us, developers, this new version.<\/p>\n<p>This article is part of a series on what\u2019s new on the last versions of Java, for those who wants to read the others, here are the links : <a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-14-quoi-de-neuf\/\">Java 14<\/a>, <a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-13-quoi-de-neuf\/\">Java 13<\/a>, <a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-12-quoi-de-neuf\/\">Java 12<\/a>, <a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-11-quoi-de-neuf\/\">Java 11<\/a>,\u00a0<a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-10-quoi-de-neuf\/\">Java 10,<\/a>\u00a0and\u00a0<a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/les-nouveautes-de-java-9-pour-les-developeurs\/\">Java 9<\/a>.<\/p>\n<p>This new version brings lots of new JEPs, the main one being the addition of Sealed Classes. Records and Pattern Matching introduced in Java 14 remain in preview in this version.<\/p>\n<h2>JEP 360 : Sealed Classes<\/h2>\n<p>Sealed Classes allow you to limit the number of implementations of a class or an interface to a predefined list. The hierarchy of this class \/ interface is therefore closed (sealed).<\/p>\n<p>As this hierarchy is known at compile time, this opens up possibilities for Pattern Matching, a future implementation of switch based on the type of an object is planned in one of the next versions of Java. This also allows the author of a class \/ interface to express its use in a finer way than via visibility modifiers by restricting its use to a specific list.<\/p>\n<p>Here are some examples taken from the JEP<\/p>\n<pre><code>package com.example.geometry;\n\npublic sealed class Shape\n    permits Circle, Rectangle, Square {...}\n<\/code><\/pre>\n<p>If classes are declared in the same source file, the <code>permits<\/code> clause can be ignored.<\/p>\n<pre><code>package com.example.geometry;\n\nsealed class Shape {...}\n    class Circle    extends Shape {...}\n    class Rectangle extends Shape {...}\n    class Square    extends Shape {...}\n<\/code><\/pre>\n<p>Now that we know the list of classes implementing an interface, we can more easily write a series of if\/else on the <code>Shape<\/code> class:<\/p>\n<pre><code>Shape rotate(Shape shape, double angle) {\n    if (shape instanceof Circle) return shape;\n    else if (shape instanceof Rectangle) return shape.rotate(angle);\n    else if (shape instanceof Square) return shape.rotate(angle);\n}\n<\/code><\/pre>\n<p>When Pattern Matching would have been extended to cover Sealed Classes, we could write a switch with a test on the type of an object:<\/p>\n<pre><code>Shape rotate(Shape shape, double angle) {\n    return switch (shape) {\/\/ won't compile in Java 15 ...\n        case Circle c    -&gt; c;  \/\/ no action needed\n        case Rectangle r -&gt; r.rotate(angle);\n        case Square s    -&gt; s.rotate(angle);\n    }\n}\n<\/code><\/pre>\n<p>A new keyword has been introduced <code>non-sealed<\/code> which opens the hierarchy from one of the subclasses or subinterfaces of a sealed class.<\/p>\n<h2>Other news<\/h2>\n<ul><li><a title=\"JEP 339\" href=\"https:\/\/openjdk.java.net\/jeps\/339\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 339<\/a>: Edwards-Curve Digital Signature Algorithm (EdDSA). Implementation of the cryptography algorithm EdDSA.<\/li>\n\n<li><a title=\"JEP 373\" href=\"https:\/\/openjdk.java.net\/jeps\/373\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 373<\/a>: Reimplement the Legacy DatagramSocket API. After re-implementing the <code> java.net.Socket <\/code> and <code> java.net.ServerSocket <\/code> in Java 13, it&#8217;s the turn of <code> java.net.DatagramSocket <\/code> and <code> java.net.MulticastSocket <\/code>. The motivation is the same, replacing an aging implementation that is difficult to maintain with a more recent implementation to facilitate the future implementation of the Lightweight Thread of the Loom project.<\/li>\n\n<li><a title=\"JDK-8244441\" href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8244441\" target=\"_blank\" rel=\"noopener noreferrer\">JDK-8244441<\/a>: support of the <code>certificate_authorities<\/code> extension of TLS 1.3.<\/li>\n\n<li><a title=\"JDK-8215401\" href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8215401\">JDK-8215401<\/a>: <code>CharSequence.isEmpty()<\/code>.<\/li>\n<\/ul>\n<h2>Features that go from preview to standard<\/h2>\n<p>The following features, which were in preview, are now standard, for details on these you can refer to my previous articles.<\/p>\n<ul><li><a title=\"JEP 377\" href=\"https:\/\/openjdk.java.net\/jeps\/377\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 377<\/a>: ZGC: A Scalable Low-Latency Garbage Collector<\/li>\n\n<li><a title=\"JEP 379\" href=\"https:\/\/openjdk.java.net\/jeps\/379\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 379<\/a>: Shenandoah: A Low-Pause-Time Garbage Collector<\/li>\n\n<li><a title=\"JEP 378\" href=\"https:\/\/openjdk.java.net\/jeps\/378\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 378<\/a>: Text Blocks<\/li>\n\n<li><a title=\"JEP 358\" href=\"https:\/\/openjdk.java.net\/jeps\/358\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 358<\/a>: Helpful NullPointerExceptions. JEP 358 gave us more understandable error messages for <code>NullPointerException<\/code> in Java 14. To my regret, this feature was disabled by default. It is now enabled by default (via <a title=\"JDK-8233014\" href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8233014\" target=\"_blank\" rel=\"noopener noreferrer\">JDK -8233014<\/a>) and that&#8217;s a very good news!<\/li>\n<\/ul>\n<h2>The features that remain in preview<\/h2>\n<p>The following features remain in preview.<\/p>\n<ul><li><a title=\"JEP 375\" href=\"https:\/\/openjdk.java.net\/jeps\/375\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 375<\/a>: Pattern Matching for instanceof. No change in this version but the functionality remains in preview because changes are planned for the following versions of Java.<\/li>\n\n<li><a title=\"JEP 383\" href=\"https:\/\/openjdk.java.net\/jeps\/383\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 383<\/a>: Foreign-Memory Access API. Functionality improvements and refactoring<\/li>\n\n<li><a title=\"JEP 384\" href=\"https:\/\/openjdk.java.net\/jeps\/384\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 384<\/a>: Records. The implementation has been revised following the first preview, we now have the possibility of creating local Records and using Sealed Classes with Records.<\/li>\n<\/ul>\n<h2>Deprecated or removed features<\/h2>\n<p>A lot of deprecation and deletion in this release. Java has decided to remove some features that haven&#8217;t been used for a long time, or which affect its maintenance, and this is generally a good thing.<\/p>\n<ul><li><a title=\"JEP 385\" href=\"https:\/\/openjdk.java.net\/jeps\/385\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 385<\/a>: Deprecate RMI Activation for Removal. It is an optional part of RMI, deprecated since Java 8 and almost no longer used. It will be deleted in a future release. The rest of RMI remains supported.<\/li>\n\n<li><a title=\"JEP 381\" href=\"https:\/\/openjdk.java.net\/jeps\/381\">JEP 381<\/a>: Remove the Solaris and SPARC Ports. A page of history of the acquisition of Sun by Oracle ends. During this takeover Oracle also bought an OS (Solaris) and a CPU architecture (SPARC). These are no longer supported by Java and their implementation in the JVM (port) is removed.<\/li>\n\n<li><a title=\"JEP 374\" href=\"https:\/\/openjdk.java.net\/jeps\/374\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 374<\/a>: Disable and Deprecate Biased Locking. Bias locking is a technique for optimizing locks that are used by a single thread. It would no longer be as relevant these days with modern CPU architectures, and entail a fairly high maintenance cost. It becomes disabled by default and will be removed in a future version.<\/li>\n\n<li><a title=\"JEP 372\" href=\"https:\/\/openjdk.java.net\/jeps\/372\" target=\"_blank\" rel=\"noopener noreferrer\">JEP 372<\/a>: Remove the Nashorn JavaScript Engine. Nashorn has been integrated into Java 8, deprecated in Java 11, and now removed. To execute JavaScript in the JVM you have to turn to GraalVM. Nashorn was no longer up to date with new versions of ECMAScript and its support was too expensive while a quality alternative exists with GraalVM.<\/li>\n<\/ul>\n<h2>Performance<\/h2>\n<p>Each release brings its share of performance improvements, both in peak performance and in start-up time.<\/p>\n<p>And the release 15 have some important optimizations:<\/p>\n<ul><li>G1: The default Garbage Collector has had several improvements in this release, the most interesting is the one described in the article by Stefan Johansson<a href=\"https:\/\/kstefanj.github.io\/2020\/04\/16\/g1-ootb-performance.html\" target=\"_blank\" rel=\"noopener noreferrer\">Improving G1 out-of-the-box performance<\/a> which allows a better calculation of the size of the heap regions, especially when the Xmx and the Xms are not the same.<\/li>\n\n<li>ZIP lookup: When starting a JVM, it will search (lookup) for entries (classes, resources) in JARs (which are ZIP), significant improvements have been made by a serie of patchs which leads to a gain not negligible for reading these entries. Details are on Claes Redestad&#8217;s blog <a title=\"Zip lookups - a word from the sponsor\" href=\"https:\/\/cl4es.github.io\/2020\/04\/27\/Zip-Lookups.html\" target=\"_blank\" rel=\"noopener noreferrer\">Zip lookups &#8211; a word from the sponsor<\/a><\/li>\n\n<li>StringConcat: String concatenation is optimized from Java 9 via a StringConcatFactory. This one has been refactored to take less time to start as well as to optimize for the most classic cases of concatenation.<\/li>\n\n<li>AppCDS: Application Class Data Sharing is a feature that allows you to create an archive of class metadata to load when starting a JVM, this avoids searching on the disk, reading and parsing a class (small description of AppCDS <a title=\"Quarkus, jlink et Application Class Data Sharing (AppCDS)\" href=\"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/quarkus-jlink-et-application-class-data-sharing-appcds\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>). With Java 15, the metadata of lambdas are added to the archive.<\/li>\n<\/ul>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Now that Java 15 is features complete (Rampdown Phase One at the day of writing), it\u2019s time to walk throught all it\u2019s functionalities that brings to us, developers, this new version. This article is part of a series on what\u2019s new on the last versions of Java, for those who wants to read the others, here are the links : Java 14, Java 13, Java 12, Java 11,\u00a0Java 10,\u00a0and\u00a0Java 9. This new version brings lots of new JEPs, the main&#8230;<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-15-quoi-de-neuf\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9],"tags":[11,186,163],"class_list":["post-1112","post","type-post","status-publish","format-standard","hentry","category-informatique","tag-java","tag-java15","tag-whatsnew"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":722,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-10-quoi-de-neuf\/","url_meta":{"origin":1112,"position":0},"title":"Java 10 : what&#8217;s new ?","author":"admin","date":"Monday March 26th, 2018","format":false,"excerpt":"Now that java 10 is out, it's time to look at all the new functionalities of this version. Like my previous article on Java 9, I will focus on the changes that will impact developers that uses Java leaving aside the changes that are internal\/very small\/on rarely used API. The\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1375,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-18-quoi-de-neuf\/","url_meta":{"origin":1112,"position":1},"title":"Java 18 : what&#8217;s new ?","author":"admin","date":"Tuesday January  4th, 2022","format":false,"excerpt":"Now that Java 18 is features complete (Rampdown Phase One at the day of writing), it\u2019s time to walk throught all the functionalities that brings to us, developers, this new version. This article is part of a series on what\u2019s new on the last versions of Java, for those who\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":947,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-13-quoi-de-neuf\/","url_meta":{"origin":1112,"position":2},"title":"Java 13 : what&#8217;s new ?","author":"admin","date":"Tuesday August 13th, 2019","format":false,"excerpt":"Now that Java 13 is features complete (Release Candidate at the day of writing), it\u2019s time to walk throught all it\u2019s functionalities that brings to us, developers, this new version. This article is part of a series on what\u2019s new on the last versions of Java, for those who wants\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1572,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-20-quoi-de-neuf\/","url_meta":{"origin":1112,"position":3},"title":"Java 20: what&#8217;s new ?","author":"admin","date":"Wednesday December 14th, 2022","format":false,"excerpt":"Now that Java 20 is features complete (Rampdown Phase One at the day of writing), it\u2019s time to walk through all the functionalities that bring to us, developers, this new version. This article is part of a series on what\u2019s new on the last versions of Java, for those who\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1684,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-21-quoi-de-neuf\/","url_meta":{"origin":1112,"position":4},"title":"Java 21: what&#8217;s new ?","author":"admin","date":"Tuesday August  8th, 2023","format":false,"excerpt":"Now that Java 21 is features complete (Rampdown Phase Two at the day of writing), it\u2019s time to walk through all the functionalities that bring to us, developers, this new version. This article is part of a series on what\u2019s new on the last versions of Java, for those who\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"Java Collection API hierarchy","src":"https:\/\/i0.wp.com\/cr.openjdk.org\/~smarks\/collections\/SequencedCollectionDiagram20220216.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/cr.openjdk.org\/~smarks\/collections\/SequencedCollectionDiagram20220216.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/cr.openjdk.org\/~smarks\/collections\/SequencedCollectionDiagram20220216.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/cr.openjdk.org\/~smarks\/collections\/SequencedCollectionDiagram20220216.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/cr.openjdk.org\/~smarks\/collections\/SequencedCollectionDiagram20220216.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/cr.openjdk.org\/~smarks\/collections\/SequencedCollectionDiagram20220216.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1758,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-22-quoi-de-neuf\/","url_meta":{"origin":1112,"position":5},"title":"Java 22: what&#8217;s new?","author":"admin","date":"Monday January  8th, 2024","format":false,"excerpt":"Now that Java 22 is features complete (Rampdown Phase One at the day of writing), it\u2019s time to walk through all the functionalities that bring to us, developers, this new version. This article is part of a series on what\u2019s new on the last versions of Java, for those who\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/posts\/1112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/comments?post=1112"}],"version-history":[{"count":0,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/posts\/1112\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/media?parent=1112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/categories?post=1112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/tags?post=1112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}