Thursday, December 4, 2014

Write Once Run Anywhere...

From the introductory post you are repeating this, what is this ?
You like your new home and one of your friend wants to know about it. You ask him to build one for him. He finds your plan useful and thinks of reusing it.
Well, yes, the same thing happens in Java too. Once you have made the plan (compiled java class), you can reuse it to build your home (run the program).

So, once you have the compiler generated class file, you can run it on any machine where Mr. JVM is available. Let me put some picture.

You wrote it in Windows and running in other platforms also
On a more detailed picture, it looks like,

Write Once Run Anywhere
So, how it looks like in detailed steps ?
Here it is.
First you write your program in Java,

Source code in java

Next you compile it and compiler generates byte code from the source code. The byte code looks like below,

The byte code generated by the compiler
This is basically written in Hex Code. It is really a bad idea to look the program this way. You can view a Mnemonics version of the generated class file using javap. If you have ever done Micro Processor programming, you can relate things. If not, then also its not a bad idea to take a look...
Mnemonic version of the compiled output
That's all. Now you can run this any environment you like such as Windows, Linux, Unix, Mac OS.
To run a program, you don't require JDK, just JRE will suffice.

Next we will learn about JDK and JRE. What are they and how are they used.




Prev     Next
Palash Kanti Kundu

No comments:

Post a Comment