• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

d'bt REgarding Comment !!!!

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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......
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic