{"id":4800,"date":"2023-11-30T16:18:42","date_gmt":"2023-11-30T16:18:42","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=4800"},"modified":"2023-11-30T16:20:32","modified_gmt":"2023-11-30T16:20:32","slug":"java-11-new-features","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/java-11-new-features\/","title":{"rendered":"Java 11 New Features"},"content":{"rendered":"<ol>\n<li>New methods to the String class: isBlank, lines, strip, stripLeading, stripTrailing, and repeat.<\/li>\n<li> readString and writeString static methods from the Files class\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nPath filePath = Files.writeString(Files.createTempFile(tempDir, &quot;demo&quot;, &quot;.txt&quot;), &quot;Sample text&quot;);\r\nString fileContent = Files.readString(filePath);\r\nassertThat(fileContent).isEqualTo(&quot;Sample text&quot;);\r\n<\/pre>\n<\/li>\n<li>java.util.Collection interface contains a new default toArray method\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nList sampleList = Arrays.asList(&quot;Java&quot;, &quot;Kotlin&quot;);\r\nString&#x5B;] sampleArray = sampleList.toArray(String&#x5B;]::new);\r\nassertThat(sampleArray).containsExactly(&quot;Java&quot;, &quot;Kotlin&quot;);\r\n<\/pre>\n<\/li>\n<li>A static not method has been added to the Predicate interface. Predicate.not(String::isBlank)<\/li>\n<li>The new HTTP client from the java.net.http package was introduced in Java 9. It has now become a standard feature in Java 11.The new HTTP API improves overall performance and provides support for both HTTP\/1.1 and HTTP\/2:\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nHttpClient httpClient = HttpClient.newBuilder()\r\n    .version(HttpClient.Version.HTTP_2)\r\n    .connectTimeout(Duration.ofSeconds(20))\r\n    .build();\r\nHttpRequest httpRequest = HttpRequest.newBuilder()\r\n    .GET()\r\n    .uri(URI.create(&quot;http:\/\/localhost:&quot; + port))\r\n    .build();\r\nHttpResponse httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());\r\nassertThat(httpResponse.body()).isEqualTo(&quot;Hello from the server!&quot;);\r\n<\/pre>\n<\/li>\n<li>A major change in this version is that we don\u2019t need to compile the Java source files with javac explicitly anymore:<br \/>\n<strong>Before Java 11Version<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n$ javac HelloWorld.java\r\n$ java HelloWorld \r\nHello Java 8!\r\n<\/pre>\n<p><strong>New Version<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n$ java HelloWorld.java\r\nHello Java 11!\r\n<\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>New methods to the String class: isBlank, lines, strip, stripLeading, stripTrailing, and repeat. readString and writeString static methods from the Files class Path filePath = Files.writeString(Files.createTempFile(tempDir, &quot;demo&quot;, &quot;.txt&quot;), &quot;Sample text&quot;); String fileContent = Files.readString(filePath); assertThat(fileContent).isEqualTo(&quot;Sample text&quot;); java.util.Collection interface contains a new default toArray method List sampleList = Arrays.asList(&quot;Java&quot;, &quot;Kotlin&quot;); String&#x5B;] sampleArray = sampleList.toArray(String&#x5B;]::new); assertThat(sampleArray).containsExactly(&quot;Java&quot;, &quot;Kotlin&quot;);&hellip; <a href=\"https:\/\/codethataint.com\/blog\/java-11-new-features\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[347],"tags":[],"class_list":["post-4800","post","type-post","status-publish","format-standard","hentry","category-interview-java-11"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=4800"}],"version-history":[{"count":2,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4800\/revisions"}],"predecessor-version":[{"id":4802,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4800\/revisions\/4802"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=4800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=4800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=4800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}