Difference between compiler and interpreter


What's the difference between a compiler and an interpreter? Can a programming language have both a compiler and an interpreter?


To clarify the difference, let's find out what it is:

Compiler – a program or hardware that performs compilation.

Compilation – translation of a program written in a high-level source language into an equivalent program in a low-level language close to machine code (absolute code, object module, sometimes into assembly language). The input information for the compiler (source code) is a description of the algorithm or a program in a domain-specific language, and the output of the compiler is an equivalent description of the algorithm in a machine-oriented language (object code). Wikipedia

An interpreter is a program (a kind of translator) that performs interpretation.

Interpretation is a statement-by-statement (command-by-command, line-by-line) analysis, processing and then immediately executing the original program or request (as opposed to compilation, in which the program is translated without executing it). Wikipedia

Thus, we can conclude that the compiler converts the source code to close to machine code. The interpreter, on the other hand, allows you to perform some representation of the program, converting it into machine code on the fly.

If you take the java language, then it has both a compiler and an interpreter. The compiler converts the source code to bytecode. And the bytecode at the initial stage of program execution is processed by the interpreter.

The compiler is a separate javac program, the interpreter is built into jvm . In addition to the usual compiler, jvm has just-in-time compilation. since interpretation is rather slow, then hot spots in the program are compiled into machine code by the jit compiler, thereby speeding up the execution.

Scroll to Top