• 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

Assigning to char, giving problem

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
Have a look here.when I assign char like

char c = '\u000a';
its giving compilation error.
What I know is, here c is assigned an unicode, ie hexadecimal representation of a. that means 10. It is within the range of char, then why its giving error? It compiles fine for b,c,e&f. I couldn't understand what is heppening.
Can anyone pls explain?
thanx in advance
Latha

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It gives error with char c = '\u000d'; also.
I found a good site for details of Unicode : http://www.unicode.org/unicode/reports/tr18/index.html
It looks like '\u000a' and '\u000d'represents empty string.
But I'm not sure. Plz. go through the site.
Thanks
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ...
The unicode char '\u000A' is a 'newline'; '\u000D' is a return.
The compiler gives the message illegal line end in character literal so it must be interrupting them during the compile.
You can use them in a string as '\n' or '\r'
Hope that helps.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that the Unicode excape sequences are processed in the first step at compile time. So the line:
char c = '\u000a';
actually becomes....
char c = '
';
when the compiler actually tries to infer it. So, as it sees two lines there, it generates an error message!
That's the reason there are other escape qequences like \n for u000a etc. You must use them to represent the trouble makers!!!
HTH,
Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Latha
Go thru' this:
When java compiler processes statements, it first turns ASCII text into unicode, including any unicode escape sequences. this process turns '\u000a' into a linefeed that is interpreted as a line terminator. therefore, the only way you can represent carriage return and linefeed characters is with the '\r' and '\n' escape sequences, respectively.
Hope this helps.
Regards
Sanjeev
 
latha
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx guys,
Latha
 
reply
    Bookmark Topic Watch Topic
  • New Topic