File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes why java compiler compile comments? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why java compiler compile comments?" Watch "why java compiler compile comments?" New topic
Author

why java compiler compile comments?

Sukhadev Patil
Greenhorn

Joined: Apr 12, 2006
Posts: 12
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Sukhadev Patil
Greenhorn

Joined: Apr 12, 2006
Posts: 12
i think newline character and Caridge retrun character makes it to check comment..but how ?
pls. reply on this
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
There is an explanation here: http://jqa.tmorris.net/GetQAndA.action?qids=5&showAnswers=true


Tony Morris
Java Q&A (FAQ, Trivia)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
 
subject: why java compiler compile comments?
 
Similar Threads
comment problem
char declaration
Compile time Difference between // and /* */
unicode character
Character Literals