We all know how to write Java programs. We also have used English language for doing this. Today, I tried to write a Java program in hindi language using eclipse and then execute it.
1. The Java Program in Hindi
Let us see how this can be done. Below is a code sample that can easily be written with any language translator.
public class DemoHindiProgram {
public static void main(String... s) {
java.util.Locale हिन्दी = new java.util.Locale("hi", "IN");
int लंबाई = 20;
int चौड़ाई = 10;
int क्षेत्रफल;
क्षेत्रफल = लंबाई * चौड़ाई;
System.out.printf(हिन्दी, "%dn", क्षेत्रफल);
}
}
2. Problem
The actual problem starts when you copy the above code in the eclipse. When you copy the above code in eclipse, it complains through various compilation issues.
These issues are basically due to the default character encoding in eclipse which is “Cp1252“. We need to change this.
3. Solution – Change Default Encoding
This default encoding can be changed from location : "File > Properties"
. Change it to UTF-8.

4. Demo
Now create a class with name “DemoHindiProgram.java”. This file will have no compilation issues and if you execute the above program “Right click > Run as > Java program“, you will be able to see the output as “200” in the console output.
A fun fact is that console output is also in Hindi letters.

Happy Learning !!
Comments