Javatpoint Logo
Javatpoint Logo

Why is Java Platform Independent

Java is a class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is intended to let application developers write once and run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without recompilation. Java was first released in 1995 and is widely used for developing applications for desktop, web, and mobile devices. Java is known for its simplicity, robustness, and security features, making it a popular choice for enterprise-level applications.

One of the most prominent features of Java is platform independent. Platform-independent means the Java code that has been compiled generates compiled code or the byte code, and this byte code can run on all of the operating systems provided they have JVM installed in it. Basically, a program is a set of instructions that have been written in a human-readable language. Note that programs written by humans are not understood by machines. Here compilers come into the picture. A compiler compiles the program or source code into a format that can be easily understood by machines.

Therefore, one can say that a compiler is a translator that does the translation of code from human-readable format to executable code. The executable code may be run directly by the machine or maybe an intermediate representation that is run on the virtual machine. In Java, that intermediate representation is known as the Java Byte Code.

Step By Step Code Execution in Java

  • The developer or programmer writes the code in a human-readable format. Java compiler compiles it into byte code. Note that Byte code is not the native code for the machines. (Unlike C++/C compiler)
  • Byte code is not the machine executable code and hence, requires an interpreter to interpret it. The interpreter is the Java Virtual Machine (JVM) that executes the Byte code.
  • Eventually, the program executes and shows the output.

In C or C++ compiler compiles the code to generate the .exe file that has been executed by the machine on which the compiler is installed. However, in the case of Java, instead of .exe file, a .class file or Byte code is generated.

Java is Platform Independent but not JVM

It is important to note that JVM is platform dependent. So, for the Windows operating system, we have the JVM specific to Windows. For the Macintosh operating system, we have the Macintosh-specific operating system, and the same concept is applied to the Linux operating system too. The same is evident when we go to the websites to download the JDK (JVM is part of JDK). A list of operating system-specific JDKs is shown, and the user has to decide which one is suitable for accomplishing the task. Observe the following screenshots.

For Windows,

Why is Java Platform Independent

For Linux,

Why is Java Platform Independent

For Macintosh,

Why is Java Platform Independent

By looking at these screenshots, it is evident that JVM is not platform specific.

Important Points To Remember

  • It is the Byte code that makes the Java platform independent.
  • Because of the platform-independent, Java gets an important feature called portability. Each system has its specific JVM that is installed automatically when the Java Development kit (JDK) is installed, and it is the JVM that reads the Byte code or .class file.

Note: Now, we know that Java is platform-independent, but JVM is platform dependent. Because JVM is platform-dependent, Java is not considered as a complete platform-independent language.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA