{"id":28,"date":"2008-12-31T14:48:00","date_gmt":"2008-12-31T12:48:00","guid":{"rendered":"https:\/\/blog.lifshitz.net\/java-language-change"},"modified":"2014-11-17T16:09:05","modified_gmt":"2014-11-17T14:09:05","slug":"java-language-change","status":"publish","type":"post","link":"https:\/\/blog.lifshitz.net\/?p=28","title":{"rendered":"Java Language Change"},"content":{"rendered":"<p>I&#8217;ve been to <a href=\"http:\/\/www.javaedge.net\/\">JavaEdge 2008<\/a> last week, and while many of the sessions were interesting, I found the one about the Java Language Change particularly intriguing.<\/p>\n<p>During the session 10 proposed changes were introduced, all of them minor by definition (as stated by Sun in the JavaOne 2008 TS-5881 presentation), and everyone got to (anonymously) vote.<\/p>\n<p>Here is the list of proposed changes, and even if you don&#8217;t get to vote, I think it&#8217;s interesting and thought provoking:<\/p>\n<p><strong>1. Map-for-each:<\/strong><\/p>\n<pre><code><br \/>for <a style=\"color:red\">(String key, Integer value : map)<\/a> {<br \/>...<br \/>}<br \/><\/code><\/pre>\n<p><strong>2. For-each iteration control:<\/strong><\/p>\n<pre><code>for (String str : list <a style=\"color:red\">: it<\/a>) {<br \/>\tif (str.length() > 100) {<br \/>\t   \t<a style=\"color:red\">it.remove();<br \/>\t}<br \/>\tit.set(...);<br \/>\tit.index();<br \/>\tit.isFirst();<br \/>\tit.isLast();<br \/>\t<\/a><br \/>}<br \/><\/code><\/pre>\n<p><strong>3. List\/map access:<\/strong><\/p>\n<pre><code><br \/>List&lt;String&gt; list = ...<br \/>Map&lt;String, Job&gt; map = ...<br \/>Map&lt;String, Map&lt;String, Task&gt;&gt; combined = ...<br \/><br \/>String str = list<a style=\"color:red\">[0]<\/a>;<br \/>list<a style=\"color:red\">[0]<\/a> = \"Hi\";<br \/>Integer value = map<a style=\"color:red\">[str]<\/a>;<br \/>map<a style=\"color:red\">[\"Hi\"]<\/a> = 56;<br \/>Task task = combined<a style=\"color:red\">[\"Test\"][\"Monitor\"]<\/a>;<br \/><\/code><\/pre>\n<p><strong>4. Infer generics in declarations:<\/strong><\/p>\n<pre>Instead of<br \/><code>List&lt;String&gt; list = new ArrayList&ltString&gt;();<br \/><\/code>use<code><br \/>List&lt;String&gt; list = new ArrayList<a style=\"color:red\">&lt;&gt;<\/a>();<br \/><\/code><\/pre>\n<p><strong>5. Multi-catch of Exceptions:<\/strong><\/p>\n<pre><code><br \/>try {<br \/>\tdoSomething();<br \/>\tdoSomethingElse();<br \/>}<br \/>catch (IOException<a style=\"color:red\">, SQLException ex<\/a>) {<br \/>\/\/ handle..<br \/>}<br \/><\/code><\/pre>\n<p><strong>6. String switch:<\/strong><\/p>\n<pre><br \/><code><br \/>String str = ..<br \/><a style=\"color:red\">switch (str)<\/a> {<br \/>\t<a style=\"color:red\">case \"name\"<\/a>:<br \/>\t\tprocessName();<br \/>\t\tbreak;<br \/>\t<a style=\"color:red\">case \"surname\"<\/a>:<br \/>\t\tprocessSurname;<br \/>...<br \/>}<\/code><\/pre>\n<p><strong>7. String interpolation:<\/strong><\/p>\n<pre><code><br \/>String name = ...<br \/>String Value = ..<br \/>String out = <a style=\"color:red\">$<\/a>\"The value of <a style=\"color:red\">${name}<\/a> is <a style=\"color:red\">${value}<\/a>\";<\/code><\/pre>\n<p><strong>8. Multi-line Strings<\/strong><\/p>\n<pre><code><br \/>String sql = <br \/><a style=\"color:red\">\"\"\"<\/a>SELECT firstname, lastname, birth_date,<br \/>\ttelephone, account<br \/>\tFROM <br \/>\tpreson, phone, email<br \/>\tWHERE <br \/>\t..<br \/>\t\"\"\";<\/code><\/pre>\n<p><strong>9. Resource management:<\/strong><\/p>\n<pre><br \/><code><br \/>try <a style=\"color:red\">(FileReader in = new FileReader(file))<\/a> {<br \/>\tprocessFile(in);<br \/>} \/\/ and resource validation and release is done automatically<br \/><\/code><\/pre>\n<p><strong>10. Null-handling:<\/strong><\/p>\n<pre><br \/><code><br \/>Session sess = ..<br \/><br \/>String code = sess<a style=\"color:red\">?<\/a>.preson()<a style=\"color:red\">?<\/a>.address()<a style=\"color:red\">?<\/a>.postcode(); \/\/ if anything preceding ? is null, the result is null<br \/><\/code><br \/><\/pre>\n<p>What&#8217;s your vote? \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been to JavaEdge 2008 last week, and while many of the sessions were interesting, I found the one about the Java Language Change particularly intriguing. During the session 10 proposed changes were introduced, all of them minor by definition (as stated by Sun in the JavaOne 2008 TS-5881 presentation), and everyone got to (anonymously)&hellip;&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[9,20,21],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/posts\/28"}],"collection":[{"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=28"}],"version-history":[{"count":0,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}