Introduction
Why, Java is a platform-independent language.
There is Two Term used:
1. Platform
2. Independent
What is Platform?
Hardware
+
Software (Windows, Unix or Any operating System)
We can define a platform as the combination of hardware and software, that provides the environment to run the program. We can say that a platform is the computer and the operating system running on it. The operating system can be Windows, Mac, Linux, or any of many others. 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 of the JVM.
Source Code to Byte Code
In Java, the source code is compiled and converted into the byte code. This byte code is not the machine code so the specific platform cannot understand it since it is not machine code.
In Java, the byte code is not the required machine code. So for the required machine code we have the Java Virtual Machine in Java. It interprets the byte code 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.
Platform-independent and Platform Dependent
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; that is why it is known as platform-dependent. Java is platform-independent because it does not depend on any type of platform. Hence, Java is platform-independent language.
So, At last We can say that,
Java is a platform-independent language. because you can write your code once and then run it anywhere, on any platform that provides the environment to run it. This environment name is the Java Virtual Machine (JVM). The JVM must be present in your system to execute the java code. The JVM is different for each platform (operating system) like windows, Unix. 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. This is the key point of platform independence in Java.