Compiler and Interpreter both are translators of programming languages.
What is Compiler?
Compiler is a software that translates source code written in a programming language into another computer language.
It is primarily used to translate the source code or program written in a high-level programming language to a low-level language (e.g., assembly language, object code, or machine code).
There are different types of compilers that produce output in different useful forms –
Cross-Compiler
A cross-compiler is a type of compiler that can produce a program that will run on a computer whose CPU or Operating system is different from the computer on which the program is compiled.
Native Compiler
A program compiled through a native compiler would run on the same type of computer and operating system as the compiler itself.
Decompiler
A program that translates from a low-level language to a higher-level one is a decompiler.
Transpiler (Source-to-source compiler)
A program that translates between high-level languages is called a source to source compiler or transpiler. Example: Typescript transpiler – converts Typescript code to JavaScript.
What is Interpreter?
An interpreter is also a programming language translator, but it works differently than a compiler.
A compiler translates the entire code at once and stores the translated code in a file, and after the compilation is successful, you can use or run the compiled file.
But, an interpreter does not store the translated code, it translates the source code line-by-line (one statement at a time) and after translating the one statement it sends the translated code to the environment for execution. After execution, it goes to the next line for the iteration.
Just-in-time Compiler
Just in time (JIT) compiler has mixed features of interpreter and compiler, but it generally runs inside an interpreter.
Like the interpreter, it translates the source code line-by-line and send for execution, but it doesn’t wait until the code gets executed, like the interpreter. When the environment is busy in executing instruction, JIT translates next lines and stores them somewhere in the memory (that’s why it is faster than the interpreter).