Tuesday, August 18, 2009

Java Unicode (source code)

We all know that Java is great with Unicode. I was surprised to know that the compiler itself has moved on. The Java source itself can be in Unicode now!!

Check out the sample Java source file

 1 /**
 2  * @author prashant
 3  *
 4  */
 5 public class JavaUnicodeTest{
 6     static class मज्जाआहे  {
 7         public मज्जाआहे()     {
 8             System.out.println("constructor of " + this.getClass().getCanonicalName());
 9         }
10
11         int पाचद्या()       {
12             return 5;
13         }
14     }
15
16     public static void main(String[] args) {
17         मज्जाआहे o = new मज्जाआहे();
18         System.out.println(o.पाचद्या());
19     }
20 }

Using OpenJDK
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.5) (fedora-27.b16.fc11-x86_64)
OpenJDK 64-Bit Server VM (build 14.0-b15, mixed mode)

It runs fine, giving

constructor of JavaUnicodeTest.मज्जाआहे
5


weird, eh?

4 comments: