In this tutorial, we will learn about how a java program works, what is compiler and interpreter and how codes are executed in java programming language.
How Does Java Programming Language Work?
Steps involved to write and execute a java program
- First, we should have a java source code which must be saved with program.java extension.
- Then we use a JAVA Compiler to compile the source code to get java bytecode which must have a program.class extension. We can say that Java bytecode is a modified version of java source code.
- Now we pass the java bytecode through an interpreter called JVM (JAVA Virtual Machine) which will read every single statement at a time from java bytecode and convert it to machine level code and then will execute the code. We get the output only after JVM converts and execute the code.
Note: JAVA has platform specified JVM interpreter such specified JVM for Linux, Windows, Macintosh which allow us to execute java programs at various platform easily.
Executing JAVA Program
As we know the computer cannot understand human languages they only understand the codes in binary form i.e. 0 & 1.
A program we write in high-level programming languages such as C++ and JAVA is called source program or source code which our computers don’t understand therefore the source code or source program we write in Java must be converted into the binary form which our computers should understand and execute.
The translation of the source code into binary or machine code can be done using a programming tool called interpreter or compiler.
A compiler is a tool which converts the entire source code into machine code or any other intermediate code which our statement of the source code.
An interpreter is also a programming tool like compilers which converts the source code into machine code but interpreter works differently than a compiler. Interpreter only converts one statement of source code at a time and execute it right away. It doesn’t need executor to execute the program. The same process is followed for every other statement of the source code.