Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Illegal character ??  RSS feed

 
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
 
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 ]
 
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
Boost this thread!