Why Java is Platform Independent ?
In java, we can write one application and have it work on any device but the running device should have installed the Java Virtual Machine(JVM/JRE).
1- Create a source file using java protocols and syntax.JDK should be installed on the source code writing machine. The source file should save with the .java file extension. Let's assume we save the source file as test.java.
2- Compiling process also happens within the same machine that we use to write Java source code. javac which is located inside the JDK will do its task to compile the Java source code(Here it is test.java) and then convert the java source code to bytecode. . If the source file doesn't have any errors then java compile creates another file as test.class.
".class" is the file extension of compiled bytecode file.
3- We can take the test.class file out from the source code development machine and can run on any device which has installed JVM.
4- We can run test.class file(Java bytecode) on any device but it needs to install JVM/JRE on that device. JVM can interpret java bytecode and can convert it to machine code. JRE is the implementation of JVM so installing JRE is the same as installing the JVM. JRE has required tools to interpret and convert java bytecode to machine code.
Because we can write one source file(test.java) and run it on any device which has JVM installed we called java a platform-independent language. It doesn't depend on the operating system. But JVM is platform-dependent means for Windows operating system we have to use Windows compatible JRE and For Ubuntu, we have to use Ubuntu compatible JRE.
That's how java platform independence happens.

Comments
Post a Comment