In-depth Java Virtual machine (1)--java architecture

Source: Internet
Author: User

Java architecture

The Java architecture consists of four independent but related technologies:

1.Java programming Language
2.Java class file format
3.Java Application Programming Interface (API)
4.Java Virtual Machine

When you write and run a Java program, you use these four techniques at the same time. Write the source code in the Java programming language, compile it into a Java class file, and then run the class file in the Java Virtual machine. When writing a program, a method in the Java Application Programming Interface (API) class is implemented to access resources such as IO, network memory, etc. in the system. When the program runs, it can invoke the implementation method in the class file to satisfy the program Java API's call.

One, Java Virtual machine

Java's network-oriented core is Java Virtual machine, which supports the three pillars of Java-oriented network architecture: platform independence, security and network mobility.

A Java Virtual machine is an abstract computer whose specification defines the features that each Java virtual machine must implement, but leaves many choices for each particular implementation.

The primary task of a Java virtual machine is to load a class file and execute its bytecode. The load class is done by the class loader, which can load class files from programs and APIs. Loader Only those classes that are required for program execution in JAVAAPI are loaded. The byte code is executed by the execution engine.

Three execution engines in a Java virtual machine

1, the simplest execution engine is a one-time interpretation of byte code

2, another execution engine faster, but also more memory consumption, called "Instant Compiler" (Just-in-time compiler)

3. The third execution engine is an adaptive optimizer

The second is much more efficient than the first execution engine and executes faster, but the relative disadvantage is that memory consumption is high. When memory consumption is severe, the JVM will have an exception. In this case, the byte code that the instant compiler executes for the first time is compiled at the cost of the machine code, and the compiled local machine code is cached, which can be reused when the method is called later.

The third engine, the Adaptive Optimizer, in which the virtual machine interprets the bytecode at the beginning, but monitors the activity of the running program, and records the most frequently used code snippets. While the program is running, the virtual machine compiles only the most frequently-used code, and the other code continues to keep bytecode by the virtual machine as it is not very frequent. An adaptive optimizer can use 80%-90% of the Java Virtual machine's time to execute the optimized native code, and only need to compile 10%-20% code that has an impact on performance.

Java Virtual machine interacts with host

When the Java virtual machine is implemented by the software on the host operating system, the Java program interacts with the host by calling the local method native Mehod. There are two methods in Java, Java methods and local methods. Java methods are written in the Java language and then compiled into bytecode, stored in the class file. Local methods are written by other languages such as c\c++\ assembly language, compiler and processor-related code.

Class loader on a Java virtual machine

There are several class loaders on the Java Virtual machine, and a Java application can start the Bootstrap class loader and the user-defined class loader using the two kinds of loaders. The Startup class loader is part of the Java Virtual Machine implementation. The boot loader typically uses the default way to load classes from local disks, including Java API classes. The Startup class loader is also called the original class loader, the System class loader, or the default class loader.

Java class file

A Java class file is a binary file that can be cross-platform and compiled from a Java virtual machine.

Platform agnostic: Typically, binary executables on one platform do not work on other platforms. The Java class file is a binary file that can run on any Java virtual mechanism hardware platform and operating system.

Network adaptability: class file design is compact, so they can be quickly transmitted over the network. Second, because Java programs are dynamically linked and dynamically extensible, class files can be downloaded when needed.

Java API

The Java API is a collection of runtime libraries that provide a set of standard methods for accessing host system resources. The Java API is relatively secure and is a prerequisite for platform independence, because Java virtual machines and Java API class files are a necessary part of any Java platform to implement. Before a platform can support Java programs, the functionality of the API must be explicitly implemented on this particular platform.

Java programming language

Although Java is for networking, many people use Java to write programs, possibly because they want to take advantage of the Java programming language:

1. Object-oriented
2. Multithreading
3. Structured error handling
4. Garbage collection
5. Dynamic Connection
6. Dynamic expansion

In-depth Java Virtual machine (1)--java architecture

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.