Language Translator

Java Virtual Machine

Java Virtual Machine (JVM) is a virtual computer, typically implemented in software on top of a "real" hardware platform and operating system that runs compiled Java programs.

All Java programs are compiled for the JVM. Therefore, the JVM must be implemented on a particular platform before compiled Java programs will run on that platform.

The JVM executes Java bytecodes, so Java bytecodes can be thought of as the machine language of the JVM.

Role of JVM in making Java portable, How?

The JVM plays a central role in making Java portable. It provides a layer of abstraction between the compiled Java program and the underlying hardware platform and operating system. The JVM is central to Java's portability because compiled Java programs run on the JVM, independent of whatever may be underneath a particular JVM implementation.

Various parts of a JVM?

The "virtual hardware" of the Java Virtual Machine can be divided into four basic parts:

1. The Registers
2. The Stack
3. The garbage-collected Heap
4. The Method Area.

These parts are abstract, just like the machine they compose, but they must exist in some form in every JVM implementation. The size of an address in the JVM is 32 bits. The JVM can, therefore, address up to 4 gigabytes (2 to the power of 32) of memory, with each memory location containing one byte. Each register in the JVM stores one 32-bit address. The stack, the garbage-collected heap, and the method area reside somewhere within the 4 gigabytes of addressable memory. The exact location of these memory areas is a decision of the implementer of each particular JVM.

Various data types provided by JVM?

A word in the Java Virtual Machine is 32 bits. The JVM has a small number of primitive data types: byte (8 bits), short (16 bits), int (32 bits), long (64 bits), float (32 bits), double (64 bits), and char (16 bits). With the exception of char, which is an unsigned Unicode character, all the numeric types are signed. These types conveniently map to the types available to the Java programmer. One other primitive type is the object handle, which is a 32-bit address that refers to an object on the heap.

Use of the Stack in JVM?

The Java stack is used to store parameters for and results of bytecode instructions, to pass parameters to and return values from methods, and to keep the state of each method invocation. The state of a method invocation is called its stack frame. All the local variables being used by the current method invocation are also stored in the stack.

Use of the Heap in JVM?

The heap is where the objects of a Java program live. Any time you allocate memory with the new operator; that memory comes from the heap. The Java language doesn't allow you to free allocated memory directly. Instead, the runtime environment keeps track of the references to each object on the heap, and automatically frees the memory occupied by objects that are no longer referenced -- a process called garbage collection.

Method Area in JVM?

The method area is where the bytecodes reside.

No comments:

Post a Comment