aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes This is really amazing ...........pls check out this 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 "This is really amazing ...........pls check out this" Watch "This is really amazing ...........pls check out this" New topic
Author

This is really amazing ...........pls check out this

anilkuj
Greenhorn

Joined: Sep 18, 2000
Posts: 22
class a
{
//char a='\u000a';
}

The above code doesn't compile it throws 2 errors, why is that if that's not enough take this
class a
{
/*char a='\u000a';*/
}

this code ecompiles perfectly without any poblems anybody pls
explain this
Thanx
aNiL
anilkuj
Greenhorn

Joined: Sep 18, 2000
Posts: 22
hi! sunitha
Then how does this compile?
class a
{
//char a='\u0009';
}
BTW my question actually was why it is checking the syntax even thoudgh i comment it with // but its not doing so for /* and
*/ type of comment.
Thanx
aNiL


vidhya Ramachandran
Greenhorn

Joined: Sep 15, 2000
Posts: 13

Please read the following from JLS. Hope this answers your question:

Because Unicode escapes are processed very early, it is not correct to write '\u000a' for a character literal whose value is
linefeed (LF); the Unicode escape \u000a is transformed into an actual linefeed in translation step 1 (�3.3) and the linefeed
becomes a LineTerminator in step 2 (�3.4), and so the character literal is not valid in step 3. Instead, one should use the
escape sequence '\n' (�3.10.6). Similarly, it is not correct to write '\u000d' for a character literal whose value is carriage
return (CR). Instead, use '\r'.
Rahul
Greenhorn

Joined: Sep 22, 2000
Posts: 6
I think it is something to do with Escape seq
Try this - this works- i have removed the '\' char
class a
{
//char a='u000a';
}
This compiles fine
But i too dont understand why /* */ works without any problem
Is this a Bug in java
Experts, JGurus Wakeup !!


Njoy
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
vidhya Ramachandran already explained it
The line:
//char a='\u000a';
when read by javac into a String, has the unicode translation
applied resulting in a line feed (a line terminator) so you end up with a split line:
//char a=
;
The other example
/*char a='\u000a';*/
turns into
/*char a=
;*/
which is a perfectly valid two line comment.
Bill

Java Resources at www.wbrogden.com
anilkuj
Greenhorn

Joined: Sep 18, 2000
Posts: 22
Hi William ,
Ok the first part was clear but i am still not able to understand how the compiler is able at accept the same char. literal inside /* and */.
Thanx
aNiL
anilkuj
Greenhorn

Joined: Sep 18, 2000
Posts: 22
Hi william
yes i got it i understood i thought over it after i posted the reply. Thanx a lot.
aNiL
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: This is really amazing ...........pls check out this
 
Similar Threads
help with this
what is wrong with these two codes?
Unicode representation of a character
// commented lines also checked by compiler?
char literal