Java Basics: A detailed explanation of the JVM (Java Virtual machine)

Source: Internet
Author: User
Tags abstract object error handling exception handling execution file system garbage collection new features

There may be a lot of learning Java friends do not know how Java operation, Java Virtual machine is how to work, this article will give you a detailed explanation (JVM) Java virtual machine.

In Java, the concept of virtual machines is introduced, that is, a layer of abstract virtual machines is added between the machine and the compiler. This virtual machine provides a common interface to compilers on any platform. The compiler only needs to target the virtual machine, generate code that the virtual machine can understand, and then convert the virtual machine code to the machine code execution of the specific system by the interpreter. In Java, this code for the virtual machine to understand is called bytecode (bytecode), which does not target any particular processor, but only to the virtual machine. The interpreters for each platform are different, but the virtual machines implemented are the same. The Java source is compiled into bytecode by the compiler, bytecode is interpreted by the virtual machine, and the virtual machine sends each byte code to be executed to the interpreter, which translates it into machine code on a particular machine and then runs on a particular machine.

Java virtual machines can be said to be the foundation of the Java language. It is an important part of Java technology. A Java Virtual machine is an abstract computer, like an actual computer, that has a set of instructions and uses a different storage area. It is responsible for executing instructions, as well as managing data, memory, and registers. The Java interpreter is responsible for translating the byte code into machine code for a particular machine. Java is a simple language. It uses a few concepts and is more familiar to programmers. If you're a programmer, mastering Java is a breeze for you. Even if you haven't learned any programming language, learning Java is much easier than learning C + +.

Since Java was originally designed to control electronic products, it must be simple and straightforward. To ensure this simplicity, Java removes many of the complex, redundant, two-semantic concepts of C + +, such as operator overloading, multiple inheritance, automatic data type conversions, and more. In order to free programmers from the burden of complex memory management, but also to reduce errors, Java uses the automatic memory garbage collection mechanism, the programmer as long as the need to apply, do not need to release, and Java itself to collect, free memory of useless blocks.

Compared with C + +, Java has a stronger object-oriented characteristics, is a relatively pure object-oriented language. In general, some of the so-called object-oriented programming languages we use, such as C++,object Pascal, are actually a hybrid language, that is, adding object-oriented extensions to procedural languages. In Java, almost everything is object, even some basic data types, such as Integer, character, floating-point type, in Java can be treated as objects. Java's object-oriented characteristics can be almost comparable to Smalltalk, but its applicability to the distributed computing environment is far more than the Smalltalk.

Java is a programming language that supports distributed operations. Using Java-provided URL classes, users can access objects on the network just as they would access local files, which is very handy. In the client/server mode, Java can also spread the operation from the server side to the client, improve the efficiency of the system, avoid the bottleneck of the server constraints. Java's network Class library supports distributed programming. The socket class provides a reliable stream network connection that supports the TCP/IP protocol. By writing protocol handles, programmers can also expand the set of protocols that Java supports.

Java provides very effective security controls. Because Java is used in the development of network programs, security becomes critical. Because the Java applet needs to be downloaded to the client to interpret the execution, if there is no security control, it will give some network hackers the opportunity, which is very dangerous for users. Fortunately, the Java security mechanism can effectively prevent the production of virus programs, download programs to the local file system damage, as well as network hackers to steal passwords and intrusion.

Java is a very robust language. Because the following methods are used in Java:

Pointers are not supported. In C + + programs, pointer errors use the culprit of bugs in the usual program. In Java completely removed the pointer, eliminate the illegal access to memory, so as to ensure 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 simplifies both the error handling task and the recovery, and also increases the readability of the program.

Java has very good platform independence and portability. Because Java was originally designed for electronic programming, it has a perfect platform-independent nature. It uses a platform-independent code-bytecode, rather than machine code on a particular machine, which is interpreted by the Java interpreter in the Java Virtual machine on the platform. Java virtual machines are free and are available on many platforms.

Java provides a good portability. Using Java as a programming language, as long as a program development work, the development of the program does not need to undergo any changes, it can run on a variety of platforms. Java uses two methods to make Java applications independent of specific systems:

Use of data types based on international standards. The original data type of Java is the same on any machine, for example, the integral type is always 32 bits, and the long integer is always 64 bits.

Provides an extensible class library for accessing the underlying operating system features.

Java is a high-performance language. "Fish and paws can not have both", usually, robustness, security, platform-independent, portability and other aspects of the increase always at the expense of performance. Java is no exception, Java memory management increases the complexity of the run-time system, because the Java runtime system must be embedded in a memory management module, as well, the Java program's interpretation of the efficiency of execution is lower than the direct execution of compiled source code efficiency. But Java has taken some good steps to compensate for these performance gaps:

Generates an efficient byte code. Java bytecode design takes into account the performance factor, the bytecode format is simple, the interpreter can generate efficient machine code.

Provides an optional measure for Just-in-time compilation and embedding of C code. 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 improve the interactive performance of graphical user interface. Java provides built-in multithreaded control, simplifies the development of multithreaded applications, and supports synchronous control of threads.

Java is a dynamic language. Dynamic characteristics are an extension of object-oriented features that enable programs to adapt to changing execution environments. The dynamic nature of Java is mainly manifested in the following aspects:

Java classes have run-time representations so that, even at runtime, the program can identify the relationship between classes and type information, and dynamically link a class to a running system from the local or the web.

Java classes are dynamically loaded during the run, so Java can dynamically maintain consistency between applications and Java class libraries in a distributed environment. When the class library is upgraded, the application does not need to be recompiled, and it can take advantage of the new features that are added to the class library.

Supports dynamic data types and dynamic protocols. By writing a protocol handle, Java can support new, custom transport protocols, write content handles, and support new data types.



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.