How does Java achieve cross-platform? What is the principle?

Friends who learn Java must all know that Java allows cross-platform use, so do you know how Java implements cross-platform? What is the principle? Xiaoqian will answer you today.

1610502970954.jpg

One, the principle of Java cross-platform

First, let's talk about the running process of Java code:

1. First compile the java file into a bytecode (.class) file;

2. Use Java Virtual Machine (JVM-Java Virtual Machine) to run bytecode files.

In the above steps, in the first step, the bytecode files generated on all platforms are the same.

In the above steps, in the second step, the Java virtual machines that run bytecode files on different platforms are different.

The Java development team has developed corresponding versions of java virtual machines for different platforms, which allows the same java code file to run on different platforms.

Therefore, java can achieve cross-platform operation because of the support of the java virtual machine corresponding to various platforms.

2. Explanation of several terms involved

JDK

JDK is the abbreviation of Java Development Kit, and JDK is the software development kit (SDK) of the Java language. Provides the files and environment needed for java development, compilation, and operation.

There is a jre directory in the JDK installation directory, which contains two folders bin and lib. Here you can think that the bin is jvm, and the lib is the class library required for jvm work, and the combination of jvm and lib is Called jre.

JRE

JRE is the abbreviation of Java Runtime Environment. There is a Java Virtual Machine and some standard Class Library inside JRE. JRE is a necessary tool for running java bytecode files.

JVM

JVM is the abbreviation of Java Virtual Machine. JVM is a specification for computing devices. It is a fictitious computer that is realized by simulating various computer functions on an actual computer.

JVM has versions for different platforms, they can run bytecode files compiled with the same java code, which makes the Java code cross-platform.

After reading it, I believe students should understand the principle of Java cross-platform.

The original text comes from Qianfeng Education: http://wh.mobiletrain.org/ , please indicate the source for reprinting.


Guess you like

Origin blog.51cto.com/15128702/2665355