File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am now totally confused about using char literal.Please help me.

 
pradeep singh
Ranch Hand
Posts: 339
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all
I am now totally confused about using char literal.Please help me.


1. char a='\u0000'; //legal declaration

2. char a='\u001A';// also legal

3. char a='\u0010';//also legal

4. char a='\u000b';//also legal
5. char a='\u000a';//is illegal
6. char a='\u000';//is illegal


please tell me how can i find that it is legal or illegal char initialization.I have read from the book is that char can be assigned value
'\uxxxx'.And xxxx stands for hexadecimal digit.But '\u000a' is not legal .WHY?
 
Prasun Howlader
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler translates unicode characters at the beginning of the compile cycle. You cannot use the character literals \u000a(newline) or \u000d(carriage return) in char literals or string literals as they will be interpreted as line terminator not as input characters. Instead always use special characters '\n' or '\r'
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See JLS - 3.10.4 Character Literals...
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'.
 
pradeep singh
Ranch Hand
Posts: 339
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr.Prasun Howlader and Mr.marc weber .
If you know other limitations other than '\u000a','\u000d',\u005c' ,'\0027' ,which we can not use in assigning a char literal,Please tell me if others are present

[ January 06, 2008: Message edited by: pradeep singh ]
[ January 06, 2008: Message edited by: pradeep singh ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic