The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Illegal character ?? 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 "Illegal character ??" Watch "Illegal character ??" New topic

Illegal character ??

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
hi friends ,

i have some doubt in this declaration i.e..

char a = '\u000A' why is giving output as Illegal character ???



Thanks & Regards<br /> <br />-Srikanth
madhu cm

Joined: Jun 26, 2005
Posts: 22
To clear your doubt....
visit this page <
[ September 09, 2005: Message edited by: madhu cm ]
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
when we compile the java file the source is converted from default encoding to unicode. At that time unicode chars like \Uxxx are replaced with the
corresponding character. After that the source file is compiled. Here \u000a is a new line character like '\n'.

so String newline="\u000A" would be replaced like below

So compiler shows the error message unclosed string literal

Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" target="_blank" rel="nofollow">SCWCD Group</a>
madhu cm

Joined: Jun 26, 2005
Posts: 22
Unicode escape characters, of the form '\Uxxxx', where xxxx is a hexadecimal value, are processed very early in the translation process (See JLS ?3.10.4). As a result, the special characters '0A', line feed and '0D', carriage return are interpreted literally as 'end of line'.
The expression:

char A = '\u000A';

therefore becomes

char A =;

which results in a compile-time error.
To avoid this error, always use the special escape characters '\n' (line feed) and '\r' (carriage return);
I agree. Here's the link:
subject: Illegal character ??
It's not a secret anymore!