Java is not purely a traditional compiled or interpreted language, but tries to come in between them.
In Java, source code is saved in files with .java extensions. This source code is then compiled into a intermediate platform independent byte code, and this form has a .class extension. This .class file is then executed by Java’s JVM.
Java’s JVM execute an optimized platform independent binary bytecode (the .class files), not the high level source code. So the execution will be clearly faster than a regular interpreter that interprets the source code.
Java can compile the bytecode again to platform specific binary with additional optimizations during execution. This called Just-In-Time compilation as compilation occurs during execution.
JVM will not compile the whole bytecode at first, but will wait to see the code run, and then compile some sections of the code that is executed frequently and execute some sections of code that is less frequent, without compiling.
There are multiple implementations of JVM. Oracle itself provides open source and commercial JVM versions. IBM also provides its own JVM along with its products.
Oracle’s standard JVM implementation (that we download from oracle downloads page) is known as Hotspot JVM.
Hotspots are sections of code that are executed more than other sections of code.
When the JVM executes code, it does not begin compiling the code immediately. It would not be worth to compile and execute a section of code which is executed only once or very less times; instead it would be better to interpret the bytecode directly without compiling in those cases. Compiling a frequently executing section of code (hotspot) will be worth as the extra CPU cycle time taken for compilation can be overcome during subsequent runs. Also, more the JVM executes sections of code it can figure out more optimizations that can be made.
This was a quick introduction to the compiler and JVM in Java and is enough for continuing with other tutorials in this book. Click here if you would like to learn more about JIT compilers.
Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!