HOW JAVA PLATFORM INDEPENDENT

The Java Platform
A Platform is the hardware or software Environment in which a program runs. We have already mentioned some of the popular platforms like Microsoft Windows, Linux, Solaris OS, and Mac OS.
Most platforms can be described as a combination of the operating system and underlying hardware.
The java platform is software-only platform that runs on top of other hardware-based platforms.
The java platform has two components:
i) The java virtual machine.
ii) The java application programming interface(API).
As we have already discussed about JVM, it is the base for java platform and is ported onto various hardware-based platforms.
The API is a large collection of ready- made software components that provide many useful capabilities.
It is grouped into libraries of related classes and interfaces,these libraries are known as packages.
 

How Java Is Platform Independent?

java platform independent

In the java programming language, all source code files saved ending with the .java extension.
Those source files are then complied into .class files by the javac complier.
A ".class files"contains bytecodes(in the form of 0 & 1).
The java launcher tool then runs your application with an instance of java virtual machine.
JVM is available on many different operating system, the same ".class files" are capable of running on Microsoft Windows, the Solaris Operating System (Solaris OS), Linux, Mac OS.
Java programs that have been compiled into byte code still need an interpreter to execute them on any given platform.
The interpreter reads the byte code and translates it into the native language of the host machine on the fly.
Since the byte code is completely platform independent, only the interpreter and a few native libraries need to be ported to get Java to run on a new hardware or OS.
The rest of the runtime environment including the compiler and most of the class libraries are written in Java.
The concept of Write-once-run-anywhere (known as the Platform independent) is one of the important key feature of java language that makes java as the most powerful language.
Not even a single language is idle to this feature but java is more closer to this feature.
The programs written on one platform can run on any platform provided the platform must have the JVM.