Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char value

 
pradeepta chopra
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A{
public static void main(String[] args)
{
char c='\u123';
System.out.println(c);
}
}

output:
?

why does it gives the above output??
and how can i print the unicode value for a given character???
thanks
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may this links helps you to understand the concepts OR googled it !
[ August 13, 2008: Message edited by: Sagar Rohankar ]
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think perhaps it gives a ? because u123 is an invalid Unicode character. At least, I'm getting that error in Eclipse. Have a look here for a good Unicode table.

http://www.tamasoft.co.jp/en/general-info/unicode.html


(The page may take some time to load so be patient)

[edit]Corrected UBB tags. CR[/edit]
[ August 13, 2008: Message edited by: Campbell Ritchie ]
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<a href=http://www.tamasoft.co.jp/en/general-info/unicode.html
]http://www.tamasoft.co.jp/en/general-info/unicode.html>http://www.tamasoft.co.jp/en/general-info/unicode.html
]http://www.tamasoft.co.jp/en/general-info/unicode.html</a>
 
Campbell Ritchie
Sheriff
Pie
Posts: 48932
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look it up in Unicode (look for file U0100.pdf), you find it says this:
ģ
0123 LATIN SMALL LETTER G WITH CEDILLA
� Latvian
� there are three major glyph variants
≡ 0067 g 0327 $̧
And when I tried it on a Bash shell (Linux) I got this output:
javac Print123.java
campbell@linux-pgix:~/java> java Print123
ģ
campbell@linux-pgix:~/java>
So the problem might be that your terminal window won't support all the Unicode characters; I find Windows or DOS often fails to print non-ASCII characters.
 
pradeepta chopra
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the above refrences and can you please tell me if there is a method through which i may be able to print the unicode values of characters??
 
Campbell Ritchie
Sheriff
Pie
Posts: 48932
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, it's not '\u123' but '\0123'. '\u123' doesn't seem to compile. I knew to try \u0123 first, but in future, please Post Real Code with ctrl-c ctrl-v.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48932
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works nicely on Eclipse when you have 4 (hexadecimal) numbers after the \u. That's the problem.
 
Norm Radder
Ranch Hand
Posts: 883
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the Integer class. It has methods to convert int to hex.
Then prepend the \u with some 00s to it.
 
pradeepta chopra
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i even tried '\u0123' but it still prints ?
maybe windows do not support the char
even if i say '\u0000' it doesnt print a 0, it simply doesnt prints anything.
so what do we do if theres such a question in the exam that asks for the output
it seems to be implementation dependent
 
Campbell Ritchie
Sheriff
Pie
Posts: 48932
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already told you Windows/DOS tends not to support non-ASCII characters; I have sometimes had problems with characters in the range 0x80 to 0xff.

And '\u0000' isn't "0"; it is the null character, so you wouldn't expect anything to appear.
 
pradeepta chopra
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thankyou
 
Campbell Ritchie
Sheriff
Pie
Posts: 48932
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic