Java Virtual Machine

This lesson describes the Java Virtual Machine and introduces interview questions related to it.

Question # 1

What is the Java Virtual Machine or JVM?

The Java virtual machine is an implementation of a specification, detailing the behavior expected of a JVM. Any implementation that conforms to the JVM specification should be able to run code compiled into Java bytecode irrespective of the language in which the code was originally written. The Java Virtual Machine is implemented for several different operating systems, like Windows, Mac OS, Linux, IBM mainframes, Solaris etc. Thus, if your Java program can run on a Java Virtual Machine on Windows, it can normally also run on a Java Virtual Machine on Mac OS or Linux. Note that the JVM is a program itself that can be invoked on the command line and instructed to execute a file containing java bytecode.

In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes — the machine language of the Java Virtual Machine. The java launcher tool then runs your application with an instance of the Java Virtual Machine.

The JVM is by definition a virtual machine or an abstract computer, i. e. a software machine that simulates what a real machine does. Like a real machine, it has an instruction set, a virtual computer architecture and an execution model. It is capable of running code written with this virtual instruction set, pretty much like a real machine can run machine code.

In practice, JRE is the implementation of the Java Virtual Machine. The JRE contains the JVM and java binaries and other classes to execute any program successfully.

Question # 2

Describe JVM architecture?

The Java Virtual Machine consists of three components:

  • Class Loader Subsystem: The part of a Java virtual machine implementation that takes care of finding and loading types is called the class loader subsystem. The class loader subsystem is responsible for more than just locating and importing the binary data for classes. It must also verify the correctness of imported classes, allocate and initialize memory for class ...

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.