Why is Java Platform Independent Language?


Java has gained huge popularity among all other programming languages since its birth. And the reason for such an immense response is the ability to provide unique features. Java syntax will be almost similar to c++ but provides way far features than c++.

The availability of object-oriented programming (OOP) made java stand out from all other remaining languages at its time. Java was developed to use OOP at its core and it was one of a reason for being a most used language. This concept increases reusability, seamless execution. At this moment, there may be a question in our mind “why should we use an object?”.

Objects in Java are similar to structures in c language, where we are binding similar methods and variables together. Along with that Java also provides abstraction, encapsulation, inheritance, and polymorphism which encourages the user to implement objects.

Java plays a dominant role in many domains like app development, web development, building software tools. It also has a rich number of libraries which makes things easier. Also, the availability of IDE plays a crucial role in gaining the attention of developers. IDEs like Eclipse, IntelliJ, NetBeans are frequently used by many developers.

Fine, now let’s come to our discussion.

But first of all, what does platform independence mean?. To get an answer to that question we need to know what happens when we compile a code.

Compiling a Code

Whenever we write a code, we follow the syntaxes of a programming language, which would have a fair amount of readability. And it contains few words, phrases, variable names, method names, etc. All these things are considered to be human-readable and human-understandable text.

So a machine uses a compiler to convert the source code into a machine-readable code which is also referred to as machine-level language. The compiler builds the machine-level code in a specific presentation such that it can be easily understood by the CPU and hence execute it seamlessly.

This building of machine-level language differs by each programming language and each operating system. For example, c/c++ generates a .exe file that is not the same for two machines if they are running on a different operating system.

And here arises the problem!

When a machine level language differs by each operating system, then we cannot run a code that is compiled in a different machine in a new machine, unless both of the systems operate on the same operating system. This feels like crap for many programmers and developers.

But Java makes things easier, and java has a solution for this. Let’s get started.

Java is Platform Independent

So what happens when we compile code in java?

Whenever we enter a statement “javac” or compile a code in java, javac compiles the code. And it creates an intermediate code called Byte Code.

This is where java makes difference between all different programming languages. It creates a .class file, which is considered as byte code. Whereas languages like c/c++ will create a natively executable code when they are compiled and thus makes them platform dependent.

Hold on, this is too early for celebration. This byte code is not executable. We need a translator for executing this byte code. And JVM does this job. Generally, JVM resides in the main memory of our computer. Java Virtual Machine acts as an interpreter and then executes the byte code generated by javac.

And now we are done, our code gets executed successfully.

So how does java going to manage it all alone?

And the answer would be, it’s because of the JVM. The byte code generated by source code compilation would run in any operating system, but the JVM present in a machine differs for each operating system. And this is how java is considered a platform-independent programming language.

To understand it properly, let’s understand the architecture and working of the JVM.

Our learners also read: Java free online courses!

JVM Architecture

JVM is part of the java runtime environment and is responsible for converting a .java file into a .class file. When we compile a java code JVM calls the main method in the source code.

                                JVM Architecture


It is a subsystem in the java virtual machine. It loads the .class file, checks if there are any exceptions and it is the reason for few runtime exceptions. And after checking it allocates the memory for the variables and the methods present, assign default values to variables and arrays. It also executes the static methods or variables present in the code.

There are 3 built-in class loaders inJVMm, bootstrap classloader, Extension classloader, Application classloader.

Memory Areas in JVM

Method/Class Area

It stores information like class names, method names, variables. It is a shared resource for all the methods and variables in a class.


It stores the information of all the data stored in the heap area.

JVM Language Stack

It stores the information in blocks also called stack-frames/frames, which stores the current information when there is a function call, stores local variables, it also plays a dominant role in thread management.

PC Register

It stores the address of the instruction which is currently being executed. It is useful in a multi-thread execution situation.

Native Method Stack

It stores all the information of the native methods used.

Execution Engine

The Execution engine will execute the byte code, and it removes the allocated memory to the objects which are unreachable or unreferenced. The interpreter in the execution engine will execute the byte code by reading it in a stream and interpreting line by line.

It also has an exciting part called JIT compiler (Just In Time Compiler), where it creates a native executable code for methods, so if there are multiple function calls then the JVM need not interpret it again, rather directly use the native executable code. Hence it improves the performance of execution.

Native Method Interface

This interface is used by java for interacting with the applications implemented in different languages like C/C++. The interaction is bidirectional, where the JVM may call those applications or can be called by those applications.

Native Method Libraries

It keeps track of the native language libraries, which may be used by the execution engine.

Now that we’ve understood the architecture of the JVM let’s get back to our discussion. So this JVM is different for different operating systems, but the output generated by those JVMs will be the same for the same byte code provided.

Also Read: Java Project Ideas & Topics

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.


We’ve gone through few unique features of java, understood what happens when we compile code in languages like C/C++, understood the difference between natively executable code and byte code. We’ve walked through the explanation of why java is considered a platform-independent language, understood that JVM is the reason behind java’s platform independence. We had a look at JVM architecture for a better understanding.

Now that you are aware of the reason why java is platform-independent, explore other unique features of java and start utilizing them!

If you’re interested to learn more about Java, full-stack software development, check out upGrad & IIIT-B’s Executive PG Program in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

What are the advantages of Java over other languages?

There are many advantages of Java over other languages. Let's start with the topmost advantage, Java is platform independent. Java code can run on any hardware platform, operating system and browser. It can run on any device. This means that once you have written your application in Java, you can run it on any device. It's as simple as that! Also, once you have written your code, it's very easy to debug and fix bugs. Finally, Java is object oriented. This means that you need to use smaller programs and code. This will make your code easier to work with. If any modifications are needed, the code is less prone to errors. It has features like Multithreading, Memory Management, Platform independent, Security, Virtual Machine i.e., bytecode, Collection Framework, Garbage Collector, Layered architecture, etc.

Why is Java platform-independent?

Java is platform-independent because it uses a virtual machine. The Java programming language and all APIs are compiled into bytecodes. Bytecodes are effectively platform-independent. The virtual machine takes care of the differences between the bytecodes for the different platforms. The run-time requirements for Java are therefore very small. The Java virtual machine takes care of all hardware-related issues, so that no code has to be compiled for different hardware.

What is automatic garbage collection in Java?

Automatic garbage collection is a garbage collection technique in which the garbage collector runs automatically, without the programmer having to write code for it. In Java, garbage collection is done by putting the Java Virtual Machine into a special mode. The garbage collector will run when it sees an opportunity to do so. Some garbage collectors use a stop-the-world approach, and the Java Virtual Machine must stop executing the program to do garbage collection. Garbage Collection isn’t an easy concept, but once you get it, there’s no looking back. And Java’s garbage collection is one of the easiest to understand.

Want to share this article?

The best time to learn is now!

Leave a comment

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

Our Popular Software Engineering Courses

Get Free Consultation

Leave a comment

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

Let’s do it!
No, thanks.