C # Convert to Java, JVM learn more

Source: Internet
Author: User

Turn from

Http://www.cnblogs.com/Coda/p/4331432.html

I believe you have learned that Java has cross-platform features that can be "compiled once, run Everywhere", programs written under Windows can run under Linux without any modification, which is difficult for C and C + +.

So how does a cross-platform implement it? This will refer to the Java Virtual machine (Java VM, or JVM).

The JVM is also a software that has different versions of different platforms. We write the Java source code, compiled will generate a. class file, called a bytecode file. The Java Virtual machine is responsible for translating bytecode files into machine code under a specific platform and then running. That is, as long as the corresponding JVM is installed on different platforms, you can run the bytecode file and run the Java program we wrote.

In this process, the Java program that we write does not make any changes, just through the JVM, the "middle layer" can be run on different platforms, and really achieve the "compile once, run everywhere" purpose.

JVM is a "bridge", is a "middleware", is the key to achieve cross-platform, Java code is first compiled into bytecode files, and then by the JVM to translate bytecode files into machine language, so as to achieve the purpose of running Java programs.

Note: The result of compiling is not to generate machine code, but to generate bytecode, bytecode can not run directly, must be translated into machine code by the JVM to run. The bytecode generated under different platforms is the same, but the machine code translated by the JVM is not the same.

Therefore, running the Java program must have the support of the JVM, because the result of the compilation is not machine code, it must be re-translated by the JVM to execute. Even if you package a Java program as an executable file (for example,. exe), you still need the JVM's support.

Note: The cross-platform is a Java program, not a JVM. The JVM is developed in C/s + +, is compiled machine code, not cross-platform, different platforms need to install different versions of the JVM.



Figure 1 JVM implementation efficiency across platforms for JVM execution

In the first few years of Java launch, people have different views, explaining that bytecode is definitely slower than running at full speed, and sacrificing performance to cross-platform benefits is worth it?

However, the JVM has an option to translate the most frequently used bytecode into machine code and save it, a process known as instant compilation. This is really effective, and the Microsoft. NET platform also uses virtual machines.

The now-in-time compilers have been pretty good, even as competitors of traditional compilers, and in some cases even more than traditional compilers, because the JVM can monitor runtime information. For example, an instant compiler can monitor code that is used more frequently and optimize it, eliminating function calls ("inline").

C # Convert to Java, JVM learn more

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.