Re: Using unicode in a Java program

From: addison@inter-locale.com
Date: Thu Jul 20 2000 - 06:37:25 EDT


There are several ways to get Unicode characters into your Java programs.

You are correct in that you can use \uxxxx to represent any Unicode
character. You put the escape sequence anywhere that you would put a
single character like "a" (so it goes inside the quotation marks).

If you can type the character itself, the NativeToAscii utility supplied
with the JDK will convert the characters to the escape sequence for you.

Note that in order to see the characters you will to have the proper fonts
(and, in the case of Windows, code pages) installed. Otherwise you'll see
"?" or an empty black square for your character. If you stick strictly to
Western European characters (as a proof of concept) you shouldn't have any
trouble, though.

You may wish to view the pages on Internationalization at the Javasoft
website. Try searching for "Internationalization" (you can also search for
"John O'Connor"-- he wrote several very clear introductory articles on the
topic and it reduces the noise in the search considerably.)

In the meantime, try using this line:

textstring="\u0109\u00e0\u00f1\u0020\u00fd\u00f5\u00fb\u0020\u0073\u00e8\u00e9\u0020\u00ef\u0074\u003f";

thanks,

Addison

=======================================================
Addison P. Phillips Principal Consultant
Inter-Locale LLC http://www.inter-locale.com
Globalization Engineering & Consulting Services

+1 408.210.3569 (mobile) +1 408.904.4762 (fax)
=======================================================

On Wed, 19 Jul 2000, William Overington wrote:

> I am learning to program in Java and wonder if someone could kindly point me
> in the right direction as to how I can get unicode character codes into my
> programs please. I have written various applets on non-unicode topics and
> got them to work successfully. I am aware that Java uses unicode for all of
> its characters and strings but thus far I have not been able to get any
> character that cannot be typed on an ordinary keyboard into the software.
>
> Here is what I have so far for the present program, which works.
>
> import java.awt.*;
>
> public class TryUnicode extends java.applet.Applet
> {
> String textstring;
>
> public void init()
> {
> setBackground(Color.yellow);
> textstring="The quick brown fox";
> }
>
> public void paint(Graphics screen)
> {
> screen.setColor(Color.blue);
> screen.drawString("" + textstring,50,200);
> }
>
> public void update(Graphics screen)
> {
> paint(screen);
> }
>
> }
>
> Suppose that I wish to get a lowercase c circumflex character printed onto
> the screen. As I understand it, this is character (decimal) 265 and
> (hexadecimal) 109. From something I saw a long time ago, before I started
> learning Java, I think that I need to put something like \u0109 into the
> program somewhere, though whether it is \u0109 or "\u0109" in quotation
> marks or whatever I do not know. Is that correct or is there some other
> method please?
>
> William Overington
>
> 19 July 2000
>
>
>
>
>



This archive was generated by hypermail 2.1.2 : Tue Jul 10 2001 - 17:21:06 EDT