O'Reilly logo

Java Programming Interviews Exposed by Noel Markham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10

Understanding the Java Virtual Machine

The Java virtual machine (JVM) is the platform upon which your programs run. It is built for that specific operating system and architecture, and sits between the operating system and any compiled programs or applications you write, making it platform agnostic. Java programs are compiled (using javac) into bytecode. This is interpreted by the JVM into the specific instructions for that architecture and operating system.

Other compiled languages such as C++ or Objective-C need to be compiled to run with a defined host architecture and operating system, but this is not the case with Java. Regardless of the platform on which your Java code was compiled, it can run on any JVM of the same or later version.

Considering this is where your code runs, it is important to understand how the JVM works, and how you can tweak certain parameters to obtain optimum performance for your code.

This chapter covers the particulars around the JVM’s memory model, such as how that memory is allocated to your objects, and how the JVM reclaims that memory once you no longer need it. It then reviews the different memory areas and how the JVM uses them. Finally, this chapter looks at certain language hooks to allow executing code to interact with a running JVM.

Garbage Collection

How is memory allocated?

The new keyword allocates memory on the Java heap. The heap is the main pool of memory, accessible to the whole of the application. If there is not ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required