Richard Chapman
Richard Chapman

Reputation: 3

Java - How can I use Arabic characters?

I'm creating a flashcard-type game to help in learning a new language. Now the actual language I'm trying to use in my program is Urdu, but when I look at a unicode chart Arabic and Urdu letters are mixed together and I thought more people would know what I'm talking about if I said Arabic.

So, on my Windows 8 machine I can change the keyboard layout to Urdu and whatever I type into Java is correctly displayed back to me. However transferring this code to another computer with Windows 7 (at my school) changes the Urdu characters in the raw Java file to odd-characters/mumbo-jumbo. Coping and pasting the character from the online unicode chart displays in the java file, but is shown as a '?' in the actual program itself, and in the System.out method.

Now when I use the unicode escape commands (ex. \uXXXX) these are displayed correctly on both computers.

The problem is that I don't want to use escape commands every time I want to write something in Urdu. I plan on writing long sentences and many words. So I was thinking of making an array of the unicode codes and then perhaps a method that converts a English string of letters into Urdu using this array but I thought there must be an easier way to fix this problem.

I'm still kinda a beginner, but I wasn't planning on making a very complex program anyway. For any help, thanks.

Upvotes: 0

Views: 3003

Answers (1)

Brage Celius
Brage Celius

Reputation: 141

This sounds like a problem with the encoding in your compiler on the Windows 7 computer. You should make sure that both computers are using encoding that supports arabic/urdu characters, such as UTF-8, when compiling.

If this is not specified, the compiler will use the system's default encoding which might not support arabic/urdu characters. See this link for information on how to find/set encoding properties.

You can get the encoding currently used for compiling by adding this piece of code:

System.out.println(System.getProperty("file.encoding"));

Upvotes: 3

Related Questions