How to Compile and Run Java Program in Hindi

Lokesh Gupta

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.

eclipse-default-encoding-7096997

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.

java-hindi-program-output-4191902

Happy Learning !!

Comments

Subscribe
Notify of
guest
2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode