The Java Virtual Machine

The Java Virtual Machine

Machine language consists of very simple instructions that can be executed directly by the CPU of a computer. Almost all programs, though, are written in high-level programming languages such as java, or C++. A program written in a high-level language cannot be run directly on any computer. First, it has to be translated into machine language. This translation can be done by a program called a complier. A compiler takes a high-level-language program. Once the translation is done, the machine-language program can be run any number of times, but of course it can only be run on one type of computer if the program is to run on another type of computer it has to be re-translated, using a different computer, into the appropriate machine language. There is an alternative to compiling a high-level language program. Instead of using a compiler, which translates the program all once, you can an interpreter, which translates it instruction-by instruction, as necessary. An interpreter is a program that acts much like a CPU, with a kind of fetch-and-execute cycle.

In order to execute a program, the interpreter runs in a loop in which it repeatedly reads one instruction from the program, decides what is necessary to carry out that instruction, and then performs the appropriate machine-language commands to do so. One use of interpreters is to execute high-level language programs. For example, the programming language Lisp is usually executed by an interpreters rather than a complier: However, interpreters have another purpose: they can let use a machine-language program meant for one type of computer on a completely different type of computer. For example, there is a program called "Virtual PC" that runs on Macintosh computers. Virtual PC is an interpreter that executes machine-language programs written for IBM-PC-clone computers. If you run Virtual PC on your Macintosh, you can run any PC program, including programs written for Windows. The designers of Java chose to use a combination of compilation and interpretation. Programs written in Java are compiled into machine language, but it is a machine language for a computer that doesn't really exist. This so-called "virtual" computer is known as the Java virtual machine. The machine language for the Java virtual machine is called Java byte code could not be used as the machine language of a real computer, rather than a virtual computer.

However one of the main selling points of Java is that it can actually be used on any computer. All that the computer needs is an interpreter for Java byte code. Such an interpreter simulates the Java virtual machine in the same way that Virtual PC simulates a PC computer. Of course, a different Java byte code is needed for each type of computer, but once a computer has a Java byte code interpreter; it can run any Java byte code program. And the same Java byte code program can be run on any computer that has such an interpreter. This is one of the essential features of Java: the same complied program can be run on many different types of computers.

 

 

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.