File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes I am now  totally confused about using char literal.Please help me. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "I am now  totally confused about using char literal.Please help me." Watch "I am now  totally confused about using char literal.Please help me." New topic
Author

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

pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
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?


SCJP 5.0(75%), SCWCD 5.0(88%)
Prasun Howlader
Ranch Hand

Joined: Oct 21, 2007
Posts: 89
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'


"Control time instead of letting time control you."
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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'.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I am now totally confused about using char literal.Please help me.
 
Similar Threads
unicode questions
chars
include directive question in java black belt
Compile time Difference between // and /* */
regarding forward referencing and 'implicit narrowing conversion'