0

I have a referred this Stack Overflow Post regarding the \u000d to be treated as a new line character during run time due to which a code like this:

public static void main(String[] args)
{         
     // \u000d System.out.println("comment executed");
}

will output "comment executed" but then I never quite really understood why is that when I replace the \u000d with a more conventional form \n ,the comment does not work like the previous way.

Community
  • 1
  • 1
Tilak Madichetti
  • 4,110
  • 5
  • 34
  • 52
  • `"\n"` is nothing else than just `"\n"`. You need "someone" to interpret it as an actual new line character. The compiler does that for unicode stuff. But I guess a little bit of research had told you that as well. – Tom Dec 30 '16 at 13:40
  • Possible duplicate of [Why is executing Java code in comments with certain Unicode characters allowed?](http://stackoverflow.com/questions/30727515/why-is-executing-java-code-in-comments-with-certain-unicode-characters-allowed) – VGR Dec 30 '16 at 16:16

2 Answers2

2

Java process unicode sequences prior to compilation. The \u000d is included in that processing. \n is not a unicode sequence and is not processed.

See the explanation in this post: Why is executing Java code in comments with certain Unicode characters allowed?

Community
  • 1
  • 1
Bob Lukens
  • 700
  • 6
  • 10
1

The java compiler doesn't look for escape sequences in comments, only unicode.

I found a bit of small print in the comments section in the java language specification.

In section 3.10.6 - Escape Sequences for Character and String Literals:

Octal escapes are provided for compatibility with C, but can express only Unicode values \u0000 through \u00FF, so Unicode escapes are usually preferred.

This can be found at the very bottom of section 3.10.6

Luke Melaia
  • 1,470
  • 14
  • 22