{"id":5182,"date":"2019-04-02T07:11:49","date_gmt":"2019-04-02T07:11:49","guid":{"rendered":"https:\/\/gtechbooster.com\/?p=5182"},"modified":"2023-06-21T11:43:00","modified_gmt":"2023-06-21T11:43:00","slug":"switch-expressions-comes-with-java-12","status":"publish","type":"post","link":"https:\/\/gtechbooster.com\/switch-expressions-comes-with-java-12\/","title":{"rendered":"Switch Expressions comes with Java 12"},"content":{"rendered":"\n<p>Java 12, the latest six-monthly release of Java, has been released  with support for Switch Expressions and the inclusion of the Shenandoah  low-pause garbage collector.\u00a0 <\/p>\n\n\n<div class=\"gtech-migrated-from-ad-inserter-placement-2\" style=\"text-align: center;\" id=\"gtech-1007225398\"><div style=\"margin-right: auto;margin-left: auto;text-align: center;\" id=\"gtech-1363650287\"><a data-bid=\"1\" data-no-instant=\"1\" href=\"https:\/\/gtechbooster.com\/linkout\/17207\" rel=\"noopener\" class=\"notrack\" aria-label=\"26001\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gtechbooster.com\/media\/2023\/01\/26001.jpeg\" alt=\"\"  srcset=\"https:\/\/gtechbooster.com\/media\/2023\/01\/26001.jpeg 1024w, https:\/\/gtechbooster.com\/media\/2023\/01\/26001-768x960.jpeg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" width=\"500\" height=\"625\"  style=\"display: inline-block;\" \/><\/a><\/div><\/div><p>There are eight main improvements to the new release, starting with  switch expressions. This is still a preview feature, and it extends the  switch statement so that it can be used as either a statement or an  expression. Whichever form is used, you can use either a traditional or a  simplified scoping and control flow behavior. <\/p>\n\n\n<p>\nOracle says that in addition to simplifying everyday coding, the\naddition prepares the way for the use of pattern matching in the switch\nstatement. Pattern matching is available as another preview language\nfeature.\n&nbsp;\nCurrently, the default flow of control of switch blocks is fall\nthrough, so requiring a break statement to avoid the rest of the Case\nstatements in a block being tested and potentially executed. The new\nswitch expressions introduce a new form of switch label, written &#8220;<code>case L -&gt;<\/code>&#8221; to signify that only the code to the right of the label is to be executed if the label is matched. For example:\n<\/p>\n\n\n<pre class=\"wp-block-code\"><code>switch (day) {\n    case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);\n    case TUESDAY                -> System.out.println(7);\n    case THURSDAY, SATURDAY     -> System.out.println(8);\n    case WEDNESDAY              -> System.out.println(9);\n}<\/code><\/pre>\n\n\n<p>The next improvements to the new release are to the current garbage\ncollector. From now on, the garbage collector will&nbsp; automatically return\n Java heap memory to the operating system when idle rather than waiting\nuntil a full garbage collection to return memory to the operating\nsystem, and it will also respect pause times better.<\/p>\n\n\n<p>Until now, the garbage collector sometimes started an amount of work\nthat would take longer than the pause target, meaning the task overran.\nUnder the improved version, if this is happening, the garbage collector\nlowers its targets.&nbsp;\nStill on garbage collection, Shenandoah has been added in an\nexperimental version. Shenandoah is Java&#8217;s new low-pause-time garbage\ncollector algorithm. It reduces GC pause times by doing evacuation work\nconcurrently with the running Java threads. Pause times with Shenandoah\nare independent of heap size, meaning you will have the same consistent\npause times whether your heap is 200 MB or 200 GB.<br \/><\/p>\n\n\n<p>Another improvement is the addition of a basic suite of\nmicrobenchmarks to the JDK source code, as well as making it easy for\ndevelopers to run existing microbenchmarks and create new ones. There&#8217;s\nalso a new JVM Constants API that can be used to model nominal\ndescriptions of key class-file and run-time artifacts.<\/p>\n\n\n<p>The OpenJDK open source release is available now, along with the  commercial license version. JDK 12 will receive a minimum of two updates  before being followed by Oracle JDK 13, which is due out in September  2019.<\/p>\n\n\n<h4 class=\"wp-block-heading\">More Information<\/h4>\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/jdk.java.net\/12\/\" target=\"_blank\">Oracle OpenJDK open source release<\/a><\/li><li> <span class=\"removed_link\" title=\"https:\/\/blogs.oracle.com\/java-platform-group\/oracle-jdk-releases-for-java-11-and-later\">Java 12 commercial license<\/span><\/li><\/ul>\n<div class=\"gtech-end-cont\" id=\"gtech-1386075607\"><div style=\"margin-right: auto;margin-left: auto;text-align: center;\" id=\"gtech-755893975\"><a data-bid=\"1\" data-no-instant=\"1\" href=\"https:\/\/gtechbooster.com\/linkout\/17207\" rel=\"noopener\" class=\"notrack\" aria-label=\"26001\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gtechbooster.com\/media\/2023\/01\/26001.jpeg\" alt=\"\"  srcset=\"https:\/\/gtechbooster.com\/media\/2023\/01\/26001.jpeg 1024w, https:\/\/gtechbooster.com\/media\/2023\/01\/26001-768x960.jpeg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" width=\"500\" height=\"625\"  style=\"display: inline-block;\" \/><\/a><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Java 12, the latest six-monthly release of Java, has been released with support for Switch Expressions and the inclusion of the Shenandoah low-pause garbage collector.\u00a0 There are eight main improvements to the new release, starting with switch expressions. This is still a preview feature, and it extends the switch statement so that it can be [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":5183,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1915],"tags":[480,619,6],"class_list":["post-5182","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ndocs","tag-java","tag-open-jdk","tag-programming"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/posts\/5182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/comments?post=5182"}],"version-history":[{"count":0,"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/posts\/5182\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/media\/5183"}],"wp:attachment":[{"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/media?parent=5182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/categories?post=5182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gtechbooster.com\/api-json\/wp\/v2\/tags?post=5182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}