Saturday, July 11, 2015

JVM Understanding

à  Bytecode is a special machine language that can be understood by the Java Virtual Machine (JVM) independent of any particular computer hardware, so any computer with a Java interpreter can execute the compiled Java program, no matter what type of computer the program was compiled on. Java Virtual Machine (JVM) can now be understood

à All languages compiler translate source code into machine code for a specific computer. Java
compiler also does the same thing. Then how does java achieve architecture neutrality? The
answer is that the java compiler produces an intermediate code known as bytecode for a machine that physically does not exist, this so called virtual machine is known as the java virtual machine (JVM) & it exists only inside the computer memory. The machine language for the java virtual machine is called java bytecode.

à The process of compiling a java program into bytecode which is also referred to as virtual
machine code is not machine specific. The machine specific code generated by the java
interpreter by acting as intermediary between the virtual machine & the real machine as given in
following fig. the interpreter is different for different machine.

àJava bytecode can run on any computer that has an interpreter this is one of the essential features of java: the same compiled program can be run on many different types of computer but JVM must be installed.

àA Java Virtual Machine (JVM) is a set of computer software programs and data structures that use a virtual machine model for the execution of other computer programs and scripts. The model used by a JVM accepts a form of computer intermediate language commonly referred to as Java bytecode. This language conceptually represents the instruction set of a stack-oriented, capability architecture. As of 2006, there are were estimated four billion JVM-enabled devices worldwide.

Overview of JVM:

àJava Virtual Machines operate on Java bytecode, which is normally (but not necessarily) generated from Java source code; a JVM can also be used to implement programming languages other than Java. For example, a source code can be compiled to Java bytecode, which may then be executed by a JVM. JVMs can also be released by other companies besides Sun (the developer of Java) — JVMs using the "Java" trademark may be developed by other companies as long as they adhere to the JVM specification published by Sun (and related contractual obligations).

àThe JVM is a crucial component of the Java Platform. Because JVMs are available for many
hardware and software platforms, Java can be both middleware and a platform in its own right -
hence the trademark write once, run anywhere. The use of the same bytecode for all platforms
allows Java to be described as "compile once, run anywhere", as opposed to "write once,  compile anywhere", which describes cross-platform compiled languages. The JVM also enables such features as Automated Exception Handling that provides 'root-cause' debugging information for every software error (exception) independent of the source code.

àThe JVM is distributed along with a set of standard class libraries that implement the
Java API (Application Programming Interface). An application programming interface is what a
computer system, library or application provides in order to allow data exchange between them.
They are bundled together as the Java Runtime Environment.

Execution environment

Programs intended to run on a JVM must be compiled into a standardized portable binary format, which typically comes in the form of .class files. A program may consist of many classes in different files. For easier distribution of large programs, multiple class files may be packaged together in a .jar file (short for Java archive).

The JVM runtime executes .class or .jar files, emulating the JVM instruction set by interpreting it, or using a just-in-time compiler (JIT) such as Sun's Hotspot. JIT compiling, not interpreting, is used in most JVMs today to achieve greater speed. Ahead-of-time compilers that enable the developer to precompile class files into native code for a particular platforms also exist.
Like most virtual machines, the Java Virtual Machine has a stack-based architecture akin to a

microcontroller/microprocessor. The JVM, which is the instance of the JRE (Java Runtime Environment), comes into action when a Java program is executed. When execution is complete, this instance is garbage-collected. JIT is the part of the JVM that is used to speed up the execution time. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.

No comments:

Post a Comment