Skip to main content

Java's Magic (Byte codes)

>

What is JVM? What are Bytecodes (Java’s Magic):

  • JVM is an abbreviation for Java Virtual Machine, which is a set of tools used to execute Java programs. JVM serves as the intermediary between your program and the host computer.
  • Running a java program is a two-step process:
    1. With the compiler, first you translate a program into an intermediate language called Java bytecodes—the platform-independent codes interpreted by the interpreter on the Java platform.
    2. The interpreter parses and runs each Java bytecode instruction on the computer. Compilation happens just once; interpretation occurs each time the program is executed.
    3. Figure: Programs written in the Java programming language are first compiled and then interpreted.
  • Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system, which is called the Java Virtual Machine (JVM). That is, in its standard form, the JVM is an interpreter for bytecode. Java bytecodes are the machine code instructions for the Java Virtual Machine to interpret.
  • Figure: Java source code is translated into bytecode.
  • Java bytecodes help make "write once, run anywhere" (WORA) possible. The program can be compiled into bytecodes on any platform that has a Java compiler. The bytecodes can then be run on any implementation of the Java VM. Bytecodes are the .class files generated after compilation, which provides actual flow for the program. That means that as long as a computer has a Java VM, the same program written in the Java programming language can run on Windows 2000, a Solaris workstation, or on an iMac, as shown in figure below:
    Figure: Programs can be written once and run on almost any platform.
    Translating a Java program into bytecode helps makes it much easier to run a program in a wide variety of environments. The reason is straightforward: only the JVM needs to be implemented for each platform. Once the run-time package exists for a given system, any Java program can run on it.

Comments

Relevant to YOU:

Popular posts from this blog

ASCII Code in Java (Part 1)

> The ASCII Code: (Part 1) ASCII stands for "American Standard Code for Information Interchange". As you may remember (Grade 9), computers only work with HIGH(1) and LOW(0) electrical states, known as bits, with correspond to mathematical Base 2 numbers. That is, computers only understand binary language. ASCII codes represent text (or other things) in computers. Assume that you are working with MS Word, or PPT or any other tool that uses text based inputs from user. You need to type a sentence that computer is not aware of. ASCII codes help to exchange this information between user and computer. When you type a character, it is converted into ASCII code first and then into Binary, which makes the computer understand what is to be typed. Hence every key on the keyboard has a specific ASCII code which is used to make the computer understand our language. If you press 4 from keyboard, then keyboard send the value 100 (value equival...

Characteristics of Java OR Java Buzzwords (Part 2)

> Java Properties: (Part 2) Robust: Java is robust because it is more reliable. It ensures the reliability by providing early checking for possible errors. It eliminates error causing constructs such as pointers. Java restricts the programmers in a few key areas, to force them to find mistakes early in program development. At the same time, Java frees from having to worry about many of the most common causes of programming errors. Because Java is a strictly typed language, it checks the code at compile time. However, it also checks your code at run time. Consider two main reasons of program failure: Memory management mistakes and Mishandled exceptional conditions (run time errors). Memory management is difficult and tedious in c/c++, the programmers have to manually allocate and free memory. This sometimes leads to problems, because programmers will either forget to free memory that has been previously allocated or, worse, try to ...