Why Java is Platform Independent Language?

In this article we will learn about why java is platform independent. Before getting into details of this first we should know what platform independence is.

Platform Independence: It means if we have written a program it should run on any platform without any modifications. Platform means hardware + operating system.

Why Java is Platform Independent Language?

Java package is coming with JDK (Java Runtime Environment) and JRE (Java Runtime Environment). JDK will be useful for developing and compiling java code. After compilation it will give output .class file. This class file can run using JRE. If JRE installed in system then JVM also be installed automatically. JVM give platform independence to java. If we take an example of platform dependent language then we can be clearer about how JVM is giving platform independence to java.

Let us take our familiar language ‘C’ which is platform dependent. After writing C program we will compile the code it will provide .out file. This .out file will contain machine understandable code. According to the machine configurations and operating system environment this compiled codes may vary.  We can say that those compiled codes are machine native. In the case of java, after compiling the java program, we will get byte code as an output. This byte code can run on a virtual machine that is java virtual machine.

This java virtual machine is very standard one. It will provide same environment for the byte code to execute whatever the underlying hardware and operating systems are present. Different JVMs are available for each type of platform. Now our java compiled code (Byte code) can run anywhere irrespective of the platform because of JVM. We can’t say these byte codes are machine native codes because we can write a java code and compile here but we can run on any system.  It will give same output. But only one thing is JVM should be installed on that system on which we want to execute our byte code.

Lets try to visualize this scenario using pictures.

write once compile anywhere

Image Source

Here we can write code on our system but it should be compiled on the system where we want to execute it. If we observe, for execution of the program we are depending on platform here. We are considering what type of platform we have to execute.

Where as in case of java,

write once run anywhere

Here we can write java program and compile that code in our system itself. After that compilation .class file will be generated. It is globally executable (with the restriction JVM should be installed).

Java Platform Independence Benefits

  1. Java is developed for emerging need of a programming language for embedded devices. So java developers aimed at one programming language which can be used irrespective of the platform. They introduced a language finally that is java. So we can say that the main aim of developing java is platform independence. Java can be used on any platform but with constraint JVM should be installed on it.
  2. Because platform independence most of the enterprises will choose java. Because if they are developing an application they need to worry about the user platforms. Suppose if our application is platform dependent let us take windows platform, and then they have to lose the users who are using platform other than windows. But it is not in the case of java. If we are developing an application we can deploy it on any platform.
  3. Because of platform independence it solves the many problems in internet programming. Simple web applications are being written in java in the form of applets. If we are using java enabled web browsers then we can run those applets on our machines. Those are very simple to use.

Leave a Comment

Your email address will not be published. Required fields are marked *