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.
Geek 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.
1. It makes processing by ASCII-based tools easier.
2. This guarantees java Platform dependence which is the independence from supported character sets.
3. 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:
This unicode program is converted into its representative values to produce “Hello World”
- Comments in Java
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.concurrent.Phaser class in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai