A summary of the operating mechanism of Java

Source: Internet
Author: User

This essay mainly records my platform independence of Java some new understanding, previously only know that Java is a very easy to cross-platform language, as "Compile once, run anywhere" this sentence, but also know that Java will first load the class bytecode file mechanism, But for this is smattering, so I think it is necessary to summarize the loading mechanism in depth.

The Java mechanism that you know

    • Write the source code
    • Compile as a byte code
    • Byte code interpreted as machine code by the JVM

This is really the basic loading process of Java code, so sometimes we call "Java is interpreted", but recently read a related article and found it inaccurate.

"Interpreting execution" and "Compiling execution"

Let's talk about the JRE (Java Runtime Environment) and the JDK (Java Development Kit), the JRE is the runtime environment, contains the JVM and Java class libraries, and some modules, and the JDK is a superset of the JRE, The JDK we downloaded will contain the JRE, which provides more tools such as compilers and various diagnostic tools. Why is it inaccurate to say "interpret execution"? Because some JVMs provide a JIT (just-in-time) compiler, often referred to as a dynamic compiler, as the hotspot JVM provided by Oracle JDK, JIT compiles hot-spot code into machine code at run time, in which case part of the code is compiled and executed. Rather than explain the execution.

What is "compilation" and "Interpretation"?

General programmers use high-level languages like C and Java, and computers only know machine language, so we have to translate high-level languages into machine languages before they can run on computers, there are two ways of compiling and interpreting them. such as C + + is a direct compilation of the language, need to use a special compiler, as well as Python, Ruby is an interpreted language, using a dedicated interpreter line-by-row interpretation and immediate execution, relative to the former run slower. Java is a combination of compiled and interpreted language, we are accustomed to the Java is divided into compile time and runtime, where the compilation and C is not the same, the Java source code compiled to bytecode is the first compilation, then the byte code is processed by the JVM, that is, as long as a platform with the JVM, You can run Java programs. At run time, the JVM loads bytecode through the ClassLoader (Class-loader), explaining or compiling the run. This involves a deeper concept, mainly the processing details of the JIT. The mainstream Java version is often the interpretation and compilation of mixed patterns, the JVM for the different application of the different compilation and interpretation strategies, such as desktop applications and server applications, there are different requirements, the concept here may be a bit vague, to go deep into the JVM, recommend "in-depth understanding of Java Virtual Machine." The most common Java usage patterns of the day, is a new way of compiling, AOT (Ahead-of-time compilation), directly to the bytecode compiled into machine code, of course, this is just some basic concepts, in order to understand the Java operating mechanism, it is necessary to read more relevant books and technical articles.



Summarize

The high-level program language from the source code to run the phase is generally: encoding ——— compile ——— run ——— debugging, Java introduced the JVM mainly to achieve cross-platform features, of course, there are other functions, such as the specification of the bytecode can be run on the JVM, such as JRuby, Jython, etc. The overall running speed of the Java program is between C and Python, each language has its own advantages, suitable for different occasions, Java operating mechanism is more complex than this article said, but it is not so difficult, as long as the perseverance of learning, one day you will become a good developer.

A summary of the operating mechanism of Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.