This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.

Question: The difference between compiled and interpreted languages

I’m trying to understand the difference better. I found many explanations online, but they tended to be abstract differences rather than actual meanings.

Most of my programming experience has been with CPython (dynamic, interpreted) and Java (static, compiled). However, I know that there are other types of interpreted and compiled languages. Other than the fact that executables can be distributed from programs written in compiled languages, are there any advantages/disadvantages to each type? I often hear people argue that interpreted languages can be interactively used, but I believe that compiled languages can also have interactive implementations, right?

Popular answers

A compiled language is a language in which a program, once compiled, is represented by instructions from the target machine. For example, the addition + operation in source code can be translated directly into the ADD instruction in machine code.

An interpreted language is one in which instructions are not executed directly by the target machine, but are read and executed by other programs (usually written in the native language). For example, the same + operation would be recognized at run time by the interpreter, which would then call its own add(a, b) function with the appropriate arguments, and which would then execute the machine-code add instruction.

You can do things that you do in compiled languages, interpreted languages, and vice versa — they’re all Turing-complete. However, both have advantages and disadvantages in implementation and use.

I’m going to generalize completely (purists forgive me!) However, in general, compiled languages have the following advantages:

  • Improve performance by using native code directly from the target machine
  • There is an opportunity to apply very powerful optimizations at compile time

Here are the advantages of interpreted languages

  • No compile phase: code can be executed “dynamically” directly
  • It can be used more easily

Note that modern techniques such as bytecode compilation add some additional complexity — the compiler here is for a “virtual machine” that is different from the underlying hardware. These virtual machine instructions can be compiled again at a later stage to obtain native code (for example, through the JavajVMJIT compiler).

The article translated from Stack Overflow:stackoverflow.com/questions/3…