Today I came by 9.00.Today I learned What is a Compiler and Interpreter.
*Compiler *
Definition: Converts the whole program into machine code at once.
Example:
Java compiler (javac) translates .java file into .class file (bytecode).
Advantage
Fast execution after compilation.
Disadvantage
If there is any error, you can see it only after compilation.
Interpreter
Definition: Translates code line by line at runtime.
In Java, the JVM (Java Virtual Machine) works as an interpreter. It executes bytecode line by line.
Advantage: Easy debugging.
Disadvantage: Slower than compiler.
*Java Execution Process
Step 1: You write a program → Hello.java.
Step 2: Compiler (javac) → Converts into Hello.class (bytecode).
Step 3: Interpreter (java) → JVM executes bytecode line by line.
Java Code → Compiler → Bytecode → JVM (Interpreter) → Output
*Key Differences
Feature Compiler Interpreter
Translation Whole program at once Line by line
Speed Fast after compilation Slower
Error check After compilation As soon as error occurs
Example in Java javac JVM
*Conclusion
Wrap up with a simple line:
"In Java, both compiler and interpreter work together. Compiler converts code into bytecode, and JVM interpreter it to give the final output
Top comments (0)