Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How much does Java know about virtual machine JVM) and the example analysis of cross-platform principle

2025-05-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you an example analysis of how many virtual machines you know about Java, JVM) and cross-platform principles. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.

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

So, how is cross-platform implementation? This is about to talk about the Java virtual machine (Java Virtual Machine, referred to as JVM).

JVM is also a software, and different platforms have different versions. The Java source code we write will be compiled to produce a .class file called a bytecode file. The Java virtual machine is responsible for translating bytecode files into machine code on a specific platform and then running it. In other words, as long as the corresponding JVM is installed on different platforms, you can run the bytecode file and the Java program we wrote.

In this process, the Java program we wrote has not made any change, just through the "middle tier" of JVM, it can run on different platforms, which really achieves the goal of "compile once, run everywhere".

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

Note: the result of compilation is not to generate machine code, but to generate bytecode. Bytecode cannot be run directly and must be translated into machine code through JVM before it can be run. The bytecode compiled on different platforms is the same, but the machine code translated by JVM is different.

Therefore, running a Java program must have the support of JVM, because the compiled result is not machine code and must be retranslated by JVM before it can be executed. Even if you package the Java program into an executable file (such as .exe), you still need JVM support.

Note: cross-platform is the Java program, not JVM. JVM is developed with CumberCraft +, which is compiled machine code and cannot be across platforms. Different versions of JVM need to be installed on different platforms.

Figure 1 JVM implementation of cross-platform

On the execution efficiency of JVM

A few years before the launch of Java, people took a different view, explaining that bytecode must be much slower than full-speed machine code, is it worth sacrificing performance for cross-platform advantages?

However, JVM has an option to translate the most frequently used bytecode into machine code and save it, a process called just-in-time compilation. This approach is really effective, resulting in the use of virtual machines on Microsoft's .NET platform.

Today's just-in-time compilers are so excellent that they have even become competitors to traditional compilers, in some cases even better than traditional compilers, because JVM can monitor runtime information. For example, the just-in-time compiler can monitor frequently used code and optimize it, eliminating function calls (that is, "embedding").

However, after all, Java has some additional overhead that Cmax Cure + does not have, and key applications are slow. For example, Java uses a platform-independent drawing method, and the GUI program (client program) executes slowly; it also takes time to start the virtual machine.

The collapse of the client market

Java's GUI library is not excellent, the interface is not friendly, most users are not used to it; Java client resource consumption is also relatively large, the performance of applications with large amounts of data and complex functions is worrying.

What is even more unacceptable is that after Microsoft separated from SUN due to self-interest, Windows is no longer pre-installed with JVM. Before installing your program, users must install JVM and set it correctly. You can ask ordinary users to install your software, but can you expect him to know about JVM and install settings correctly?

Although you can integrate JVM into your program, automatically install and set it up without user intervention, do you want to include a JVM that is much bigger than your program? It may be acceptable for one software to do this, and thousands of software do so, so how many JVM do users have to install? How much disk space will be wasted?

Therefore, the client programs directly put on the market for ordinary users are rarely developed with Java, and most of the clients developed by Java are for employees within the enterprise to use. When the employees receive the computer, the technical department has already configured it. If you want to engage in client-side development, it is recommended that you learn from Cumberbatch + and .NET, which have a big advantage in Window client-side development.

For various reasons, it is doomed that the Java client is not conducive to the market and accepted by ordinary users. But then again, client development is not the original intention of Java. Java was originally embedded, but it grew rapidly with the rise of the Internet and showed its skills in Web development.

The above is the example analysis of how many virtual machines (JVM) and cross-platform principles shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report