Java — Executable Comments | Code Factory

Donate : Link

WordPress Blog : Link

Applications… : Link

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


This code will be executed and compiled successfully to produce the output.


Code Factory 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


The Unicode character Shifts the print statement to the next line which is then executed like a normal java program. So, the question arises why the translation of Unicode escapes happens before any other source code processing?

  1. Java source code can be written in any encoding which allows a wide range of characters in string, literal and comments.
  2. It makes processing by ASCII-based tools easier.
  3. This guarantees java Platform dependence which is the independence from supported character sets.
  4. This helps in documenting code in non-Latin languages.

Being able to write any Unicode character anywhere in the file is a neat feature, The fact that it can interfere with the semantics in such subtle ways is just a side-effect.

Let’s consider this java program

Save below code in file


- javac

- java Ugly


Hello world



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store