Showing posts with label interpreted. Show all posts
Showing posts with label interpreted. Show all posts

Thursday, July 17, 2014

Why Java Is Platform Independent

Getting output from java program is two step procedure, compilation and interpretation. Output of java compiler is not executable code but it is compiled code. JVM is an interpreter for byte code. Byte code is set of instructions which are to be executed by java run time system called as Java Virtual Machine (JVM). Each JVM has its own executable format so this byte code (.class file) becomes platform independent as this byte code runs on JVM and not on actual OS.
So once we have compiled java program, it can be executed on any platform. The details of the JVM differ from platform to platform and each OS has its own JVM format.  So in java it is “write once; run anywhere, anytime”.

So java is platform independent and JVM is highly platform dependent.

Saturday, July 12, 2014

Java is Compiled and Interpreted Both

It seems little confusing for java beginner to understand the exact difference between compilation and interpretation. Java is compiled language because java code is compiled to get byte code. Java is interpreted language because this byte code is interpreted into native code.

Actually getting output from java program is two steps process compilation and interpretation. The executable used for these steps are java compiler (javac) and java interpreter (java). First step is compilation in which the java compiler compiles the source code to generate byte code in the form of .class file. Actually this byte code is not machine code but it is just an intermediate code. In the second step java interpreter uses this byte code to generate native code for under lying operating system. The JIT (Just In Time) compiler comes into action in second interpretation step. The JIT reads the byte code to generate native code dynamically so that program runs fast.


Finally in short, java is compiled to byte code which is then used by JVM where it gets interpreted to native code. So java is compiled and interpreted both.