Why and How Java is Platform Independent Language?

Yes, Java is a platform independent programming language. Java is often referred as "WORA"  or  "Write Once Run Anywhere" language. Like C++ and Python Java is a general-purpose Object Oriented Programming language but it has some advanced features when it was introduced. One of the super cool feature is platform independence which means the Java program can run on any platform like Windows, Linux, Mac OS..etc. This helps the programming community build software without worrying about the software's platform.

Why Java is Platform independent?

It's not the raw code, platform independence is achieved by Java byte code. If  raw code of any language(python,c+. etc.) is copied and pasted into another operating system and able to run code doesn't mean its a platform independent language.

Java achieved this due to the way the program is compiled and executed. Platform independence is possible only when the compiled code or byte code can run on multiple platforms without making changes. But in languages like C++, the written code is needed to compile for each operating system separately. This will be disadvantage to a software if it will be use across different platforms.

How Java is Platform Independent?

Java followed the below process,
  • Java Compiler: Before executing the code the compiler will compile the java code to byte code. This byte code is global and it's adaptable to all the hardware and operating system.
  • Java Virtual Machine(JVM): Java codes are executed by Java Virutal Machine. Each operating system or platform has its own version of JVM which is responsible to execute the byte code. Here the JVM becomes platform dependent to run the java byte code independently in any platform.

Why java is portable?

Platform independent feature facilitates the Java code to be portable means once the code is written and compiled then the compiled or byte code can be used on any platform to test and run the byte code. 

Advantage of Platform Independent Language

  1. Portability: Once the code is compiled it's easy to carry to any platform
  2. Compatible: In java JVM is platform dependent that makes the software compatible to any hardware and operating system
  3. Cost cutting: There is no need to work for specific platform that saves more time and cost
  4. Consistency: A portable software functionality would be same on different platform so there will be very less platform specific error and exception


Post a Comment

Previous Post Next Post
B