The semantics of constructs in Java language are defined by the Java language specification, but they're not in terms of JVM instructions. So, is there possiblity that the specification is not strictly defined to prevent mis-implementation of Java compilers? Or the mapping between Java language and JVM instructions is pretty straightforward, there's no need to worry about this?
In Java, programs are not compiled into executable files; they are compiled into bytecode (as discussed earlier), which the JVM (Java Virtual Machine) then executes at runtime. Java source code is compiled into bytecode when we use the javac compiler. The bytecode gets saved on the disk with the file extension .
A Java Virtual Machine instruction consists of a one-byte opcode specifying the operation to be performed, followed by zero or more operands supplying arguments or data that are used by the operation. Many instructions have no operands and consist only of an opcode.
Java Virtual Machine (JVM) is a engine that provides runtime environment to drive the Java Code or applications. It converts Java bytecode into machines language. JVM is a part of Java Runtime Environment (JRE). In other programming languages, the compiler produces machine code for a particular system.
Like all other virtual machines, JVM has an instruction set. There are nearly 255 instructions in this set, however you will not be dealing with all of them. JVM takes "class" files as input. Class files are binary files, so it is not an easy job to write a class file from scratch.
It would defeat much of the point of separating the language from the bytecode for there to be a clear mapping of Java code to JVM instructions. Instead the compiler has the freedom to make determinations of which instructions best represent the provided source, in order to optimize the efficiency of what's actually run.
This does mean it's possible for a compiler to do the wrong thing, however generally speaking you can trust major compilers like Oracle's are doing the right thing; they get tested a lot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With