
Compiler:
- A compiler is a software tool that takes source code as input.
- It reads the entire source code at once, checks for syntactical errors, and if no errors are found, it generates an intermediate file called bytecode.
- If there are syntax errors, it throws a compile-time error and halts the compilation.
- Since it processes the whole code at once, it displays all syntax errors together.
Bytecode:
- Bytecode is an intermediate, platform-independent code generated by the compiler when the source code is free of syntax errors.
- It acts as a bridge between the source code and the machine code.
- In Java, the bytecode file has a
.class extension.
- Bytecode is not directly executed by the machine; instead, it requires an interpreter or Virtual Machine (like the Java Virtual Machine - JVM) for execution.
Interpreter:
- An interpreter reads and executes the bytecode line by line.
- It checks for logical errors during execution and throws runtime errors if found.
- If an error occurs, the interpreter halts execution immediately, showing one error at a time.
- Since it processes code sequentially, it is generally slower than a compiler.
✅ Difference Between Compiler and Interpreter: