Why Java is platform independent?

Java is a popular programming language. It is used to build mobile apps, desktop apps, web applications, enterprise software and many more. Java supports Object Oriented Programming (OOP). What makes Java special is that it is platform independent. That means, Java code written in one machine can run on a different machine. This principle is called WORA (Write Once, Run Anywhere).

But how Java is able to maintain platform independence? How does code written on one machine can run on some another machine? The answer lies in the structure of how a Java program is converted to machine code.

Unlike other programming languages, where compiler converts the high level code to machine code, thus making it impossible to run that code in some other machine, Java code is first converted into Java Byte code. You must have seen that when we compile a java program, a .class file is created. This .class file contains the Byte code.

Now, the next step is taken care of by what we call the Java Virtual Machine (JVM).The JVM comes bundled with the SDK for a particular operating system.

The JVM is different for different machines. Thus, it converts the Byte code to machine specific machine code and executes it. So for different machines, the JVMs are different. While the Byte code is platform independent, the JVM is platform dependent.

Therefore, we can write a Java program on any machine and run it on different machine because the Byte code will be converted by the JVM designed for that particular machine. The flow is as follows:

Java Code -> Compiler -> Byte code -> JVM(for the particular machine)-> Machine specific code

The Java Virtual Machine is downloaded according to the machine.

Hope that you liked the post. Keep visiting iCuriousGeek!

Also read: Computer Software: I love using these

Leave a Comment

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

Copy link
Powered by Social Snap