Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal character ??

 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends ,

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

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

thanks

srikanth
 
madhu cm
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To clear your doubt....
visit this page <

http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter09/characterEncodng.html
[ September 09, 2005: Message edited by: madhu cm ]
 
Raghu Shree
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
newline="
";


So compiler shows the error message unclosed string literal
 
madhu cm
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic