GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes d'bt REgarding Comment !!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "d Watch "d New topic
Author

d'bt REgarding Comment !!!!

Amitkumar Dhama
Ranch Hand

Joined: Feb 14, 2005
Posts: 56
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......


SCJP 1.4, SCWCD 1.4, M.Tech(CSE)
challa
Greenhorn

Joined: Mar 28, 2005
Posts: 23
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

Joined: Apr 10, 2005
Posts: 195
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.


SCJA 1.0 (98%), SCJP 1.4 (98%)
Amitkumar Dhama
Ranch Hand

Joined: Feb 14, 2005
Posts: 56
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

Joined: Apr 10, 2005
Posts: 195
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.
 
GeeCON Prague 2014
 
subject: d'bt REgarding Comment !!!!