Thursday, December 14, 2006

First question for any one in Java .. ? JVM/JRE/JDK ?

A very old friend of mine at very early stages of picking up Java wanted to know what's exactly different between JVM, JRE and JDK. Well not one, but many did have the same question..

If you want to develop Java get these clear.

JVM is inside JRE, or its an instance of JRE. Its like (sorry its not exactly like but in-effect) a virtual machine. When a Java application has to be run, It opens up the byte code (.class file) provided to it. Loads it into the Virtual Machine, interprets the byte code based on machine type on which its running or uses JIT compiler such as Sun’s Hotspot. Keep in mind that some Java programs like Hello World might not even need JIT compilation, it can just work with interpretation, but more complex application might/will need JIT compiler where it compile before running it. It also manages the way the application runs inside the Virtual Machine. i.e. it manages the space allocation, etc… while the loaded application is running. Once execution is complete the JVM is garbage collected.

JRE as explained it contains JVM, and in essence it contains the Java API Libraries, Browser Plug-in, which makes minimum environment to execute Java based applications, and JVM uses these while executing an application. JRE also acts as an interface between the OS and JVM.

So if any one is going to run a Java application (already developed) they will need JRE which sits on top the OS, and JVM which sits within the JRE. So a clients machines will need JRE.

But who is going to develop the application? And one who develops - will they need JRE? No. As explained above JRE will only be able to take in the class file for it to run the application, but to get the class file, developer of the application will need JDK. Developer Kit, is going to contain the list of java classes (over 5000  classes today from Sun Microsystems) to build the java (.java) application to byte code (.class) type. This byte code can be distributed as just .class file, or if there are several .class files which make an application then it can be archived into .jar file type and shipped/transferred to client machine to execute it on their machine where JRE is installed already.

Having JDK on client is not any harm, since JDK comes with JRE and JVM, you don't need to separately install JRE. But its an overkill. Client machines are obviously expected to be thin in configuration , like even a mobile phone can have a JRE where you can run your application, and installing JDK on a Linux based thin machine, will make it choke and cry. So as a developer (expected) who is reading this, you will need only JDK, and request your friends / clients to install JRE.