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”
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Comments in Java
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.Lang.Float class in Java
- Java.io.BufferedInputStream class in Java
- Java.io.ObjectInputStream Class in Java | Set 1
- Java.util.BitSet class in Java with Examples | Set 1
- Java.io.File Class in Java
- Java.io.BufferedWriter class methods in Java
- Java.io.DataOutputStream in Java
- Java.io.StreamTokenizer Class in Java | Set 1
- Java.io.InputStream Class in Java
- Java.io.SequenceInputStream in Java
- Java.io.StreamTokenizer Class in Java | Set 2
- Java.io.Console class in Java
- Java.io.FilterOutputStream Class in Java
- Java.io.StringWriter class in Java
- Java.io.CharArrayReader Class in Java
- Java.io.FileInputStream Class in Java
- Java.io.CharArrayWriter class in Java | Set 1
- Java.io.CharArrayWriter class in Java | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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