Categories: Java

Byte Code in Java

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

Share
Published by
Rabecca Fatima

Recent Posts

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

1 month ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

1 month ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

2 months ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

2 months ago

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

2 months ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

3 months ago