This is the 14th day of my participation in the August Text Challenge.More challenges in August


One weekend, the CPU and JVM got into a conversation


Summary of concepts: compiled languages, interpreted languages, scripting languages

All three are programming languages. Compiled languages exist relative to interpreted languages, and interpreted languages exist relative to compiled languages. Scripting languages are not language categories, as explained below

Compiled language

Baidu Encyclopedia: compiled language is explained as follows

A program needs a special compilation process before it can be executed. The program is compiled into a machine-language (instruction set) file, which can be used directly at run time without retranslation. Program execution efficiency, compiler – dependent, less cross-platform. Such as C, C++ and so on

Chinese Wikipedia: The compilation language is explained below

Compiled language is a type of programming language that is implemented by the compiler. Instead of an interpreter running code sentence by sentence, as in an interpreted language, it uses a compiler, which first compiles the code into machine code and then runs it. In theory, any programming language can be compiled, or translated (interpreted). The difference between them is only related to the application of the program

The advantages and disadvantages

In general, programs written in compiled languages run faster at runtime than programs written in interpreted languages. Because at compile time, the program has been pre-compiled into machine code, can run directly, as interpreted language, like another translation program.

However, compile languages have to be compiled before you can run them. Generally speaking, compiled language program development speed, as well as debugging time, are relatively long. Because it’s not like an interpreted language where you can write a line or a short program and then run it and debug it. Interpreted languages often reduce overall development time and allow programmers to test their ideas more flexibly and quickly during development.

Just-in-time compilation techniques, developed to improve the efficiency of compiling languages, have narrowed the gap between the two. This technique combines the advantages of compiled and interpreted languages by first compiling the program source code into bytecode, as in compiled languages. At run time, the bytecode is translated and then run. Java and LLVM are representative products of this technology.

Interpretive language

Interpretive language is also called literal language

Baidu Encyclopedia: interpretive language is explained as follows

In contrast to compiled languages, source code is not translated directly into machine language, but is first translated into intermediate code, which is then interpreted and run by an interpreter. Python, JavaScript, Perl, Shell, and so on are all interpreted languages.

Interpreted languages: programs do not need to be compiled; they are translated into machine language at runtime, every time they execute. So it’s inefficient. Basic, for example, has an interpreter that executes Basic programs directly, and each statement is translated as it is executed. (It is translated at run time, with an interpreter dedicated to translation, and each statement is translated at run time. Low efficiency, interpreter dependence, good cross-platform.)

Chinese Wikipedia: Explanatory language is explained below

Interpreted language is a type of programming language. In this type of programming language, code is run verbatim without the need for Compiled language to make machine code and run it later. This language requires an interpreter to interpret code dynamically into machine code, or subroutines that have been precompiled into machine code, at run time, and then run again.

In theory, any programming language can be either compiled or interpreted. The difference between them is only related to the application of the program. Many programming languages use both compilers and interpreters, including Lisp, Pascal, C, BASIC, and Python. JAVA and C# take a hybrid approach, compiling code into bytecode and interpreting it at run time.

Scripting language

Scripting languages do not fall into the language category

“Script” is a term used to describe the “orientation and purpose of a program.

Languages that are widely used to write scripts and processes are often referred to as scripting languages. And because many times (especially for non-professional software developers) the scripting languages used are interpreted languages (interpreted languages are usually better than compiled languages), it is not a serious statement to say that scripting languages = interpreted languages

Find some information as follows: Zhihu -What is the difference between a programming language and a scripting language?


Essential differences between compiled and scripting languages

Interpreted languages are instruction sets encapsulated by high-level languages, not machine instruction sets. It needs to be interpreted as a high-level language and then executed by a high-level language

Compiled languages, on the other hand, compile directly into machine instruction sets: programs need a special compilation process before they can be executed. The program is compiled into machine-language files, and the runtime uses the compiled results directly

This should be the essence of what separates a programming language from a scripting language

The example analysis

Nodejs

Nodejs does not require compilation and is essentially a top layer of C, making it an interpreted language

Special Java

wikipedia

Java is very special

  • Previously Java was compiled directly into machine language
  • Java programs today also need to be compiled, but instead of being compiled directly into machine language, they are compiled into bytecode, which then == translates (translation ≠ interprets)== executes bytecode.

    Bytecode: Intermediate code defined by Java for cross-platform use. Java code is compiled into bytecode, which is then translated by the JVM into the CPU instructions for the current platform and then executed by the CPU. Bytecode and CPU instruction set is very similar, each bytecode has a corresponding assembly instructions, the difference is that the bytecode is not like CPU instructions have long and short, but unified is a byte, so called bytecode!

To decide whether Java is a compiled or interpreted language, it should == be compiled == for the following reasons:

  • Although Java is not compiled directly into machine language, there is no interpretive process.
  • Translation is only done for cross-platform. Although the word translation is easily associated with interpretation, it is not the same thing: each bytecode has a corresponding assembly instruction, and translation is more efficient than interpretation, which is completely different. (Just like there is a “leap earth and 猹”, the interpretation is equivalent to the Chinese teacher will analyze and understand it to tell you, and the translation is similar to the English teacher will translate him into English)
  • Translation makes Java not only less slow than interpreting languages, but also more efficient than C thanks to JIT technology.

    JIT: to generate some mediation code (Java Bytecode /MSIL) in compile form, convert it (usually in units of functions or blocks) to machine code at run time, and execute it. The converted machine code can be cached to improve the efficiency of repeated execution.The efficiency of this increase could even exceed that of C

Conclusion: at first, I just feel that the word “compiled language” is better than “interpreted language, scripting language”, so sometimes when I see some people on the Internet saying that Java is scripting language, interpreted language and so on, as a Javaer, I feel a little uncomfortable. As Java’s greatness dawned on me, I no longer wanted to call it a compiled language. Because Java, that’s Java== Java==