Java Platform Independent or Platform Dependent? JDK or JRE?


Java platform independent

We have read everywhere it described that java as platform independent. Yes. (Period) It is only platform independent language. The other languages like JavaScript, PHP and Python are considered as platform independent. But those are scripting or interpreting language. Only Java is platform independent high level programming language. Point to note here is JRE gives the platform independent flexibility in java.

JDK VS JRE VS JVM

 

Let us have an example, The USB drive is created with flash chips and controllers. It is assembled in manufacturing unit. Once it is assembled, it is accessible from all the smart gadgets such as laptop, desktop, smart TV or music player. It looks like the USB drive is device independent as it works with all the smart gadgets. But that is far from truth. Each smart gadgets has its own USB device driver installed and that identifies the USB device and connects with smart gadgets. So USB device driver makes the USB drive as device independent, meantime the USB device driver is device dependent. Every operating systems and smart gadgets has its own USB device drivers. So USB device driver is device dependent and USB device is device independent. Meantime to access the flash drive, the USB device driver is sufficient, do not require the manufacturing unit. But if we want to change the flash chips or controller in USB drive, we require the manufacture unit.

 

The above analogy in Java as well in terms of platform independent. The .class files are created from .java after compile the .java file in JDK. The .class file could run in all the platforms which has JRE installed. JRE is platform dependent, every OS has different JRE installer.  So same .class file run in all the OS platform without any changes with the help of JRE. So we call java as platform independent. But the reality is JRE makes the java as platform independent and JRE is platform dependent.

 

If we want to run the class file, we do not require JDK. Just JRE is sufficient to run the .class file. To deploy the war or ear file in Application server such as Jboss or Apache Tomcat, only JRE would be required. But if we want to change the Java code, we require the JDK. Final words, JRE is sufficient to run the class file which is compiled java code. JDK is required to change, compile or debug the java code. The connected dots as below,

 Memory chips and controllers to create USB device    <=>   *.java code to create *.class file

 Manufacturing unit which creates USB drive  <=>   JDK which creates *.class file.

 Device dependent USB device driver to connect USB device  <==>  Platform dependent JRE to run *.class file

 USB device driver connect the USB with all the smart gadgets<=>   JRE runs class file in all the platform.

In short, JDK = JRE + Java development libraries

We have no more confusion. Now we know, what we require JDK or JRE? In Other words, USB manufacturing unit or USB device driver 🙂 We are moving towards architect goal. We require JDK and Eclipse workspace to begin. Happy Coding!!!

Tags: , ,

You may also like