Java Virtual Machine (JVM) works as a layer on the operating system that we use. There are different Java Virtual Machines (JVMs) for different operating systems like Windows, Linux and IOS. Following are the steps that are happening from the time we save a java program until we see an output.
- Save your written java program as a java file using the .java extension. This file is then called as Source File. The code within the Source File is called as Source Code.
- Then enter javac <fileName.java> command which handovers the java file to the java compiler (jcompiler) for future processes. Jcompiler is a software.
- Jcompiler converts the source file into the Class File.
- If jcompiler finds grammar mistakes with the java code, it gives Compile Errors.
- After a successful compilation fileName.class file will be made. The code within this file is named as bytecode. This is the bytecode for the Java Virtual Machine (JVM).
- Then enter java <classFileName> and it will connect the class file with the Java Virtual Machine (JVM). JVM can see our written codes in order through the bytecode.
- Then Java Virtual Machine (JVM) will execute the java code line by line.
- The final output will be delivered after the java program gets connected with the operating system.