The JVM (Java Virtual Machine) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. It is an abstraction of an underlying, actual machine, such as the server that a program is running on. The JVM has two primary functions: to allow Java programs to run on any device or operating system, known as the "write once, run anywhere" principle, and to manage and optimize program memory.
The JVM is detailed by a specification that formally describes what is required in a JVM implementation. A class file contains Java Virtual Machine instructions (Java byte code) and a symbol table, as well as other ancillary information. The class file format is the hardware- and operating system-independent binary format used to represent compiled classes and interfaces.
JVM languages are any languages with functionality that can be expressed in terms of a valid class file which can be hosted by the Java Virtual Machine. A notable feature of JVM languages is that they are compatible with each other, so that, for example, Scala libraries can be used with Java programs.
The JVM performs the following operations:
- Classloading
- Bytecode Verification
- Execution
- Memory Management and Garbage Collection
The JVM is specifically responsible for converting bytecode to machine-specific code and is necessary in both JDK and JRE.