Byte Code in Java

Byte Code in Java

Byte Code is the biggest improvement in Java, when compared to other languages like C++. I will discuss what is Byte code and why it is needed, and what is the benefit of using Byte code in Java.

Most of the languages that developers work in face two main problems. They are:-

1. Security
2. Portability

Security
We all know that, while downloading any file from anywhere on the internet, we face two major problems, they are a viral infection, that is the file may be corrupted with virus. And the second is that the file may contain a spyware that is some malicious code in the file scans your computer for your data. No one likes that, but that's a big reality. 

Portability
We all want that, once we do the coding, we can easily take the output to many other platforms. But the issue is that most of the systems, don't provide compatibility to the previous code. It may be that you are coding on the windows machine and tomorrow you want to run the code on a linux machine, in that case there could be portability issues. Java has the benefit of "code once and use anywhere". I will tell you how.

Java faces both of these threats by a simple means called the Byte code. Byte code is a highly optimized code that runs only on JVM(Java Virtual Machine). The issue of virus and spyware protection is solved by making sure that, everything runs with the JVM environment, and nothing goes out of that, so there is no chance of getting the files infected by virus or spyware. JVM provides a complete shell like environment which encloses all the processing of the Java operations.

The issue of portability is again resolved by using Byte code. Byte code is not the normal executable code, it need the JVM for its operations. So you just need to ensure that JVM is installed on the system on which you are working, and the Byte code will run perfectly fine. So in fact you may code the program once, compile it to convert it into Byte code, and then use the Byte code on any JVM compatible machine. So it is simply "Code once and use anywhere". That's the power of Java.

The Byte code is a highly optimized code which is understood only by the JVM. The JVM is the interpreter of the Byte Code. There could be various versions of JVM operating on various machines, but all interpret the same Byte code, and so it provides a highly cool feature of portability.