How the JVM works
At the core, the JVM sits between your Java bytecode and your computer. As illustrated next, we develop our Java source code in an IDE, and our work is saved as .java
files. We use the Java compiler to convert our Java source code to bytecode; the resulting files are .class
files. We then use the JVM to run our bytecode on our computer:
Figure 1.1 – Java application workflow
It is important to realize that Java is different from typical compile-and-execute languages where source code is fed into a compiler, which then produces a .exe
file (for Windows), a .app
file (for (macOS), or ELF
files (for Linux). This impressive process is much more complex than it seems.
Let’s take a closer look at what is going on with regard to the JVM, using a basic example. In the following code, we implement a simple loop that prints to the console. It is presented so that we can see how the JVM handles Java code:
// Chapter1 // Example...