What is Bytecode? And purpose of bytecodes.
Java is platform-independence and it is achieved using bytecodes. There are basically 2 forms of programs exists i.e. source code and object code.
Source code is nothing but the textual version of the program that we write using a text editor.
Object code is an executable form of a program. It can be executed by the computer and it is specific to a particular CPU. Therefore, it cannot be executed on a different platform.
To remove this restriction java compiler produces an object file that contains bytecodes instead of producing executable code. Bytecodes are instructions that are not for any specific CPU.
What is Java Virtual Machine? And purpose of JVM.
Java virtual machine is nothing but a virtual machine that runs the java code.
Bytecodes are designed to be interpreted by a java virtual machine. Java becomes platform-independence due to the fact that the same bytecodes can be executed by any JVM.
If JVM is implemented for a given environment, it can run any java program.
For example, Java programs can be executed under Windows 98, IRIX, Solaris etc for which a JVM has been implemented.