What is Java Virtual Machine

 It’s a process which converts compiled JAVA byte code* to machine code.


J
VM is the cornerstone of the Java Platform and includes wide range of responsibilities-

1. Making JAVA the platform independent language.

2. Protects users from malicious programs.

3. Generate the compiled code which is smaller in size.

*Byte code is an intermediary language between Java source and the host system.

A brief explanation:

JVMArchitectureMostly compiler produce code for a particular Operating system but Java compiler produce code for a virtual machine. Other languages like C, C++ etc compiles the source code into the machine code (for one specific type of machine). Which means you write code once, but you would have to compile the code first on the machine (operating System) where you want to run it.
Java’s compiler will convert the source code into the byte code and then JVM will convert the byte code to machine code on any specific Operating system. This makes Java a platform independent language (you write code once and run it anywhere).

Let’s see how JVM works:

Firstly we write the simple java program(source code), the java compiler converts the source code into the bytecode , after that JVM reads this bytecode and converts this into the machine code.

JVM

JVM is a part of Java Run Time Environment(JRE). And, every operating System requires a seperate JRE.

 The Lifetime of a Java Virtual Machine:

A runtime instance of the Java virtual machine has a clear mission in life: to run one Java application. When a Java application starts, a runtime instance is born. When the application completes, the instance dies. If you start three Java applications at the same time, on the same computer, using the same concrete implementation, you’ll get three Java virtual machine instances. Each Java application runs inside its own Java virtual machine.

 Some worth knowing points about JVM:

1. The Java virtual machine knows nothing of the Java programming language, only
of a particular binary format, the class file format. A class file contains Java
virtual machine instructions (or bytecodes) and a symbol table, as well as other
ancillary information.

2. For the sake of security, the Java virtual machine imposes strong syntactic and
structural constraints on the code in a class file. However, any language with
functionality that can be expressed in terms of a valid class file can be hosted by
the Java virtual machine.