Why java is platform independent language? To understand this just look at two pictures you will understand half of the concept.
Javac: The Java compiler that converts source code(.java file) into byte code(.class file)
JVM: Java Virtual Machine is the interpreter that converts byte code(.class file) into Machine language.
- As we all know java is both compiled and interpreted language.
- Once the .java file also known as source code is compiled, it gets converted into native code known as byte code( or .class file) which is portable and can be easily executed on all the operating systems.
- The .class file is basically represented in hexa decimal format which is same for all the platform whether it is Macintosh, windows or Linux.
- After compilation, the interpreter reads the generated byte code(.class file) and translates it according to the host machine.
- Byte code(.class file) is executed by Java Virtual Machine(JVM) which is available with all the operating systems we install.
- So to port Java programs to a new platform all that is required is to port the interpreter and some of the library routines.
If you like the article, please like, subscribe and comment to be updated with this kind of articles.