As we hear all the time that the Java is the Platform Independent, then which is the thing that makes java more cooler(platform independent) than the other languages.
when we consider the computer, we know that it understands only one language and that is the Binary and as a programmer what we write is the language other than the Binary, so that to convert our code to the from of the language that the system can understand, at that time the compiler comes in to the picture, the function of the compiler is to convert the source code from the regular human understandable language to the Object language(Binary)
Java is been developed by the sun microsystems which is now been owned by the Oracle Corporation, the Java people thought little bit different from the others, they came with the Consept of the thing called “Class Files” or “Byte Code”, i ll explain that shortly.
Following figure represents the Function of the Compiler with the Regular languages like C,C++ etc.
as you can see , in the first pass you will be having the code and then you will compile that code with some compiler and than it will result in some object file that can only be understand by your system, object file is nothing but the file that contain ones and zeros. And the Linker is nothing but the one that links your current file to the other files thats been written already.
Where as in Java the Follwing thing is goin to happen, when you compile the java code.
So as you can see that , when you wll be having the source code and when you will compile that with any kind of Compiler(Ex:-Eclipse) and that will output in some kind of file that is known as the Class file that consist some kind of numbers that is known as the Byte codes, or some intermediate code, that can only be understand by the JVM(Java Virtual Machine), the class file that wont be understand by the machine, the JVM is going to pretend like that its a machine and that is going to execute that code for you. and so that to Execute the Java programs we are required to install the JRE in our systems that consist the JVM, and to Compile the code we need to have JDK.
so that you might be having the Question that why do we need to do this Extra process of going from class file to the JVM and then the output, then the Answer is that we live in the world where we have the machines like MAC, PC(Windows), Linux etc, and the 1’s and 0’s of the MAC is different from the 1’s and 0’s of the PC(Windows), and that is different from the 1’s and 0’s of Linux. so to deal with this we use this java, and the Class file will remain same for all the machine, and the JVM will result in the same output for all the machine for that class file, the thing is that JRE is the one that is platform dependent and there are various JRE available for all the Platforms, and thats why the code thats written in the MAC can be executed on the PC with the help of its class file, so that it is known as the paltform independent.