{"id":2274,"date":"2020-02-21T01:12:15","date_gmt":"2020-02-21T01:12:15","guid":{"rendered":"http:\/\/kusuaks7\/?p=1879"},"modified":"2024-01-04T15:09:43","modified_gmt":"2024-01-04T15:09:43","slug":"whats-new-in-java-14","status":"publish","type":"post","link":"https:\/\/www.experfy.com\/blog\/software-ux-ui\/whats-new-in-java-14\/","title":{"rendered":"What\u2019s New in Java 14?"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"2274\" class=\"elementor elementor-2274\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"has_eae_slider elementor-section elementor-top-section elementor-element elementor-element-4ea5b9d8 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"4ea5b9d8\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"has_eae_slider elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-58bfba26\" data-id=\"58bfba26\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-418676a1 elementor-widget elementor-widget-text-editor\" data-id=\"418676a1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<section>\n<p id=\"e6b0\" data-selectable-paragraph=\"\">Java 14 is going to be released on March 17, 2020. Besides ~2,400 bug fixes and small enhancements, the new version of Java contains 16 major enhancements, also called JEPs (Java Enhancement Proposals).<\/p>\n<p id=\"9fb5\" data-selectable-paragraph=\"\">Let\u2019s take a closer look at the major updates in Java 14: new switch expressions, better\u00a0<code>NullPointerException<\/code>s, improvements in garbage collection, JFR event streaming, and more.<\/p>\n\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-43b40e5 elementor-widget elementor-widget-image\" data-id=\"43b40e5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/648\/0*ABhRToGeo9b4Y5CE.jpg\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"has_eae_slider elementor-section elementor-top-section elementor-element elementor-element-e791ed9 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e791ed9\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"has_eae_slider elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-34839e3\" data-id=\"34839e3\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-017a839 elementor-widget elementor-widget-text-editor\" data-id=\"017a839\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p style=\"text-align: center;\" data-selectable-paragraph=\"\">Image source: Author<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9b11353 elementor-widget elementor-widget-heading\" data-id=\"9b11353\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"f11e\" data-selectable-paragraph=\"\">Switch Expressions<\/h1>\n<\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-35330b5 elementor-widget elementor-widget-text-editor\" data-id=\"35330b5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"2faf\" data-selectable-paragraph=\"\">This update to the Java language was already available in Java 12 and 13 but only as a preview language feature, which means it was not enabled by default. Finally, the new switch expressions are released in Java 14. Making a long story short, Java 14 introduces a new simplified form of a switch block with\u00a0<code>case L -&gt; ...<\/code>\u00a0labels. The new switch expressions may help to simplify code in some cases. Here are a couple of examples.<\/p>\n<p id=\"6163\" data-selectable-paragraph=\"\">Let\u2019s assume that we have an enum that describes weekdays. We can write the following code using the new switch expressions:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b9f95c2 elementor-widget elementor-widget-text-editor\" data-id=\"b9f95c2\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">switch (day) {\ncase MONDAY\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -&gt; System.out.println(&#8220;Aweful&#8221;);\ncase TUESDAY, WEDNESDAY\u00a0 -&gt; System.out.println(&#8220;Okay&#8221;);\ncase THURSDAY\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -&gt; System.out.println(&#8220;Good&#8221;);\ncase FRIDAY\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -&gt; System.out.println(&#8220;Great&#8221;);\ncase SATURDAY, SUNDAY\u00a0\u00a0\u00a0 -&gt; System.out.println(&#8220;Awesome&#8221;);\n}<\/span><\/div>\n<p id=\"8d19\" data-selectable-paragraph=\"\">Here we just used a single expression for each\u00a0<code>case<\/code>. Note that the\u00a0<code>switch<\/code>\u00a0block doesn&#8217;t use any\u00a0<code>break<\/code>\u00a0statement, which makes it much shorter. The next example shows how the new switch expressions can return a value:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-457a719 elementor-widget elementor-widget-text-editor\" data-id=\"457a719\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">int numLetters = switch (day) {\ncase MONDAY, FRIDAY, SUNDAY -&gt; 6;\ncase TUESDAY\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -&gt; 7;\ncase THURSDAY, SATURDAY\u00a0\u00a0\u00a0\u00a0 -&gt; 8;\ncase WEDNESDAY\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -&gt; 9;\n};<\/span><\/div>\n<p id=\"fa83\" data-selectable-paragraph=\"\">It\u2019s also possible to write multi-line blocks and return a value with a new keyword\u00a0<code>yield<\/code>:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-68c7732 elementor-widget elementor-widget-text-editor\" data-id=\"68c7732\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">int result = switch (s) {\ncase &#8220;Foo&#8221; -&gt; 1;\ncase &#8220;Bar&#8221; -&gt; 2;\ndefault\u00a0\u00a0\u00a0 -&gt; {\nSystem.out.println(&#8220;Neither Foo nor Bar, hmmm&#8230;&#8221;);\nyield 0;\n}\n};<\/span><\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fc2c65a elementor-widget elementor-widget-text-editor\" data-id=\"fc2c65a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"a0c1\" data-selectable-paragraph=\"\">There are several important things that you need to keep in mind when you use the new switch expressions. For example, the cases of new switch expressions have to be exhaustive. It means that, for all possible values, there has to be a matching switch label. Or, since\u00a0<code>yield<\/code>\u00a0is now a keyword, a class with a name\u00a0<code>yield<\/code>\u00a0now becomes illegal in Java 14.<\/p>\n<p id=\"8839\" data-selectable-paragraph=\"\">If you&#8217;d like to learn more about the new switch expressions, you&#8217;re welcome to read\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/361\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 361<\/a>. The authors provided quite a lot of useful info about the new switch expressions.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-03c9f12 elementor-widget elementor-widget-heading\" data-id=\"03c9f12\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"c97f\" data-selectable-paragraph=\"\">Helpful NullPointerExceptions<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a72356b elementor-widget elementor-widget-text-editor\" data-id=\"a72356b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"0366\" data-selectable-paragraph=\"\">The JVM throws a\u00a0<code>NullPointerException<\/code>\u00a0(NPE) when code tries to dereference a null reference. All Java developers have seen them before. For example, the following code may result in an NPE:<\/p>\n\n<pre>foo.bar = 10;<\/pre>\n<p id=\"61a0\" data-selectable-paragraph=\"\">The NPE is going to look like the following:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-51de7fe elementor-widget elementor-widget-text-editor\" data-id=\"51de7fe\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">Exception in thread &#8220;main&#8221; java.lang.NullPointerException\nat App.main(App.java:17)<\/span><\/div>\n<p id=\"746c\" data-selectable-paragraph=\"\">The exception message contains a filename and a line where the null dereference happened. For the\u00a0<code>foo.bar = 10;<\/code>\u00a0statement, it&#8217;s not too difficult to figure out that the NPE was thrown because the\u00a0<code>foo<\/code>\u00a0variable was null. Unfortunately, sometimes it\u2019s not clear what exactly causes an NPE. For example, if either\u00a0<code>a<\/code>,\u00a0<code>b<\/code>\u00a0or\u00a0<code>c<\/code>\u00a0is null, then an NPE is going to be thrown:<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c05dec3 elementor-widget elementor-widget-text-editor\" data-id=\"c05dec3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>a.b.c.d = 42;<\/pre>\n<p id=\"e052\" data-selectable-paragraph=\"\">However, no matter which field was null, the NPE is going to look the same. It doesn\u2019t give any clue which field was actually null.<\/p>\n<p id=\"3ebf\" data-selectable-paragraph=\"\">Here is another example. If one of the nested arrays is null, it results in an NPE:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c146dc5 elementor-widget elementor-widget-text-editor\" data-id=\"c146dc5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>a[i][j][k] = 99;<\/pre>\n<p id=\"3080\" data-selectable-paragraph=\"\">Again, no matter which array was null, the NPE is going to look the same.<\/p>\n<p id=\"8acf\" data-selectable-paragraph=\"\">Java 14 addresses this problem and makes NPEs more friendly. Now the JVM can figure out which variable was null, and then it lets the user know about it in the exception message. For example, a null dereference in the line\u00a0<code>foo.bar = 10;<\/code>\u00a0is going to result in the following NPE:<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-96a9cda elementor-widget elementor-widget-text-editor\" data-id=\"96a9cda\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">Exception in thread &#8220;main&#8221; java.lang.NullPointerException:\nCannot assign field &#8220;bar&#8221; because &#8220;foo&#8221; is null\nat App.main(App.java:17)<\/span><\/div>\n<p id=\"1382\" data-selectable-paragraph=\"\">A null dereference in the line\u00a0<code>a.b.c.d = 41;<\/code>\u00a0is going to result in the following NPE if\u00a0<code>a.b<\/code>\u00a0was null:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-48bb403 elementor-widget elementor-widget-text-editor\" data-id=\"48bb403\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">Exception in thread &#8220;main&#8221; java.lang.NullPointerException:\nCannot read field &#8220;c&#8221; because &#8220;a.b&#8221; is null\nat App.main(App.java:17)<\/span><\/div>\n<p id=\"3d1b\" data-selectable-paragraph=\"\">The new info in\u00a0<code>NullPointerException<\/code>s may be very helpful in analyzing its root cause and can make the developer\u2019s life a bit easier. By the way, the improvement has been available in SAP\u2019s JVM since 2006. Unfortunately, it took 14 years to finally bring it into OpenJDK.<\/p>\n<p id=\"d104\" data-selectable-paragraph=\"\">If you\u2019re interested in the details, the authors of the\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/358\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 358<\/a>\u00a0provided a lot of info about the new feature.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b06e07a elementor-widget elementor-widget-heading\" data-id=\"b06e07a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"255a\" data-selectable-paragraph=\"\">Packaging Tool (Incubator)<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"has_eae_slider elementor-section elementor-top-section elementor-element elementor-element-fe0e307 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"fe0e307\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"has_eae_slider elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-9adc336\" data-id=\"9adc336\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-67b6955 elementor-widget elementor-widget-text-editor\" data-id=\"67b6955\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"846c\" data-selectable-paragraph=\"\">Currently, a Java application is usually distributed as a simple JAR file. However, it\u2019s not very convenient, especially for a user of the application. It would be much better if the Java application were an installable package like MSI on Windows or DMG on Mac. This would allow Java applications to be distributed, installed, and uninstalled in a way that is familiar to users.<\/p>\n<p id=\"9458\" data-selectable-paragraph=\"\"><a href=\"https:\/\/openjdk.java.net\/jeps\/343\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 343<\/a>\u00a0introduces the\u00a0<code>jpackage<\/code>\u00a0tool, which packages a Java application into a platform-specific package that includes all of the necessary dependencies. Here\u2019s a list of supported package formats:<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a311b99 elementor-widget elementor-widget-text-editor\" data-id=\"a311b99\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul>\n \t<li id=\"69c2\" data-selectable-paragraph=\"\">DEB and RPM on Linux<\/li>\n \t<li id=\"61d0\" data-selectable-paragraph=\"\">PKG and DMG on macOS<\/li>\n \t<li id=\"3dda\" data-selectable-paragraph=\"\">MSI and EXE on Windows<\/li>\n<\/ul>\n<p id=\"0171\" data-selectable-paragraph=\"\">Here is an example of how the new tool can be used:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6477e61 elementor-widget elementor-widget-text-editor\" data-id=\"6477e61\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">$ jpackage &#8211;name myapp &#8211;input lib &#8211;main-jar main.jar\n&#8211;main-class myapp.Main<\/span><\/div>\n<p id=\"eb7d\" data-selectable-paragraph=\"\">It takes the\u00a0<code>lib\/main.jar<\/code>\u00a0file and produces a package in the format most appropriate for the system on which it is run. The entry point is the\u00a0<code>myapp.Main<\/code>\u00a0class.<\/p>\n<p id=\"b1a1\" data-selectable-paragraph=\"\">The JEP\u2019s authors provided quite a lot of useful\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/343\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">information about the new tool<\/a>.<\/p>\n<p id=\"b0da\" data-selectable-paragraph=\"\">Although the\u00a0<code>jpackage<\/code>\u00a0tool is available in JDK 14, it&#8217;s delivered as an incubator module, which means that the functionality is not guaranteed to be stable and may be revised in a future release.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fd9e8e7 elementor-widget elementor-widget-heading\" data-id=\"fd9e8e7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"982f\" data-selectable-paragraph=\"\">Better Garbage Collection<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b835104 elementor-widget elementor-widget-text-editor\" data-id=\"b835104\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"9507\" data-selectable-paragraph=\"\">Java 14 contains multiple enhancements in garbage collection.<\/p>\n<p id=\"d5b2\" data-selectable-paragraph=\"\"><a href=\"https:\/\/openjdk.java.net\/jeps\/345\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 345<\/a>\u00a0improves the G1 garbage collector by implementing NUMA-aware memory allocation. By the way, NUMA stands for Non-Uniform Memory Access. This feature has been implemented in the parallel garbage collector for a long time. Now it can be enabled in the G1 as well by running Java with a new\u00a0<code>+XX:+UseNUMA<\/code>\u00a0command-line option. This should improve G1 performance on large machines.<\/p>\n<p id=\"d05d\" data-selectable-paragraph=\"\"><a href=\"https:\/\/openjdk.java.net\/jeps\/363\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 363<\/a>\u00a0removes the Concurrent Mark Sweep (CMS) garbage collector which was deprecated a couple of years ago. Goodbye CMS!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4870987 elementor-widget elementor-widget-text-editor\" data-id=\"4870987\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"6730\" data-selectable-paragraph=\"\"><a href=\"https:\/\/openjdk.java.net\/jeps\/364\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 364<\/a>\u00a0and\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/365\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 365<\/a>\u00a0make the Z garbage collector (ZGC) available on macOS and Windows. ZGC is a concurrent garbage collector that was added to the JVM a couple of years ago. ZGC tries to reduce pause times for garbage collections and can handle heaps of size ranging from a few hundred megabytes to multi-terabytes. Previously, the collector could run only on Linux.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ec7f83f elementor-widget elementor-widget-text-editor\" data-id=\"ec7f83f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/openjdk.java.net\/jeps\/366\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 366<\/a>\u00a0deprecates the combination of the Parallel Scavenge and Serial Old garbage collection algorithms. This combination had to be enabled by the user with the\u00a0<code>-XX:+UseParallelGC -XX:-UseParallelOldGC<\/code>\u00a0command-line options. The authors believe that the combination is uncommon but requires a significant amount of maintenance effort. In fact, the option\u00a0<code>-XX:UseParallelOldGC<\/code>\u00a0is now deprecated. A warring is going to be displayed if the deprecated modes are used.\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7135b3a elementor-widget elementor-widget-heading\" data-id=\"7135b3a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"e0ea\" data-selectable-paragraph=\"\">JFR Event Streaming<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d5d4de9 elementor-widget elementor-widget-text-editor\" data-id=\"d5d4de9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"d6e0\" data-selectable-paragraph=\"\">JDK Flight Recorder (JFR) is an event recorder that is built into the JVM. It captures diagnostic and profiling data about the JVM itself, and the application running in the JVM. JFR used to be a proprietary tool, but it was open-sourced in 2018 Java released as part of OpenJDK 11.<\/p>\n<p id=\"56fc\" data-selectable-paragraph=\"\">To consume the data provided by JFR, a user has to start a recording, stop it, dump the contents to disk, and then parse the recording file. This works quite well for application profiling but not for monitoring purposes.<\/p>\n<p id=\"e859\" data-selectable-paragraph=\"\">In Java 14, the JFR allows users to subscribe to events asynchronously. Users can now register a handler that\u2019s going to be invoked in response to the arrival of an event. The\u00a0<code>RecordingStream<\/code>\u00a0class provides a uniform way to filter and consume events. Here is an example provided by the JEP&#8217;s authors:<\/p>\n<p id=\"6d83\" data-selectable-paragraph=\"\">More info can be found in\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/349\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 349<\/a>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1423216 elementor-widget elementor-widget-heading\" data-id=\"1423216\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"fae6\" data-selectable-paragraph=\"\">Language preview features<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8554456 elementor-widget elementor-widget-text-editor\" data-id=\"8554456\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"5df4\" data-selectable-paragraph=\"\">Java 14 contains several updates to the Java language with are not yet available by default.<\/p>\n<p id=\"e9d4\" data-selectable-paragraph=\"\">First,\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/305\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 305<\/a>\u00a0extends the\u00a0<code>instanceof<\/code>\u00a0operator with a binding variable. Here is an example:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f961c59 elementor-widget elementor-widget-text-editor\" data-id=\"f961c59\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">if (obj instanceof String s) {\n\/\/ can use s here\n}<\/span><\/div>\n<p id=\"aa1f\" data-selectable-paragraph=\"\">If\u00a0<code>obj<\/code>\u00a0is an instance of\u00a0<code>String<\/code>, then it is cast to\u00a0<code>String<\/code>\u00a0and assigned to the binding variable\u00a0<code>s<\/code>.<\/p>\n<p id=\"7e4e\" data-selectable-paragraph=\"\">Second,\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/359\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 359<\/a>\u00a0introduces records to the Java language. A record has a name and a state description. The state description declares the components of the record. A record may also have a body. Here is a short example:<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-236856b elementor-widget elementor-widget-text-editor\" data-id=\"236856b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>record Point(int x, int y) {}<\/pre>\n<p id=\"1d64\" data-selectable-paragraph=\"\">Third, after collecting feedback for Java 13,\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/368\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 368<\/a>\u00a0adds a couple of new escape sequences for the text blocks that were previously introduced in Java 13 as a language preview feature.<\/p>\n<p id=\"d958\" data-selectable-paragraph=\"\">Unfortunately, these three updates are still only available as preview language features that are not enabled by default. To enable the new syntax, you\u2019ll have to run the Java compiler with\u00a0<code>--enable-preview --release 14<\/code>\u00a0options and then launch\u00a0<code>java<\/code>\u00a0with\u00a0<code>--enable-preview<\/code>\u00a0option:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-25c6297 elementor-widget elementor-widget-text-editor\" data-id=\"25c6297\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div style=\"background: #eee; border: 1px solid #ccc; padding: 5px 10px;\"><span style=\"font-family: courier new,courier,monospace;\">$ javac -d classes &#8211;enable-preview &#8211;release 14 Test.java\n$ java -classpath classes &#8211;enable-preview Test<\/span><\/div>\n<\/section>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-44a252b elementor-widget elementor-widget-heading\" data-id=\"44a252b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"9827\" data-selectable-paragraph=\"\">The Rest<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3cf85b1 elementor-widget elementor-widget-text-editor\" data-id=\"3cf85b1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"1ad8\" data-selectable-paragraph=\"\">What else has changed in Java 14?<\/p>\n<p id=\"5d65\" data-selectable-paragraph=\"\"><a href=\"https:\/\/openjdk.java.net\/jeps\/370\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 370<\/a>\u00a0introduces an API to allow Java applications to safely and efficiently access foreign memory outside of the Java heap. Sounds scary. The new API should become an alternative to the\u00a0<code>java.nio.ByteBuffer<\/code>\u00a0and\u00a0<code>sun.misc.Unsafe<\/code>\u00a0classes. This feature is provided as an incubating module.<\/p>\n<p id=\"f6fc\" data-selectable-paragraph=\"\"><a href=\"https:\/\/openjdk.java.net\/jeps\/352\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 352<\/a>\u00a0adds new file mapping modes so that the\u00a0<code>FileChannel<\/code>\u00a0API can be used to create\u00a0<code>MappedByteBuffer<\/code>\u00a0instances that refer to non-volatile memory (NVM).<\/p>\n<p id=\"45c6\" data-selectable-paragraph=\"\">The Pack200 tool was deprecated in Java 11. Now\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/367\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 367<\/a>\u00a0removed the tool and its API.<\/p>\n<p id=\"45e1\" data-selectable-paragraph=\"\">In case you know about Solaris and SPARC,\u00a0<a href=\"https:\/\/openjdk.java.net\/jeps\/362\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">JEP 362<\/a>\u00a0drops support for the Solaris\/SPARC, Solaris\/x64, and Linux\/SPARC platforms. In the future, the ports on these platforms most likely are going to be removed from OpenJDK.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a539c9b elementor-widget elementor-widget-heading\" data-id=\"a539c9b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"cb34\" data-selectable-paragraph=\"\">Conclusion<\/h1><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a26fc78 elementor-widget elementor-widget-text-editor\" data-id=\"a26fc78\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"4e0b\" data-selectable-paragraph=\"\">Compared to the five JEPs in Java 13, the new Java 14 delivers many more major enhancements. The updates touch various areas. Most likely, the most interesting updates for Java developers are going to be the new switch expressions and the enhanced\u00a0<code>NullPointerException<\/code>s. Don\u2019t forget to try out the new language preview features and provide your feedback to the JDK developers. Enjoy the new Java 14!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2008d81 elementor-widget elementor-widget-heading\" data-id=\"2008d81\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"1b6d\" data-selectable-paragraph=\"\">Link<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-eea50cd elementor-widget elementor-widget-text-editor\" data-id=\"eea50cd\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul>\n \t<li id=\"e6ba\" data-selectable-paragraph=\"\"><a href=\"https:\/\/openjdk.java.net\/projects\/jdk\/14\/\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">OpenJDK 14 schedule and the list of enhancements<\/a><\/li>\n<\/ul>\nThis article originally appeared on <a href=\"https:\/\/medium.com\/better-programming\/whats-new-in-java-14-a472ec291c05\" class=\"broken_link\" rel=\"noopener\">Medium<\/a>.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Compared to the five JEPs in Java 13, the new version of Java 14 contains 16 major enhancements, also called JEPs (Java Enhancement Proposals).The updates touch various areas. Most likely, the most interesting updates for Java developers are going to be the new switch expressions and the enhanced&nbsp;NullPointerExceptions. Don&rsquo;t forget to try out the new language preview features and provide your feedback to the JDK developers. Enjoy the new Java 14!<\/p>\n","protected":false},"author":732,"featured_media":3759,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[200],"tags":[106],"ppma_author":[3576],"class_list":["post-2274","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-ux-ui","tag-software"],"authors":[{"term_id":3576,"user_id":732,"is_guest":0,"slug":"artem-smotrakov","display_name":"Artem Smotrakov","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","user_url":"","last_name":"Smotrakov","first_name":"Artem","job_title":"","description":"Artem Smotrakov is Senior Developer Security and Open Source at SAP."}],"_links":{"self":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/2274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/users\/732"}],"replies":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/comments?post=2274"}],"version-history":[{"count":7,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/2274\/revisions"}],"predecessor-version":[{"id":35397,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/2274\/revisions\/35397"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/media\/3759"}],"wp:attachment":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/media?parent=2274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/categories?post=2274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/tags?post=2274"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=2274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}