Byte Code in Java

  • April 27, 2022
  • Java
method overloading and method overriding
Byte Code:

The Java byte code is a machine instruction for a Java processor chip called Java Virtual Machine. The byte code is independent of the computer system it has to run, i.e, Java programs are compiled, and their byte codes are produced. The byte codes are always the same irrespective of the computer system they are to execute upon.

To understand the byte code, one must be clear about the compilation process.

Ordinary Compilation process:
  • The program or the source code written by a programmer is usually called the source code.
  • This source code needs to be converted into a machine language code, which a computer can easily understand.
  • The process of converting a source code into machine language code is called compilation.
  • The converted machine code depends a lot on the platform it is executing upon, i.e, the resultant machine code is called native executable code.
  • Instead of using a compiler, one can use an interpreter, which translates the code instruction-by-instruction.

here, the first diagram is the ordinary compilation process, whereas, the second diagram represents Java compilation producing the bytecode.

Java Compilation:
  • Contrary to ordinary compilation, the Java compiler does not produce native executable code for a particular machine. Instead, it produces a special format called byte code.
  • The Java byte code looks a lot like machine language, but unlike machine language, Java byte code is the same on every platform.
  • However, the Java programs that have been compiled into byte code still need an interpreter to execute them on any given platform.
  • The interpreter reads the byte code and translates it into the native language of the host machine.
  • Since byte code is completely platform-independent, only a few native libraries need to be ported t get Java to run on a new computer or operating system.

Note: also read about the Setting CLASSPATH in Java

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Leave a Reply

Your email address will not be published. Required fields are marked *