Java Virtual Machine (1)-Java Architecture

Source: Internet
Author: User

Java Virtual Machine (1)-Java Architecture
Java Architecture

The Java architecture includes 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 writing and running a Java program, these four technologies are used at the same time. Compile 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, you can call methods in the Java application programming interface (API) class to access Chinese sources such as io and network memory in the system. When the program runs, it can call the implementation methods in the class file to meet the java api calls of the program.

I. Java Virtual Machine

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

A Java virtual machine is an abstract computer that standardizes the features that every Java virtual machine must implement, but leaves many choices for each specific implementation.

The main task of the Java Virtual Machine is to load the class file and execute the bytecode. A class loader can load class files from programs and APIs. In Java APIs, only the classes required for program execution are loaded. Bytecode is executed by the execution engine.

Three execution engines in Java Virtual Machine

1. The simplest execution engine is the one-time interpretation of bytecode.

2. The other execution engine is faster, but also consumes more memory, called the "instant compiler" (just-in-time compiler)

3. The third type of execution engine is the adaptive optimizer.

The second type is much more efficient than the first type of execution engine, and the execution speed is faster, but the disadvantage is that the memory consumption is high. When the memory consumption is high, the jvm will have an exception. In this case, the bytecode that the instant compiler executes for the first time will be compiled by the local machine code, and the locally compiled machine code will also be cached, it can be reused when a method is called later.

The third engine is the adaptive optimizer. In this method, the virtual machine starts to interpret bytecode, But it monitors the activity of running programs and records the most frequently used code segments. When the program is running, the virtual machine only compiles the Code with the most frequent activities at the cost. Because other code is not frequently used, the bytecode is retained by the virtual machine to continue instant. An adaptive optimizer can execute the optimized local code within 80%-90% of the Java Virtual Machine, instead of compiling the Code with an impact on performance.

Interaction between Java Virtual Machine and host

When the java Virtual Machine is implemented by software on the host operating system, the java program calls the local method native mehod to interact with the host. Java has two methods: java and local. The java method is compiled by the java language and then compiled into bytecode, which is stored in the class file. The local method is written by other languages such as c \ c ++ \ assembly language, and relevant code of the compiler and processor.

Class loaders on java virtual machines

There are multiple class loaders on the java Virtual Machine. A java application can use two types of loaders to start the bootstrap class loader and user-defined class loaders. Starting the class loader is part of the implementation of the Java Virtual Machine. The START loader usually uses the default method to load classes from the local disk, including the java api class. The start class loader is also called the original Class Loader, system class loader, or default class loader.

Ii. Java class file

A Java class file is a cross-platform binary file that is compiled through a Java virtual machine.

Platform independence: Generally, binary executable files on one platform cannot work on other platforms. Java class files can run on any hardware platform and operating system supporting Java virtual machines.

Network Adaptability: class files are designed to be compact, so they can be quickly transmitted over the network. Secondly, because Java programs are dynamically linked and dynamically scalable, class files can be downloaded only when necessary.

Iii. Java API

Java API is a collection of runtime libraries. It provides a set of standard methods for accessing host system resources. Java API is relatively secure, and it is a prerequisite for ensuring platform independence, Because Java Virtual Machine and Java API class files are necessary for any Java platform. Before a platform can support Java programs, it is necessary to explicitly implement API functions on this specific platform.

4. Java programming language

Although Java is made for the network, many people may use Java to write programs 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 Scaling

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.