{"id":433,"date":"2020-04-11T07:22:53","date_gmt":"2020-04-11T07:22:53","guid":{"rendered":"https:\/\/www.javaindia.in\/blog\/?p=433"},"modified":"2020-08-05T08:16:02","modified_gmt":"2020-08-05T08:16:02","slug":"java-14-arrived-whats-new-for-web-application-development","status":"publish","type":"post","link":"https:\/\/www.javaindia.in\/blog\/java-14-arrived-whats-new-for-web-application-development\/","title":{"rendered":"Java 14 Arrived: What\u2019s New for Web Application Development?"},"content":{"rendered":"<p style=\"text-align: justify;\"><span style=\"color: #000000;\">Java 14 and its open-source Java Development Kit 14 has been released for developers, the most popular coding language for application development in the world. With version 14 significant numbers of Java Enhancement Proposals (JEPs) have been introduced for usage.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\">JAVA 14 addresses several remarkable features ranging from the Java language support to the latest APIs. So what is in store for the Java developers who write and maintain code for<\/span> <a href=\"https:\/\/www.javaindia.in\/\"><strong>Java development services<\/strong><\/a> <span style=\"color: #000000;\">on a daily basis? The entire feature list comprises of:<\/span><\/p>\n<ol style=\"text-align: justify;\">\n<li><span style=\"color: #000000;\"><strong>Switch Expressions<\/strong><\/span><\/li>\n<\/ol>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\">In Java 14 release, switch expressions become permanent. In earlier releases of Java, switch expressions were offered as \u201cpreview\u201d feature. The new switch expressions ensure fewer errors within the code due to the absence of fall-through behaviour, exhaustiveness, and ease of writing. This is all possible because of the expression and compound form. A switch expression can leverage the arrow syntax, as shown in the example:<\/span><\/p>\n<pre class=\"le lf lg lh li hk fj ci\"><span style=\"color: #000000;\"><span class=\"nu mx dx aq ns b ea nv nw l nx\" data-selectable-paragraph=\"\">var log = switch (event) {\r\ncase PLAY -&gt; \"User has triggered the play button\";\r\ncase STOP, PAUSE -&gt; \"User needs a break\";\r\ndefault -&gt; {\r\nString message = event.toString();\r\nLocalDateTime now = LocalDateTime.now();\r\nyield \"Unknown event \" + message +\r\n\" logged on \" + now;\r\n}\r\n};<\/span><\/span><\/pre>\n<ol style=\"text-align: justify;\" start=\"2\">\n<li><span style=\"color: #000000;\"><strong> Text Blocks<\/strong><\/span><\/li>\n<\/ol>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\">Java 13 was released with text blocks as a preview feature. This feature makes it simple to work with multiline string literals. This feature is released again with the Java 14 and includes a couple of tweaks. It is quite common to write code with different string concatenations and escape sequences to provide proper multiline text formatting. This is an important feature used by<\/span> <a href=\"https:\/\/www.javaindia.in\/services\/java-web-application-development\"><strong>Java web Development Company<\/strong><\/a> <span style=\"color: #000000;\">during any development work. The code below shows an example for HTML formatting:<\/span><\/p>\n<pre class=\"le lf lg lh li hk fj ci\"><span style=\"color: #000000;\"><span class=\"nu mx dx aq ns b ea nv nw l nx\" data-selectable-paragraph=\"\">String html = \"&lt;HTML&gt;\" +\r\n\"\\n\\t\" + \"&lt;BODY&gt;\" +\r\n\"\\n\\t\\t\" + \"&lt;H1&gt;\\\"Java 14 is here!\\\"&lt;\/H1&gt;\" +\r\n\"\\n\\t\" + \"&lt;\/BODY&gt;\" +\r\n\"\\n\" + \"&lt;\/HTML&gt;\";\r\n\r\nYou can simplify this process by writing more elegant code using text blocks like:\r\n\r\nString html = \"\"\"\r\n&lt;HTML&gt;\r\n&lt;BODY&gt;\r\n&lt;H1&gt;\"Java 14 is here!\"&lt;\/H1&gt;\r\n&lt;\/BODY&gt;\r\n&lt;\/HTML&gt;\"\"\";<\/span><\/span><\/pre>\n<ol style=\"text-align: justify;\" start=\"3\">\n<li><span style=\"color: #000000;\"><strong> Records<\/strong><\/span><\/li>\n<\/ol>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\">Record is another preview language feature in Java 14. Like other ideas, this feature helps to reduce verbosity in Java and helping developers to write more concise code. Records focus on certain domain classes which store data in fields and do not declare any custom behaviours.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\">Here\u2019s a fully generated implementation for the BankTransaction class:<\/span><\/p>\n<pre class=\"le lf lg lh li hk fj ci\"><span style=\"color: #000000;\"><span class=\"nu mx dx aq ns b ea nv nw l nx\" data-selectable-paragraph=\"\">public class BankTransaction {\r\nprivate final LocalDate date;\r\nprivate final double amount;\r\nprivate final String description;\u00a0\r\npublic BankTransaction(final LocalDate date,\r\nfinal double amount,\r\nfinal String description) {\r\nthis.date = date;\r\nthis.amount = amount;\r\nthis.description = description;\r\n}\r\npublic LocalDate date() {\r\nreturn date;\r\n}\r\npublic double amount() {\r\nreturn amount;\r\n}\r\npublic String description() {\r\nreturn description;\r\n}\r\n\r\n@Override\r\npublic String toString() {\r\nreturn \"BankTransaction{\" +\r\n\"date=\" + date +\r\n\", amount=\" + amount +\r\n\", description='\" + description + '\\'' +\r\n'}';\r\n}\r\n\r\n@Override\r\npublic boolean equals(Object o) {\r\nif (this == o) return true;\r\nif (o == null || getClass() != o.getClass()) return false;\r\nBankTransaction that = (BankTransaction) o;\r\nreturn Double.compare(that.amount, amount) == 0 &amp;&amp;\r\ndate.equals(that.date) &amp;&amp;\r\ndescription.equals(that.description);\r\n}\r\n\r\n@Override\r\npublic int hashCode() {\r\nreturn Objects.hash(date, amount, description);\r\n}\r\n}<\/span><\/span><\/pre>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\">This provides a way to remove the verbosity and release a class that only aggregates data together with the implementations of the equals, hashCode, and toString methods.<\/span><\/p>\n<ol style=\"text-align: justify;\" start=\"4\">\n<li><span style=\"color: #000000;\"><strong> NullPointer Exceptions<\/strong><\/span><\/li>\n<\/ol>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\">Some developers consider throwing NullPointerExceptions like new \u201cHello world\u201d in Java because it is impossible to escape from them. Jokes aside, they cause problems because they often appear in application logs when code is running in a production environment, which can make the debugging hard because the original code is not readily present. For example, consider the code below:<\/span><\/p>\n<pre class=\"le lf lg lh li hk fj ci\"><span style=\"color: #000000;\"><span class=\"nu mx dx aq ns b ea nv nw l nx\" data-selectable-paragraph=\"\">var name = user.getLocation().getCity().getName();\r\n\r\nBefore Java 14, the following error is displayed:\r\nException in thread \"main\" java.lang.NullPointerException\r\nat NullPointerExample.main(NullPointerExample.java:5)\r\n\r\nNow, with release of Java 14, there\u2019s a new JVM feature that can receive more-informative diagnostics:\r\nException in thread \"main\" java.lang.NullPointerException: Cannot invoke \"Location.getCity()\" because the return value of \"User.getLocation()\" is null\r\nat NullPointerExample.main(NullPointerExample.java:5)<\/span><\/span><\/pre>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\">These are some of the important features introduced with Java 14 and to build a web application having these features, you can<\/span> <a href=\"https:\/\/www.javaindia.in\/hire-java-developer\"><strong>hire Java developers<\/strong><\/a> <span style=\"color: #000000;\">from a reputed organization having appropriate resources for the development work.<\/span><\/p>\n<p style=\"text-align: justify;\"><strong><span style=\"color: #000000;\">Frequently Asked Questions<\/span><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-390\" src=\"https:\/\/www.javaindia.in\/blog\/wp-content\/uploads\/2020\/02\/Frequently-asked-questions.jpg\" alt=\"frequently asked questions\" width=\"700\" height=\"350\" srcset=\"https:\/\/www.javaindia.in\/blog\/wp-content\/uploads\/2020\/02\/Frequently-asked-questions.jpg 700w, https:\/\/www.javaindia.in\/blog\/wp-content\/uploads\/2020\/02\/Frequently-asked-questions-300x150.jpg 300w, https:\/\/www.javaindia.in\/blog\/wp-content\/uploads\/2020\/02\/Frequently-asked-questions-360x180.jpg 360w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><br \/>\n<\/strong><\/p>\n<ol style=\"text-align: justify;\">\n<li><span style=\"color: #000000;\"><strong> Is Java 14 a LTS?<br \/>\n<\/strong>Java 14 was released in March 2020. It is not an LTS release and will be outdated at the release of Java 15 in September 2020.<\/span><\/li>\n<\/ol>\n<ol style=\"text-align: justify;\" start=\"2\">\n<li><span style=\"color: #000000;\"><strong> What does Java LTS mean?<br \/>\n<\/strong>A Java LTS (long-term support) release is a version of Java that will remain the industry standard for several years. For example, Java 8 was released in 2014, it will continue to receive updates until 2020, and extended support will end by 2025.<\/span><\/li>\n<\/ol>\n<ol style=\"text-align: justify;\" start=\"3\">\n<li><span style=\"color: #000000;\"><span style=\"color: #000000;\"><strong> What is the purpose of JDK?<br \/>\n<\/strong>The Java Development Kit (JDK) is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment, an interpreter\/loader, a compiler (javac), an archiver (jar), a documentation generator and other tools needed in Java development.<\/span><\/span><\/li>\n<\/ol>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\"><strong>Wrapping Up:<br \/>\n<\/strong>In Java 14, there are some remarkable features and updates that help developers in web application development. For example, Java 14 introduces an instance of pattern matching, which helps to reduce explicit casts. Records are available which declare classes that are used solely to aggregate data. Text blocks, a feature that helps to work with multiline string values. One other significant change is the event streaming in the JDK Flight Recorder. All these features make it the perfect choice for<\/span> <a href=\"https:\/\/www.javaindia.in\/services\/java-j2ee-development\"><strong>Java J2ee development<\/strong><\/a> <span style=\"color: #000000;\">and other development activities.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java 14 and its open-source Java Development Kit 14 has been released for developers, the most popular coding language for application development in the world. With version 14 significant numbers of Java Enhancement Proposals (JEPs) have been introduced for usage. JAVA 14 addresses several remarkable features ranging from the Java language support to the latest APIs. So what is in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":436,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[22],"tags":[],"class_list":["post-433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":18,"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions\/504"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/media\/436"}],"wp:attachment":[{"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javaindia.in\/blog\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}