My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Tuesday, May 9, 2017

Unicode characters in Eclipse console : Resolving Eclipse IDE issue when console runner not shows Unicode and Multibyte characters.

First of all little gyaan:

What is Unicode character string:
Earlier we used ASCII etc to encode characters. But the limit of the number of characters were less. Obviously, you cannot capture world in 256 numbers!
Then we developed some more encoding to cater to all languages but many of them had issues like below:
1. A particular code value corresponds to different letters in the various language standards.
2. The encodings for languages with large character sets have variable length. Some common characters are encoded as single bytes, other require two or more byte.

Here enters our beloved Unicode. Our hero, a new language standard was developed and in this character holds 2 byte. Hence, java or C++ or any language, uses 2 byte for characters representation.

lowest value:\u0000
highest value:\uFFFF


My problem statement in this post is that sometimes the unicode characters are not visible in the output console of Eclipse IDE. This blog post aims to solve that.



Suppose our program is:
public class Simple{
public static void main(String... args){
System.out.println("Hi World!");

String arabicText = "اسمي أنور";
String banglaText = "আমার নাম আনোয়ার";
String urduText = "میرا نام انور ہے";
String hindiText = "मेरा नाम अनवर है";
String frenchText = "Je m'appelle Anwar";

System.out.println(arabicText);
System.out.println(banglaText);
System.out.println(urduText);
System.out.println(hindiText);
System.out.println(frenchText);
}
}

On running the output is:
Hi World!
???? ????
???? ??? ???????
???? ??? ???? ??
???? ??? ???? ??
Je m'appelle Anwar

See screenshot:






To resolve this you need to Modify your Run Configuration:
To Open Your Run Configuration. This can be achiebved by:
In Package Explorer, right click on your project
Run As-> Run Configurations


Here In the common Tab, check the Encoding used:

Change it to UTF8.
Click apply and Run





Now Run the program and you should find correct result. New output is:

Hi World!
اسمي أنور
আমার নাম আনোয়ার
میرا نام انور ہے
मेरा नाम अनवर है
Je m'appelle Anwar

See screenshot:

You can download the repository having the sample code from Gitup. See: https://github.com/Anwar-Faiz/Simple-Java-Unicode

No comments:

Post a Comment