Why Java is platform independent

Subhadeep Ghosh
3 min readDec 12, 2021

--

One of the interesting features of java programming language is its platform independency. First of all, lets understand in brief about platform dependent and platform independent programming language.

What is a platform?

A platform is basically the system(operating system) in which a program executes. For example windows, linux etc. are platforms.

Platform dependent & independent programming language:

Suppose you have a windows system. Now you write a program using a particular programming language and execute it on your system and you see it executes fine. Now you try to execute that particular file on linux. If it does not work then the programming language you use is definitely platform dependent and if it works, it is platform independent. Programming languages like C and C++ are platform dependent, on the other hand programming language like java is platform independent.

Lets understand first in brief, why programming languages like C or C++ is platform dependent:

In case of C or C++, compiler basically converts the code in the form which is understandable only to that particular system. We can’t execute that code to another system.

Why java is platform independent?

To understand this concept, we have to be clear about one of java’s very important concepts called bytecode. After successful compilation of java code which is stored in .java file a .class file is made. That .class file is basically contains a code written in a messy language completely beyond our capacity of understanding. But the interesting fact is, that code is nothing but the code written on the .java file. Simply that messy code contained by .class file is known as bytecode. Basically that bytecode is executed by interpreter at the time of execution.

So, basically java compiler converts source code to bytecode after successful compilation of that code and that bytecode plays the vital role to make java platform independent.

Now, bytecode created in windows, definitely not understandable to linux. So how it helps to make java platform independent?

It is very simple. There is a concept of jvm or java virtual machine which is present in almost every platform. Every jvm understand the bytecode, no matter which platform that bytecode belongs to. Simply bytecode created in windows is understandable to jvm of linux or jvm of mac os or jvm of any other platform. Basically, jvm makes the bytecode understandable to its corresponding platform. So, clearly in which platform bytecode is created really does not matter for any jvm and for that reason java is platform independent.

--

--

Subhadeep Ghosh

I am a student of MCA final year and really love programming.