In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how the Java virtual machine works". In the daily operation, I believe that many people have doubts about how the Java virtual machine works. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how the Java virtual machine works. Next, please follow the editor to study!
The concept of virtual machine is introduced in Java, that is, a virtual machine is added between the machine and the compiler. This virtual machine provides a common interface to the compiler on any platform. The compiler only needs to face the virtual machine, generate the code that the virtual machine can understand, and then the interpreter converts the virtual machine code into the machine code of a specific system. In Java, this code for virtual machines to understand is called bytecode (ByteCode), and it is not targeted at any particular processor, only for virtual machines. The interpreter for each platform is different, but the virtual machine implemented is the same. After the Java source program is compiled by the compiler, the bytecode is interpreted and executed by the virtual machine. The virtual machine sends each bytecode to be executed to the interpreter, which translates it into machine code on a specific machine, and then runs on the specific machine.
It can be said that the Java virtual machine is the foundation of Java language. It is an important part of Java technology. The Java virtual machine is an abstract computer that, like an actual computer, has an instruction set and uses different storage areas. It is responsible for executing instructions and managing data, memory, and registers. The Java interpreter is responsible for translating byte code into machine code for a particular machine. Java is a simple language. It does not use many concepts and is familiar to programmers. If you are a programmer, it is easy for you to master Java. Even if you haven't learned any programming languages, learning Java is much easier than learning C++.
Since Java was originally designed to control electronics, it must be simple and straightforward. To ensure this simplicity, Java removes many complex, redundant and ambiguous concepts from C++, such as operator overloading, multi-inheritance, automatic data type conversion, and so on. In order to free programmers from the burden of complex memory management, and also to reduce errors, Java uses an automatic memory garbage collection mechanism. Programmers only need to apply when needed, without releasing, while Java itself collects and releases useless blocks in memory.
Compared with C++, Java has stronger object-oriented features and is a relatively pure object-oriented language. Generally speaking, some so-called object-oriented programming languages we use, such as object Pascal, are actually a hybrid language, that is, adding object-oriented extensions to procedural languages. In Java, almost everything is an object, and even some basic data types, such as integer, character, floating point, etc., can be treated as objects in Java. The object-oriented feature of Java is almost comparable to that of Smalltalk, but it is far more suitable for distributed computing environment than Smalltalk.
Java is a programming language that supports distributed operations. Using the URL class provided by Java, users can access objects on the network as if they were local files, which is very convenient. In the client / server mode, Java can also distribute the operation from the server to the client, which improves the efficiency of the system and avoids the bottleneck of the server. Java's network class library supports distributed programming. The Socket class provides reliable connection to streaming networks and supports the TCP/IP protocol. By writing protocol handles, programmers can also extend the set of protocols supported by Java.
Java provides very effective security control. As Java is used in the development of network programs, security becomes very important. Because Java Mini Program needs to be downloaded to the client for interpretation and execution, if there is no security control, it will give some network hackers an opportunity, which is very dangerous for users. Fortunately, the security mechanism of Java can effectively prevent the generation of virus programs, download programs to destroy the local file system, and network hackers to steal passwords and intrusions.
Java is a very robust language. Because the following methods are used in Java:
Pointers are not supported. In C++ programs, pointer errors are the culprit of BUG in the usual program. The pointer is removed completely in Java, and the illegal access to memory is eliminated, thus ensuring the reliability of the program.
Strongly typed language
Automatic memory garbage collection mechanism. Java automatically collects useless memory units, thereby preventing dynamic memory allocation problems caused by memory leaks.
The perfect exception handling mechanism not only simplifies the error handling task and recovery, but also increases the readability of the program.
Java has excellent platform independence and portability. Because Java was originally designed to program electronic products, it is perfectly platform independent. It uses a platform-independent code ── bytecode, rather than the usual machine-specific machine code, which is interpreted and executed by the Java interpreter in the Java virtual machine on the platform. The Java virtual machine is free and available on many platforms.
Java provides good portability. Using Java as the programming language, as long as a program development work is carried out, the developed program can run on various platforms without any changes. Java uses two ways to make Java applications independent of specific systems:
Data types based on international standards are adopted. The raw data type of Java is the same on any machine, for example, integer is always 32-bit, long integer is always 64-bit, and so on.
Provides an extensible class library for accessing the functions of the underlying operating system.
Java is a high-performance language. "you can't have both." usually, improvements in robustness, security, platform independence, portability and so on always come at the expense of performance. Java is no exception, the memory management of Java increases the complexity of the runtime system, because the Java runtime system must embed a memory management module; similarly, the efficiency of interpretation and execution of Java programs is also lower than that of directly executing the compiled source code. But Java has taken some good steps to bridge these performance gaps:
Generate efficient bytecode. The design of Java bytecode fully takes into account the performance factors, the bytecode format is simple, and the interpreter can generate efficient machine code.
Provides options for compiling and embedding C code in real time. Just-in-time compilation refers to compiling bytecode into machine code at run time. Support for multithreading. Java provides a language-level interface to multithreading, and the Java environment itself is multithreaded.
Java has good support for multithreading. Multithreading technology can improve the concurrency of program execution and the interactive performance of graphical user interface. Java provides multithreaded control built into the language, simplifies the development of multithreaded applications, and supports thread synchronization control.
Java is a dynamic language. Dynamic characteristic is an extension of object-oriented feature, which enables the program to adapt to the ever-changing execution environment. The dynamic nature of Java is mainly shown in the following aspects:
Java classes are represented at run time, so that even at run time, the program can identify the relationship and type information between classes, and can dynamically link a class to the runtime system from local or online.
Java classes are loaded dynamically during operation, so Java can dynamically maintain consistency between applications and Java class libraries in a distributed environment. When the class library is upgraded, the application can still take advantage of the new features in the new class library without having to recompile.
Dynamic data types and dynamic protocols are supported. By writing protocol handles, Java can support new, custom transport protocols, write content handles, and support new data types.
At this point, the study on "how the Java virtual machine works" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.