From the course: Nail Your Java Interview

What's the Java Virtual Machine? - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

What's the Java Virtual Machine?

- [Instructor] In an interview you might be asked about the underlying technology that makes a Java program work. One of these technologies is the JVM or the Java Virtual Machine. Java was designed for developers to make applications that could be run on any machine that supported Java without having to be rewritten or recompiled by the programmer. This is a develop once or compile once run anywhere ideology. When Java code is compiled it is compiled into Java bytecode. The Java Virtual Machine runs the bytecode and in turn runs your Java program. The JVM can run this same bytecode on any machine that supports the JVM because the Java Virtual Machine is aware of the particularities on the low level of each machine type. Now, in order for the Java virtual Machine to work, it has to be run on a given platform, think Mac or windows, according to the Java Virtual Machine specification. The JVM specification defines an abstract that can be mapped to any platform rather than a specific implementation for a real machine or processor. It defines an abstract for a virtual machine that runs on your computer. This specification describes a set of instructions, a set of registers, and more. Once the specification has been implemented for a given platform and the Java virtual machine has been installed as a part of your runtime environment, any Java program can run on that machine. Ultimately, the Java Virtual Machine provides a platform-independent way of executing code by abstracting the differences between operating systems and CPU architectures. With this in mind, no JVM implementation is the same and it tends to not have major effects on your programs because the power of Java comes from its OS and architecture obstruction. In short, the Java Virtual Machine is what allows Java to be run on many different platforms without being recompiled or rewritten.

Contents