Java Virtual machine a Bo Entertainment (JVM) and cross-platform principle

Source: Internet
Author: User

A Bo entertainment believe that you have learned that Java has cross-platform features, you can "compile once, run everywhere", the program written under Windows, without any modification can run under Linux, which is difficult to do 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").

However, after all, Java has some extra overhead for C/+ +, and the critical applications are slower. For example, Java uses the platform-independent drawing method, the GUI program (client program) execution is slow, and the virtual machine starts to take time.

Client market for a discount

Java GUI Library is not good, the interface is not friendly, most users are not accustomed to, Java client resource consumption is also relatively large, large data volume applications and complex application performance is worrying.

More unacceptable is that Microsoft because of its own interests and sun split, Windows will no longer pre-installed JVM, users install your program, you must install the JVM and set up correctly, you can ask ordinary users to install your software, but you can expect him to understand the knowledge of the JVM and install the correct settings?

Although you can integrate the JVM into your program, install and set it automatically, without user intervention, but would you like to include a JVM that is much larger than your program? One software might be acceptable, and thousands of software would do the same, how many JVMs would the user install? How much disk space is wasted?

Therefore, directly to the market for ordinary users of the client program, with Java development of the very few, most of the Java development of the client is to the enterprise internal staff use, staff to the computer, the technical department has been configured. If you want to engage in client development, it is recommended that you learn C + + and. NET, which have a greater advantage in window client development.

A variety of reasons, destined for the Java client is not conducive to market, let ordinary users accept. But then again, client development is not the original intention of Java, Java was initially oriented to embedded, but with the rise of the internet and rapid growth, in the web development. Recommended URL: www.yxin7.com

Java Virtual machine a Bo Entertainment (JVM) and cross-platform principle

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.