Java Virtual Machine
- A Java compiler produces a binary file called a class file which contains the bytecode for a Java program. The Java virtual machine loads one or more class files and executes programs contained in them. To achieve it, the JVM requires the support of the class loader, which locates a required class file, and a bytecode verifier, which ensures that execution of the bytecode would not cause any breaches of security.
- The Java virtual machine is a stack machine. By contrast, a stack machine performs computations by using the values existing in the top few entries on a stack and leaving their results on the stack. This arrangement requires that a program should load the values on which. It wishes to operate on the stack before performing operations on them and should take their results from the stack.
The stack machine has the following three kinds of operations
Push operation: This operation has one operand, which is the address of a memory location. The operation creates a new entry at the top of the stack. And copies the value that is contained in the specified memory location into this entry.
Pop operation: This operation also has the address of a memory location as its operand. It performs the converse of the push operation—it copies the value contained in the entry. That is at the top of the stack into the specified memory location and also deletes that entry from the stack.
n-ary operation: This operation operates on the values existing in the top n entries of the stack. deletes the top n entries from the stack, and leaves the result, if any, in the top entry of the stack. Thus, a unary operation operates only on the value contained in the top entry of the stack. A binary operation operates on values contained in the top two entries of the stack, etc.
A stack machine can evaluate expressions very efficiently. Because partial results need not be stored in memory—they can be simply left on the stack.