{"id":35089,"date":"2016-05-31T13:17:01","date_gmt":"2016-05-31T07:47:01","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=35089"},"modified":"2016-05-31T13:17:01","modified_gmt":"2016-05-31T07:47:01","slug":"how-to-execute-java-code-within-java-comments","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-execute-java-code-within-java-comments\/","title":{"rendered":"How to execute Java code within Java comments"},"content":{"rendered":"<p>We all know Java comments are not visible to compiler and are not executable. But here we will see how a comment can be executed. To execute any comment we need to append a unicode as prefix to that comment and thats it. Now when you will run the code then this comment line will be executed.<\/p>\n<p>[java]<br \/>\npublic class CommentTest {<br \/>\n\tpublic static void main(String[] args)<br \/>\n\t{<br \/>\n\t\t\/\/ Following line will be executed and will produce output.<br \/>\n\t\t\/\/ \\u000d System.out.println(&quot;This is the output generated from commented line&quot;);<br \/>\n\t}<br \/>\n}<br \/>\n[\/java]<\/p>\n<pre><strong>Output:\r\n<\/strong>This is the output generated from commented line\r\n<\/pre>\n<p>Why this is happening? Following is the explanation taken from <a href=\"https:\/\/docs.oracle.com\/javase\/specs\/jls\/se8\/html\/jls-3.html#jls-3.3\">\u00a0Java Language Specification &#8211; Section 3.3<\/a><\/p>\n<p>The Java programming language specifies a standard way of transforming a program written in Unicode into ASCII that changes a program into a form that can be processed by ASCII-based tools. The transformation involves converting any Unicode escapes in the source text of the program to ASCII by adding an extra <code class=\"literal\">u<\/code> &#8211; for example, <code class=\"literal\">\\u<span class=\"emphasis\"><em>xxxx<\/em><\/span><\/code>becomes <code class=\"literal\">\\uu<span class=\"emphasis\"><em>xxxx<\/em><\/span><\/code> &#8211; while simultaneously converting non-ASCII characters in the source text to Unicode escapes containing a single <code class=\"literal\">u<\/code> each.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We all know Java comments are not visible to compiler and are not executable. But here we will see how a comment can be executed. To execute any comment we need to append a unicode as prefix to that comment and thats it. Now when you will run the code then this comment line will [&hellip;]<\/p>\n","protected":false},"author":922,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":63},"categories":[446,1994,1],"tags":[4844,3405,3406],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/35089"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/922"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=35089"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/35089\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=35089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=35089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=35089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}