What you will learn here about why java is platform independent
- What is platform dependent
- Why C is not platform independent or why C is platform dependent
- What is platform independent
- Why java is platform independent or How java is platform independent
What is platform dependent
Platform dependent means code which we compile on one platform will not work or run on another platform. Where Platform is nothing but the combination of the operating system (OS) with a processor. The platform can be WIndows, Linux, MAC OS, etc. For Example, the C language is platform dependent.
Why C is not platform independent
For example, When we compile C code on windows, the Compiler which is running on the windows system will generate .exe file which is only understood by windows platform, not by the other platforms. If you want to run the same source code on another platform then you need to download the compiler which will compile the code for that particular platform only. This is the reason C is platform dependent means you have to download or use compiler according to the platform on which you are running C code.
What is platform independent
Platform independent means code compiled on one platform can run on another platform without compilation. Java is platform independent language means java code compiled on windows platform can run on the Linux platform as well MAC platform.
Why java is platform independent
Java is platform independent because of JVM. Now the question comes how? right!. When we compile java source code using java compiler, it generates .class file which is nothing but the bytecode. The bytecode is platform independent and bytecode is only understandable to JVM and not the windows, Linux, Mac OS, etc. So when we install JDK or JRE on any platform then JDK or JRE has to be the platform specific because JDK and JRE have inbuilt JVM which is platform specific. JVM is basically responsible for converting .class or bytecode into platform specific executable file which is shown below. This is the reason why java is palform independent
Sangeeta S M
This post is contributed by Sangeeta S M. If you like to contribute bytesofgigabytes, you can also write an article using bytesofgigabytes contribute . See your article appearing on the bytesofgigabytes.com main page to help other people.