SelfTechy

A portal for self learning

Monthly Archives: November 2013

Introduction to Java Virtual Machine (JVM)


Consider any system, it should be hiding complexity from the user, be it a programming language or any computer solution. This makes the user happy which is the goal of any application. Virtualization is a concept in computer science engineering which means creating virtual resources such as hardware, operating system, etc on top of the actual hardware. There are platforms such as VMWare or Citrix which completely abstracts the actual hardware from the user and creates virtual machines. User does not actually feel the difference due to virtualization.

Can we relate these virtual machines to Java Virtual Machine (JVM)? Let us discuss this in detail. A Java programmer develops the code without worrying about the Operating system or the hardware on which it is going to be executed. This is achieved using Java Virtual Machine. A Java program is compiled to create an intermediate level code called bytecode (CLASS file). Bytecode is executed by the execution engine of JVM. High level languages like C, C++ are used to write human readable programs which are converted to machine understandable code through the compilers. But this executable code will be platform specific. JVM runs every Java CLASS file in a virtual environment where the bytecode is interpreted into machine instructions using Interpreter or Just-in-time compiler. Hence, the Java became an platform independent language. Java provides platform specific JRE’s (Java Runtime Environment) which need to be installed on the operating system (download Java).

JVM consists of,

  1. Class loader subsystem
  2. Runtime data areas
    • Method area
    • Heap
    • Java Stacks
    • Native method stacks
    • PC Register
  3. Execution Engine
  4. Native method interface and libraries

How JVM executes a Java program?
———————————-
1. Class loader subsystem loads the CLASS files and the essential Java.lang packages.
2. Constants, methods, access modifiers, variables, etc are loaded into runtime data areas.
3. Locates "public static void main(string [] args)" method and starts execution
4. Execution engine executes the bytecode consisting opcode. JIT (Just-In-Time) compiler compiles these opcodes to machine understandable code and will be executed by the execution engine.

Here, I have made an attempt to make the reader just to have a basic understanding of what is the role of JVM in Java. Of course this can be elaborated much more. For more information kindly refer to an excellent book "Inside the Java 2 Virtual Machine" written by Bill Venners.