How to compile and run java program in Hindi

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.

Java program in Hindi

Lets see how this can done. Below is code sample which can easily be written with any language translator.

package runtime;

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

Actual problem starts with when you copy above code in eclipse plugin. As soon as you copy above code in eclipse, it start complaining through various compilation issues.

These issues are basically due to default character encoding in eclipse which is “Cp1252“.  We need to change this.

3. Solution – Change eclipse default encoding

This default encoding can be changed from location : "File > Properties". Change it to UTF-8.

eclipse-default-encoding-7096997

Now create a class with name “DemoHindiProgram.java”.

This file will have no compilation issues and if you will execute above program “Right click > Run as > Java program“, you will be able to see the output as “200” in console output.

Fun fact is that console output is also in Hindi letters.

java-hindi-program-output-4191902

Happy Learning !!

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

2 thoughts on “How to compile and run java program in Hindi”

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.