November 26, 2011

Writing Unicode characters in Java

Create the following class in the src folder of the Java Project in Eclipse


package info.icontraining.core;

public class CharExample {

   public static void main(String args[]) {
 
      char c='\u0915';
      System.out.println(c);
   } 
}


To enabled Unicode character display in the console of Eclipse, make the following 3 configurations in Eclipse:

1) Open the "Run" menu > Choose "Open Run Dialog ..." > Choose your application and the particular class (in this case, CharExample) > Click on the "Common" tab > Choose "Console Encoding" as "Other" and "UTF-8" from the drop-down list

2) Next, go on the "Arguments" tab > Copy the string "-Dfile.encoding=UTF-8" in the VM arguments text area (without the double quotes). Click "Apply" and then "Close".

3) Finally, go to the "Window" menu > Choose "Preferences ..." > Next, choose "General" > Then "Workspace" > In the "Text File Encoding" select "Other" and "UTF-8" from the drop-down list

No comments:

Post a Comment