The Java Virtual Machine is called JVM, is an abstract computing machine or virtual machine interface that drives the java code.
When we talk about the Java applications, then it works only on those machines which have JVM.
What is JVM?
- JVM, i.e., Java Virtual Machine.
- JVM is the engine that drives the Java code.
- Mostly in other Programming Languages, compiler produce code for a particular system but Java compiler produce Bytecode for a Java Virtual Machine.
- When we compile a Java program, then bytecode is generated. Bytecode is the source code that can be used to run on any platform.
- Bytecode is an intermediary language between Java source and the host system.
- It is the medium which compiles Java code to bytecode which gets interpreted on a different machine and hence it makes it Platform/Operating system independent.
JVM's work can be explained in the following manner
- Reading Bytecode.
- Verifying bytecode.
- Linking the code with the library.
Diagram of JVM
JVM generates a .class(Bytecode) file, and that file can be run in any OS, but JVM should have in OS because JVM is platform dependent.
Java is called platform independent because of Java Virtual Machine. As different computers with the different operating system have their JVM, when we submit a .class file to any operating system, JVM interprets the bytecode into machine level language.
- JVM is the main component of Java architecture, and it is the part of the JRE (Java Runtime Environment).
- A program of JVM is written in C Programming Language, and JVM is Operating System dependent.
- JVM is responsible for allocating the necessary memory needed by the Java program.
- JVM is responsible for deallocating memory space.