Share this article on

As with many other programming languages, Java uses a compiler to convert human-readable source code into executable programs. Traditional compilers produce code that can be executed by specific hardware; for example, a Windows 95 C++ compiler creates executable programs that work with Intel x86–compatible processors. In contrast, the Java compiler generates architecture-independent bytecodes. The bytecodes can be executed by only a Java Virtual Machine (VM), which is an idealized Java architecture, usually implemented in software rather than hardware.To execute Java bytecodes, the VM uses a class loader to fetch the bytecodes from a disk or a network. Each class file is fed to a bytecode verifier that ensures the class is formatted correctly and will not corrupt memory when it is executed. The byte-code verification phase adds to the time it takes to load a class, but it actually allows the program to run faster because the class verification is performed only once, not continuously as the program runs.The execution unit of the VM carries out the instructions specified in the byte-codes. The simplest execution unit is an interpreter, which is a program that reads the bytecodes, interprets their meaning, and then performs the associated function. Interpreters are generally much slower than native code compilers because they continuously need to look up the meaning of each bytecode during execution. Fortunately, there is an elegant alternative to interpreting code, called Just-in-Time (JIT) compilation.The JIT compiler converts the bytecodes to native code instructions on the user’s machine immediately before execution. Traditional native code compilers run on the developer’s machine, are used by programmers, and produce nonportable executables. JIT compilers run on the user’s machine and are transparent to the user; the resulting native code instructions do not need to be ported because they are already at their destination. Figure 1.5 illustrates how JIT compilers work. In the example, both a Macintosh and a Windows PC receive identical bytecodes, and each client performs a local JIT compilation

Share this article on

One Reply to “How java work”

  1. Prahlad tu kha chala gya mere bhai teri boht yad aati –antivirus—mujhe virus boht tang kar rhe h

Comments are closed.