- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Executable Comments in Java
As we all know, that java compiler ignores the comments written in the java code file. But using a trick we can execute the code present in a comment section. Consider the following program −
Example
public class Tester { public static void main(String[] args) { // The comment below is magic.. // \u000d System.out.println("Hello World"); } }
This will produce the following result −
Output
Hello World
The reason behind this behaviour is the use of \u000d character in comment which is a new line character. As Java compiler parses the new line character, the put the println command to next line resulting in the following program.
public class Tester { public static void main(String[] args) { // The comment below is magic.. // System.out.println("Hello World"); } }
Reasoning behind this unicode parsing before source code processing is as follows −
To keep java source code to be written using any unicode character.
To make java code processing easier by ASCII based editors.
Helps in writing documentation in unicode supporting languages.
- Related Articles
- Java comments.
- /** and /* in Java comments
- Comments in Java\n
- Java documentation comments
- Types of Java comments.
- Java single line comments.
- Java multi-line comments
- What are comments in Java language?
- Best practices for Java comments.
- Pattern COMMENTS field in Java with examples
- How to check if a file is readable, writable, or, executable in Java?
- What is the difference between /* */ and /** */ comments in Java?
- How to add different comments in the Java code?
- What are executable statements in C language?
- Comments in Python

Advertisements