Sunday, July 12, 2009

Java Virtual Machine

The Java Virtual Machine (JVM) is an idealized computer that sits between your running Java program and the native OS. It is the technology that enables Java programs to be written once and run anywhere.

Unlike programs written in typical programming languages such as C or C++, Java programs are not compiled into native machine code, that is code that specific only to the processor in your computer and can only run on it. Instead, they are compiled into bytecode, which can be described as the "machine" code for the JVM. As long as the JVM is available on your hardware, be it a full-fledge PC or a mobile phone, your Java program can run there. (Note: Mobile devices currently run a specialized version of the JVM with reduced capabilities, hence Java programs have to be written carefully to ensure that only supported libraries are used.)

It is notable that Microsoft suite of .NET programming languages also run on top of a virtual machine.

Launching the JVM

The JVM is part of both the Java 2 SDK and the JRE distributions. It is executed as a precursor to running your Java program when you execute the java or javaw command:

java -classpath classpath YourMainClass


The difference between java and javaw is that java prints output to the console window and javaw does not. (In earlier incarnation of the JRE distribution, there is also a jre command that is essentially the same as the java command. It was eliminated to avoid confusion.)

History

Java is the not first language or programming environment that makes use of the idea of a virtual machine. In the 1970s, UCSD developed the p-System, which is a virtual machine capable of running on multiple microcomputers of the day, thus enabling Pascal programs written for it to run on multiple systems.

Difference from System VM

It is important to note that while JVM shares some characteristics with Virtual Machines (including the name), they are not the same and do not share the same goals. System VMs (such as VMware) sought to emulate the hardware and can host an entire operating system unlike the JVM, which is meant primarily to interpret bytecodes and execute them.

References
  1. P-Code Machine, Wikipedia.
  2. Virtual Machine, Wikipedia.
  3. Java ME at a Glance, Sun Microsystems.
  4. Patrick Niemeyer and Jonathan Knudsen, Learning Java, 3rd ed., O'Reilly (2005), Chapter 1.


No comments:

Post a Comment