File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why java compiler compile comments?

 
Sukhadev Patil
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
niti_pat@yahoo.com

public class cv
{
public static void main(String args[])
{
// char lf = '\u000a' ;
// char lf = '\u000d' ;


}
}

where

\u000a is unicode value of Newline.
\u000d is unicode value of Carrige Return.


after compile jvm prints following error.
why java compiler compile comment?

C:\cv.java:5: unclosed character literal
// char lf = '\u000a' ;
^
C:\cv.java:6: unclosed character literal
// char cr = '\u000d' ;
^
2 errors

Press any key to continue...
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All unicode characters are actually translated before compilation, in the whole file, comments included.

Your carriage returned is also translated, so your comment becomes :

Before translation:
// char lf = '\u000a';
After translation
// char lf = '
';

This is why compilation fails.
 
Sukhadev Patil
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think newline character and Caridge retrun character makes it to check comment..but how ?
pls. reply on this
 
Tony Morris
Ranch Hand
Posts: 1608
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same here:
http://www.coderanch.com/t/403130/java/java/why-java-compiler-compile-comments

Oops
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic