wood burning stoves 2.0*
The moose likes Java in General and the fly likes Conversion of Unicode to Kanji! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Conversion of Unicode to Kanji!" Watch "Conversion of Unicode to Kanji!" New topic

Conversion of Unicode to Kanji!

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
I am developing Client side in my project. I will get all dynamic value from server in Unicode Characterset. After I get that value in Unicode, I need to convert that Unicode to Kanji(Japanese langauage) to display into Browsers.
How Can I convert Unicode to Kanji in Java?
Please help me out,
Sean MacLean
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
With Java 1.3 (the methods are available in 1.2, but I'm not sure that they were implemented) you can create new Strings using a constructor that accepts a character encoding. You'll also have to use the i18n.jar to get the extended encoding set which contains cp930 (I think that's the one you'll need). These links have some other thoughts on the matter.Have a look at and see if they help you get started.

I hope this helps.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Hmmm... I guess it depends on your situation and what you're trying to do. It sounds to me like you shouldn't need to convert to any other character set at all - the Unicode string already represents Kanji "characters". The only problem is, if you want your browser to be able to display the Kanji, you must make sure that the you have the necessary fonts installed. Your best bet is to consult the documentation here. (Note that the links Sean and I give are for JDK 1.1 - if you know that your users will have a plugin for 1.2, you can find other appropriate docs in the release notes at www.javasoft.com/docs . Alternately, you might try bypassing the JDK and installing the proper font support in the OS - if you're using Windows and Internet Explorer, go to windowsupdate.microsoft.com and download the Japanese Language support update.
Another thing to try - if you're building a GUI which is to display these characters, try using the java.util.Locale)" TARGET=_blank rel="nofollow">setLocale() method of Component to set the locale to Locale.JAPAN. This should enable the component to find the right fonts to display Japanese characters.
As for other encodings such as those provided in the i18n.jar file, you should only need those if you're working with other applications which are unable to use Unicode. For example if you need to read/write files which are encoded in ShiftJIS rather than Unicode, you'll need the jar file. Aside from the String constructors Sean mentioned, the standard way to specify an encoding is through an InputStreamReader or OutputStreamWriter constructor.
Good luck!

"I'm not back." - Bill Harding, Twister
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Thanks Sean & Jim,
Let more Specific here: I will get dynamic values in German, Spanish, Japanese, French, English from the server. As far as I don't have problem with German, Spanish,French, English. But Japanese I will get this following Unicode values like:
I need to convert this values to Kanji language to display in the browser.
I am using JDK1.3 version of Java.
Please let me know the easy solution,
Thanks in advance,
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Unicode values have two bytes, requiring 4 hex digits to represent. (European languages may fit into the 0-255 range, but Japanese will take two bytes.) You list a series of 1-byte values - and you list an odd number of them, so the "obvious" solution of combining pair of bytes into two-byte values is... questionable. I don't know what the numbers you list mean, but it's extremely unlikely they are Unicode. Probably you need to figure out what sort of data you really have. If it's stored as a String, you can get the numeric Unicode values of the characters using something like this:
<code><pre> for (int i = 0; i < str.length(); i++) {
System.out.print("Character " + i + ": ");
Now, if you really do have Unicode, then you don't convert to Kanji - the Unicode already represents Kanji. You just want to display the Kanji glyphs in your browser. Then the question is - how are you getting the data to a browser? If you're writing an Applet, then the Applet is a Component, and you should try the setLocale() method I suggested. I don't know if it will work, but it's certainly easy to try. If it doesn't work, then you will need to install Japanese fonts on your system. Go to windowsupdate.microsoft.com and get them. Read the Java documentation here.
[This message has been edited by Jim Yingst (edited April 26, 2001).]
I agree. Here's the link: http://aspose.com/file-tools
subject: Conversion of Unicode to Kanji!
Similar Threads
How to display Chinese in TextArea
Few Doubts about encoding
Unicode character
Convert character to Unicode
Japanese Font & Java