The processes involved between the moment you write a program to the moment you execute it, is not as straightforward as one would expect. Here, in this post, we will try unwinding it a little bit.
Suppose you wrote some java program say, JCombat.java, which means that it if it contains any public class, the name of the class would definitely be, JCombat.
Okay, now the following steps are involved to make a java program finally run:
- There is a java compiler, javac, that converts the java source code into something called Bytecode, into files having the extensions as ‘.class‘.
- To make sure that the java compiler and java commands are properly accessible, you need to set the environment variable ‘JAVA_HOME‘, by navigating to the ‘Advanced system settings‘ from your computer as shown:
- Different JVM (Java Virtual Machine) are available for different platforms, like Windows, Linux, Mac and so on. Each of these JVM take the very same class file containing the bytecodes as the input.
- JVM could convert these bytecodes to the machine specific code, but it won’t, since the process would be extensively slower. The option to dynamically compile only the code segment that needs to run would be a wonderful idea and it is.
- This is exactly when the JIT Compiler (just-in-time compiler) comes into the picture next and compiles the needed bytecodes to the platform specific executable code or the native code.
- JIT Compiler runs on the user’s machine and is transparent to the user. Eventually, this is how a java code finally executes.
Trying to put this into some diagrammatic notation:
Kindly post in your queries as comments to this post.