File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

d'bt REgarding Comment !!!!

 
Amitkumar Dhama
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,
Can any body tell me wats goin on in the following code.....
with single line comment in action there is a compile time error, and with multiline comment there is no error
--------------------
class A
{
// char c1 = '\u000d'; compile time error after using the comment..
// char c2 = '\u000a'; compile time error after using the comment..
char c4 = '\u0000';
char c3 = '\uface';
}
--------------------------
and thi couse no compile time error
class A
{
/* char c1 = '\u000d'; no error
char c2 = '\u000a'; */
char c4 = '\u0000';
char c3 = '\uface';
}
---------------------------------
and if in the above code i am writing '\u0d';and '\u0a'; in the first and second line, then any type of comment is not working....
can any body tell me why it is so.....
Thanx in advance......
 
challa
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
'\u000a' is a newline char and the code at compile time changes to

//char c2= '
\u000a';

this causes the error unclosed literal. This does not happen with your second code because compiler does not go through multiline comment as it does with the single line comment.

hope it is clear.
 
Joe Sondow
Ranch Hand
Posts: 195
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amitkumar Dhama:
and if in the above code i am writing '\u0d';and '\u0a'; in the first and second line, then any type of comment is not working.....

Unicode escape sequences have 4 digits after the "\u", not 2 digits, so '\u0d'; is gibberish to the compiler.
 
Amitkumar Dhama
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx 4 repplying, but as compiler does not go through the multiline comment then why it is giving error in writing '\u0d'; inside multiline comment...
 
Joe Sondow
Ranch Hand
Posts: 195
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the same reason that '\u000a' causes a problem in an end-of-line comment. The compiler reads in the entire text file and tries to parse it character by character, including comments. It interprets \u as an escape sequence prefix signifying that the next four characters will be hexadecimal digits such that \uXXXX is the Unicode sequence for a known character. The compiler will then regard that sequence as one character.

If you have \u0d'; anywhere in your .java text file, the compiler will try to interpret the Unicode character signified by the 4-digit hex number 0d'; which causes an error because 0d'; is not a valid 4-digit hex number. This occurs during the parsing of the text file, which includes comments.

After all the Unicode sequences and other characters have been read in, the compiler will fully parse the code, determining what's a comment and what's not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic