Wednesday, July 20, 2005

JVM-I

All computation in the JVM centers on the stack. Because the JVM has no registers for storing arbitrary values, everything must be pushed onto the stack before it can be used in a calculation.
A static Java compiler converts Java source code into a verifiably secure and compact architecture-neutral intermediate format, called Java byte codes. At runtime, the Java Virtual Machine (JVM) can either interpret the Java byte codes or translated into native code by Java Just-In-Time (JIT) compiler to improve the runtime performance.

JIT
The JIT compiler is contained within the JVM. The JIT compiler uses method-by-method translation; that is, it translates each method as it is loaded, rather than translating an entire class. When the JVM runs in interpreter mode (without the JIT compiler), it works directly with the Java bytecode, interpreting each instruction at run time.
When the JVM runs in JIT compiler mode (with the JIT compiler), the JIT compiler translates Java bytecode to native instructions and then the JVM then executes those instructions. During a single run of the Java interpreter, the JVM can use the same method multiple times, but the JIT compiler translates that method only once. After the JIT compiler translates a method, the JVM uses the method's native code instead of Java bytecode.

Bytecodes
Bytecodes are the machine language of the Java virtual machine. When a JVM loads a class file, it gets one stream of bytecodes for each method in the class. The bytecodes streams are stored in the method area of the JVM. The bytecodes for a method are executed when that method is invoked during the course of running the program. Intepretation, just-in-time compiling, or any other technique that was chosen by the designer of a particular JVM could execute it. A method's bytecode stream is a sequence of instructions for the Java virtual machine. Each instruction consists of a one-byte opcode followed by zero or more operands. The opcode indicates the action to take. If more information is required before the JVM can take the action, that information is encoded into one or more operands that immediately follow the opcode.

Wednesday, July 13, 2005

Platform Independence

Platform Independence

Java is created to develop network application. OO concept taken from C++ as a reduced subset of what was available in C++ and some restriction are being placed on some of OO concept like multiple inheritance. Since Java was created for networking application it have to be supported on many different platform, that’s where Java stand different than other programming languages.
Compiler being used to interpret the language semantic and syntax, and then converting it to executable form of that specified machine (here machine is used in context of hardware and OS running on it). But the problem lies here only that compiler can generate OS specific executables and compilers working on different machine has different specification (not major differences such as in MSWindows C you can use clrscr() to clear screen but in Linux C this function is not available etc) to follow, that make impossible to run one code developed on one machine to work on different machine without some modification.
Sun developed a Virtual Machine known as Java VM. This resides between java code and underlying machine. Whenever user want to compile and run a java code, the code passed to JVM which then compiles the code and convert it into byte code which can be used on any other machine. JVM create virtual OS for running executable code.
JVM also developed for many available machines, if it is available on the machine user can run any java code on that machine without any hesitation. JVM pretend java code that it running with the same machine without any modification. That is truly platform independence but needs JVM. So it is true ‘Write once run anywhere’.
DotNet come up with concept CLR ie. Common Language Runtime which specifically state that ‘Write in any language and run on one platform’, that gives us language independence (here language means that follows CLS ie. Common Language Specification).
This is one of the reason for people to use Java than any other language in the world.