THE BYTECODE
Bytecode is the product of the compilation phase in Java. The JVM is a virtual, software-described representation of a real computer. The JVM has a machine instruction set, like a regular CPU. The instruction set recognized by the JVM is called Bytecode. There are 256 instructions in the Java Virtual Machine in all, and each of these instructions occupies one byte. Hence the name Bytecode. Compiling a Java source using the Javac command produces a file with a .class extension that contains the Bytecode.

To touch on what Bytecode actually looks like let’s create a folder TestBytecode and open it in Visual Studio Code. We write the code shown in the figure. We use the javac command, as seen in the program terminal, to create the .class file and the java command to run the program.

Now we open a terminal by locating in the directory that contains the .class file and type the following command:
javap TestByteCode

This command tells us what source the file was compiled from, it has a constructor and two methods main and Denominazione with their respective parameters. In short, from the .class file we go back to the structure of the program. Let us now see how it is possible to see the machine instruction set.
We give the command
javap -c TestByteCode

THE JAVA VIRTUAL MACHINE
We will see what actually happens when we bring a program written in Java into execution.


When we put a program into execution via the java nameclass the first component that runs in the JVM is the Class Loader. This component locates the Bytecode of our executable class and loads it into memory, it also loads all references to other .class files.
THE JIT COMPILER
Once the Class Loader has loaded all the Bytecode, that of our executable class and all its reference classes, it switches to another component, the Bytecode Verifier. The task of this component is to verify the Bytecode from suspicious alterations that could compromise the security of the software. When finished, the JIT compiler performs the transformation of the bytecode into the machine code of the particular underlying platform. The JIT compiles, greatly simplifying, one method at a time and only the first time it is invoked so that subsequent invocations if it has not been modified do not have to be recompiled. The JIT compiler allows for high performance of our Java programs.



Leave A Comment