Why java is Platform Independent?
How is Java platform independent?
Platform means → H/W+S/W+OS(Windows, Mac, Linux etc.)
Java is a platform-independent language. In other words, once you write your code then run it anywhere, on any platform that provides the environment to run it.
This environment is the Java Virtual Machine (JVM). The JVM should be present to execute the code.
The JVM is different for each platform. In the case of Java, platform independence does not mean that you can run the code anywhere, you can run it wherever the environment is provided.
To run a program on any machine you need to convert it to the machine language so that the specific machine can understand it. In Java the source code is not directly converted into the machine code. It is first converted into the byte code by the compiler.
In Java, the byte code is interpreted by the JVM and converts it into the machine specific code.
So the Java Virtual Machine is very important because it makes the byte code understandable to the machine. It is the reason that, if any machine does not have the specific Java Virtual Machine then it cannot understand the byte code and the program does not execute.
Using the Java Virtual Machine we can make the byte code understandable to any platform.
That is why the byte code is known as platform-independent. But on the other hand the Java Virtual Machine is different for each platform; because of this JVM is known as platform-dependent.
Java is platform-independent because it does not depend on any type of platform. Hence, Java is a platform-independent language.
Java Program:
public class Test {
public static void main(String[] args)
{
System.out.println("WELCOME TO VDS TECH LABS");
}
}
DIAGRAM:
IMPORTANT FACTS:
Whenever a program is written in JAVA, the javac compiles it.
The result of the JAVA compiler is the .class file or the bytecode and not the machine native code (unlike C compiler).
The bytecode generated is a non-executable code and needs an interpreter to execute on a machine. This interpreter is the JVM and thus the Bytecode is executed by the JVM.
And finally the program runs to give the desired output.
Please find the video: Why Java is Platform Independent?
THANKS!!!
Comments
Post a Comment