For short, Java bytecode is an instruction set for JVM. For long keep reading...
Java program execution uses 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 (JVM). The machine language for the Java virtual machine is called Java bytecode. Being simpler Java bytecode is machine code in form of
.class file. This
.class file is executed by JVM to produce output. Java's intermediate compiled bytecode makes Java a platform independent language, and this is one of the main selling points of Java. Once the bytecode is generated, it can be run on any platform by Java Virtual Machine (JVM). Of course, a different Java bytecode interpreter is needed for each type of platform.
Java program execution is a two step process. In the first step Java compiler (
javac) executes Java source code (file having extension
.java)and produces the Java bytecode in form of
.class file. In second step Java interpreter (Java virtual machine or JVM) executes
.class file or Java bytecode. Java 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 Java bytecode.
Translating a Java program into bytecode helps makes it much easier to run a program in a wide variety of environments. The reason, as said earlier, 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. Remember, although the details of the JVM will differ from platform to platform, all interpret the same Java bytecode. This is the write once, run anywhere slogan given by Sun Microsystems to illustrate the cross-platform benefits of the Java language. On the contrary, if a Java program were compiled to native code, then different versions of the same program would have to exist for each type of CPU connected to the Internet. This is, of course, not a feasible solution. Thus, the interpretation of bytecode is the easiest way to create truly portable programs.
Hope you have enjoyed reading about Java bytecode or .class file. Please do write us if you have any suggestion/comment or come across any error on this page. Thanks for reading!
Researchers say the WannaCry ransom note was poorly translated - possibly using Google Translate.BA boss 'won't resign' over flight chaosPosted on Monday May 29, 2017
Chief executive Alex Cruz says flight disruption at Heathrow and Gatwick had nothing to do with cost cutting.Hay Festival 2017: Stephen Fry's warning for the webPosted on Sunday May 28, 2017
Delivering a lecture at the Hay Festival, the actor said society could face "dire consequences".Courtesy BBC News