Sadesh Kumar N
Sadesh Kumar N

Reputation: 2052

display the unicode value in the java screen

how to display non english words with unicode in java?

"\u0905\u092E\u0940\u0924\u093E\u092A" i have to display this ib Hindi?

Upvotes: 0

Views: 9406

Answers (1)

BalusC
BalusC

Reputation: 1108782

Just have it in a String and display it. You only need to use the proper encoding in the display component/console. UTF-8 should suffice.

System.out.println("\u0905\u092E\u0940\u0924\u093E\u092A");

See that code run at Ideone.com:

अमीताप

That code prints अमीताप in my Eclipse environment which is configured to use UTF-8 in its console.

Edit: this ain't going to work in for example the Windows command console, because it by default doesn't use UTF-8 nor has a font which covers those codepoints. If you're actually using Eclipse, then you can set the Workspace encoding in its preferences by General > Workspace > Text file encoding.

Further on, anywhere where an Java API can take the character encoding as extra argument, then you need to make use of it and set it to UTF-8. Otherwise the platform default encoding will be used, which may be ISO-8859-1 or cp1252, which is incorrect for those characters. If you for example want to write this String to some OutputStream, then you need to construct an OutputStreamWriter where in you pass UTF-8 as 2nd constructor argument. You may find this article useful as well.

Upvotes: 11

Related Questions