{"id":1951,"date":"2011-04-11T18:33:57","date_gmt":"2011-04-11T13:03:57","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1951"},"modified":"2011-04-11T18:33:57","modified_gmt":"2011-04-11T13:03:57","slug":"project-coin-java-7-new-features","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/project-coin-java-7-new-features\/","title":{"rendered":"Project Coin &#8211; Java 7 new features"},"content":{"rendered":"<p>After reading the title &#8220;<a title=\"Project Coin\" href=\"http:\/\/openjdk.java.net\/projects\/coin\/\" target=\"_blank\"><strong>project Coin<\/strong><\/a>&#8220;, few of you must be thinking that what is it ? And how it is related to Java 7 new features.<\/p>\n<p>So, here we go&#8230;<\/p>\n<blockquote><p><strong><a title=\"Project Coin\" href=\"http:\/\/openjdk.java.net\/projects\/coin\/\" target=\"_blank\">Project Coin<\/a> is the part of Java 7 development which is running since January 2009 with the aim of coming with small changes to the Java language.<\/strong><\/p><\/blockquote>\n<p>In February to march 2009, there were nearly 70 proposals were submitted for huge range of possible changes in Java 7. <strong><a title=\"Project Coin\" href=\"http:\/\/openjdk.java.net\/projects\/coin\/\" target=\"_blank\">Project coin<\/a> has set up the example that how language can be developed in the future by discussion in openly manner with the public all around the world.<!--more--><\/strong><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Java 7 new Features :<\/strong><\/span><\/p>\n<p><strong>Support of Strings in &#8220;Switch&#8221; statement:<\/strong><br \/>\nBefore Java 7, we can only use constants of type byte, char, short or enum. However, now we can use the string also in switch case statement.<\/p>\n<pre class=\"brush: java; highlight: [3,5]; title: ; notranslate\" title=\"\">\nswitch(dayOfWeek)\n{\n   case &quot;Monday&quot; : System.out.println(&quot;Its first day of the office&quot;);break;\n   ....\n   case &quot;Sunday&quot; : System.out.println(&quot;Hurrey.. its weekend&quot;);break;\n}\n<\/pre>\n<p><strong>Enhanced Syntax of Numeric literals<\/strong><\/p>\n<ul>\n<li> Numeric constants expressed as binary.<\/li>\n<li> Use of underscores in integer constants for readability.<\/li>\n<li> A specific suffix to denote that an integer constant has type short or byte.<\/li>\n<\/ul>\n<p><strong>Improved Exception handling<\/strong><br \/>\nBefore Java 7, we used to write multiple catch blocks in our program which looks like very verbose.<br \/>\nwith the help of pipe operator in Java 7, we can write multiple catch blocks in one line as shown below :<\/p>\n<pre class=\"brush: java; highlight: [6]; title: ; notranslate\" title=\"\">\npublic void printFileContent(String fileName_) {\nConfiguration cfg = null;\ntry {\nString fileText = getFile(fileName_);\n\/\/...code to print content\n} catch (FileNotFoundException|ParseException|FileLockInterruptionException e) {\nSystem.err.println(&quot;error while opening file&quot;);\n} catch (IOException iox) {\nSystem.err.println(&quot;Error while processing file&quot;);\n}\n\n}\n<\/pre>\n<p>Try with resources<br \/>\nC# developers will find the syntax friendly , as it is same as using clause.<\/p>\n<pre class=\"brush: java; highlight: [1,2]; title: ; notranslate\" title=\"\">\ntry ( FileOutputStream fos = new FileOutputStream(file);\nInputStream is = url.openStream() ) {\nbyte&#x5B;] buf = new byte&#x5B;4096];\nint len;\nwhile ((len = is.read(buf)) &gt; 0) {\nfos.write(buf, 0, len);\n}\n}\n<\/pre>\n<p><strong>Diamond Syntax :<\/strong><br \/>\nBefore Java 7, generic Syntax was like :<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nMap&lt;Movie,Songs&gt; m = new HashMap&lt;Movie,Songs&gt;();\n<\/pre>\n<p>As you can see, we are repeating the syntax at right hand side, why compiler should not be able to take care of that?<br \/>\nBelow is the new user friendly syntax.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nMap&lt;Movie,Songs&gt; m = new HashMap&lt;&gt;();\n<\/pre>\n<p>There is also change in Varargs Syntax which we will discuss in detail later on.<br \/>\nPlease leave your valuable suggestions to improve the article and content.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Project Coin and how it is related to JAVA<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[329],"class_list":["post-1951","post","type-post","status-publish","format-standard","hentry","category-java","tag-java"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1586,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/read-file-present-inside-java-and-j2ee-project\/","url_meta":{"origin":1951,"position":0},"title":"Read File Present inside Java and J2EE Project","author":"Jitendra","date":"February 24, 2011","format":false,"excerpt":"How to Read File Present inside Java and J2EE Project","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"Read File Present inside Java and J2EE Project","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Read-File-Present-inside-Java-and-J2EE-Project.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1742,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/introduction-to-jaxp\/","url_meta":{"origin":1951,"position":1},"title":"Introduction to JAXP and Difference between JAXP and JAXB","author":"Jitendra","date":"March 22, 2011","format":false,"excerpt":"Introduction to JAXP (JAVA API for XML Processing), SAX (Simple API for XML Parsing),Extensible Style sheet language transformation (XSLT)","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"XML Processing using DOM in JAXP","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/XML-Processing-using-DOM-in-JAXP.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2112,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/resolve-missing-builder-error-for-eclipse-in-ccb-ormb\/","url_meta":{"origin":1951,"position":2},"title":"Resolve Missing Builder error for eclipse in CC&#038;B (ORMB)","author":"Jitendra","date":"May 11, 2011","format":false,"excerpt":"How to Resolve Missing Builder error for eclipse in CC&B (ORMB)","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Missing Builder error in CC&B (ORMB)","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/05\/Missinh-Builder-error-in-CCB-ORMB.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3213,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/resolve-error-artifacttransferexception-could-not-transfer-artifact-or-failure-to-transfer-in-maven\/","url_meta":{"origin":1951,"position":3},"title":"Resolve Error &#8220;ArtifactTransferException: Could not transfer artifact&#8221; or &#8220;Failure to Transfer&#8221; in Maven","author":"Jitendra","date":"February 27, 2013","format":false,"excerpt":"This is very short tips to resolve the errors \"ArtifactTransferException: Could not transfer artifact\" that may occur in Maven project in Eclipse. Steps to resolve: Open folder by running this text (without Quotes) in Search Explorer of Window \"%USERPROFILE%.m2\". After running above command, \"m2\" folder of maven will open. Now\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5434,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/creating-custom-ant-plugin-or-task-in-java\/","url_meta":{"origin":1951,"position":4},"title":"Creating custom ANT plugin or Task in Java","author":"Jitendra","date":"March 19, 2016","format":false,"excerpt":"Tutorial to create custom Task in ANT with complete source code","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Create custom ANT Task in Java","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/03\/Creating-ANT-plugin.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/03\/Creating-ANT-plugin.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/03\/Creating-ANT-plugin.gif?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/03\/Creating-ANT-plugin.gif?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/03\/Creating-ANT-plugin.gif?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":979,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/invoke-method-using-reflection-in-java\/","url_meta":{"origin":1951,"position":5},"title":"Invoke method using reflection in JAVA","author":"Jitendra","date":"September 6, 2010","format":false,"excerpt":"Invoke method using reflection in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1951"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1951\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}