Why Java is platform independent?

Harshit SinghHarshit Singh
1 min read

What is platform independent?
High-level programming languages ( like C, C++) program, when get compiled, it gets converted into Machine Code, this Machine code is dependent upon the system(as well as OS) that programmer is using.

Example-
C++ program (developed on System with Windows OS & x86 processor) is compiled and converted into Machine code. So:

  1. if we try to run this machine code on Linux system, it won’t work because it was compiled for Windows machine.

  2. try to run on another Windows System, it may or may not work, depending on the processor and the compiler instruction set.

In JAVA:
Java compiler( javac) converts the java code into bytecode (.class file or .jar file), this bytecode is platform independent. Java Virtual Machine(JVM) on every system run this bytecode and translate it into machine code for that specific system, this bytecode to machine code translation is done by Just In Time (JIT) compiler.

Example-

Java program (developed on System with Windows OS & x86 processor) is compiled and converted into Byte code. This program runs on every platform because JVM convert it into machine code for that specific system.

0
Subscribe to my newsletter

Read articles from Harshit Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harshit Singh
Harshit Singh