Platform Independent In Java

When we compile a java program it converts into byte-code. Byte code is an executable form of Java code for JVM (Java Virtual machine). We can execute this compiled code (byte code) on any platform like Windows, MAC, UNIX, etc. Java code can be written once and run anywhere.

A program written in java language is a human-readable language because it contains words, phrases, etc. The machine can’t understand this language so java code is converted into machine language through certain processes.

In the first step, you compile your code using javac (Java Compiler). After successfully compiled a .class file is generated and this .class file contains byte code which only understands by JVM (Java Virtual Machine).

Suppose that you have compiled the java code on the windows operating system and after generated the .class file you can copy this class file into another operating system like Mac, Linux, etc. If this operating system has JVM installed in it then our .class file can easily run on that another platform(Operating System). You don’t need to rewrite the java code on every Operating System. Hence java is Platform Independent.

In C Programming Language when a c program is compiled it directly converted into machine language (Only understand by that operating system on which we compiled that code) but in java language when we compile a program it doesn’t directly convert into machine language rather than it convert into a byte-code form which is not directly understood by an operating system and here code is machine-independent. This byte-code is only understood by JVM and then JVM converts that code into machine language (machinedependent code)

Java Code execution process

 

If you have any Questions or Queries
You can mail us at mohsinrahman318@gmail.com