Java Virtual Machine
Hello friends, today I am going to share with you a small article on JVM. It is short yet clear to your understanding of the java virtual machine. Sit, pull a cup of coffee and join me in the lesson.
What is Java Virtual Machine(JVM)?
Just like the name insinuates, it is an engine that helps java applications run on machines. It provides runtime environment for java applications.
How does the JVM work?
It simply translates byte code into machine language. As a result, the application can run.
Unlike other compilers that directly creates a machine language during compilation, java compiler creates intermediate code called bytecode. The bytecode is then transformed into the machine language. This happens at run time and is what is referred to as just in time compiling, done by the Just In Time Compiler (JIT).
The JVM resides in the Ram. As such, the compiled bytecode needs to reach it. This happens through a subsystem called the Class Loader. This loads the bytecode onto the RAM.
In the JVM the byte code is verified for security checks by another subsystem called bytecode verifier. Then translated into machine code ready for execution. Because this is happening at runtime, it makes java a little slow compared to other languages.
See diagram below:
What are the components of JVM?
The class loader loads the bytecode, (the .class files) onto the bytecode verifier. The verifier ensures the security of the code then feeds it into the execution engine.
The execution engine does the execution of the bytecode. But to achieve this, the engine has to communicate with the underlying operating system and also translates the bytecode into the required machine language.
The class loader loads three items into the virtual machine. Majorly the three categories of classes required for the java application. These are the bootstrap classes from the rt.jar in the jre/lib folder, extension classes in the jre/lib/ext folder and the application classes.
That is all friends. I know there is a lot more than this but it gives you a glimpse of what the JVM looks like. Leave a comment and I will appreciate.