Executing comment in java

Executable Comments in Java

A comment is a statement that is not executed by the compiler or the interpreter, but before the lexical transformation of the program in the compiler, the contents of the program are encoded into ASCII to make the processing easier. Consider this program:


class Main{ 

    public static void main(String[] args) { 

        // The comment below is magic.. 

        // \u000d System.out.println("Comment Executed!"); 

    } 
} 

Output

Comment executed

This successfully produces this output because java compiler before lexical transformation parses the Unicode character \u000d as a new line and the program gets transformed into:

class Main{ 
 
    public static void main(String[] args) { 

        // The comment below is magic 

        // 

        System.out.println("Comment Executed!"); 

    } 
} 

Posted on by