How to compile and run java program written in another language

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. [For fun only]
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", क्षेत्रफल);
	}
}

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.
This default encoding can be changed from location : “File > Properties”. Change it to UTF-8.

eclipse-default-encoding

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.

Fact of the fun is that console output is also in hindi letters.

java-hindi-program-output

Happy Learning !!

Lokesh

I have 7 Years of rich experience in java technology. This has only increased my hunger to learn more. In this blog, i will be writing on different topics occasionally, and would love to engage in some meaningful serious discussions with you folks.

You may also like...

2 Responses

  1. Sir, I need to display hindi character in textfield how is it possible

  1. December 8, 2012

    [...] How to compile and run java program written in another language « How to do in JAVA [...]

Note:- In comment box, please put your code inside [java] ... [/java] OR [xml] ... [/xml] tags otherwise it may not appear/post as intended.


Want to ask any question? Or suggest anything?