I am fairly new to Java and I was wondering why Java uses a virtual machine (the java program) to execute code after it has been compiled (by javac) unlike C.
Check the link,It will make you clear about the whole process on which java works
How is Java platform-independent when it needs a JVM to run?
After the compilation,the code actually have to go through an intermediate state that is called as the bytecode.This bytecode is then taken up by the JVM present on the machine and then is converted into the form that is executable by the machine.
The JVM for every different platform is different,But the bytecode generated by the compiler is same everytime.The JVM performs the function of handling the bytecode and producing executable code in the form as is understood by the platform on which you are working on.This is the reason that java is called as "Write Once Run Anywhere".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With