In today’s topic, we are discourse about the compiler, how the compiler works, and what is java compiler is. So let discourse one by one
Execution of Programs
Computers can only understand the code in binary form.
The program written in a high-level language is also known as a source code.
The computer cannot understand a source code (which is written by the programmer), the source code must be translated into machine-level code for execution, The translation can be done using the help interpreter or a compiler (the compiler and interpreter are basically software or a program of code).
What is a compiler?
In programming, a compiler is a computer program or software that translates computer code written in one programming language into another language. The compiler translates the entire source code into a machine code file and is then executed.
What is an Interpreter?
An interpreter reads one statement from the source code, the interpreter executes the source code one line once a time and converts it to the machine-level language, and executes it in the right way.
How does the compiler work?
Programming languages were developed to allow developers to write human-like code.
But the computer does not understand the human source code it only understands the machine cord.
Thus, compilers translate the source code to machine code dedicated to a specific machine.
The compiler works with the following steps
1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Intermediate code generation
6. Code generation
Is java has a compiler or interpreter?
The java programming language is a hybrid language.
So java takes both java compiler as well as java interpreters.
In java, the source code first converted to byte code with the help of the java compiler
Then with the help of an interpreter, it is executed.
To execute a java program. So fast we are having the java source code.
The java source code will be saved with the extension of .java and then we use the java compiler.
By the java compiler, we compile the code and get the java byte code.
The java byte code has the .class extension so this java byte code is a modified version or you know the optimized version of the java source code.
After that, we pass the java byte code to the java virtual machine or JVM which is an interpreter.
It is an interpreter so it read one statement at a time from this java byte code and converts that to the machine-level code and it’s gonna execute that.
So we get the output after executing our program by our java interpreter or we know the java virtual machine.