Here's an easy question: char a = 10; System.out.println(a); //printouts a blank space char b = '\u000a'; //gives a compilation error System.out.println(b); The unicode value \u000a evaluates to decimal 10. Why is this error occurring? However, assigning \u0009, \u0008 or \u0007(space with a ding) does not cause an error!!
Thanks Rahul
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
When in doubt look in the JLS: 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'. ------------------ Moderator of the Programmer Certification Forums
is it not necessary to include ''for char value. for eg. char c='1'; throw some light.
Samith Nambiar
Ranch Hand
Joined: Mar 14, 2001
Posts: 147
posted
0
hi bala 1. char ch = 'A'; System.out.println(ch); // prints A this is the literal representation of A. 2. char ch = 65; System.out.println(ch); // prints A here the ASCII representation of A is used hope this answers the question Samith.P.Nambiar --------------------------------------------- the harder u try the luckier u get
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.