Java basics-a preliminary understanding of JVM

Source: Internet
Author: User

We know that advanced computer language execution can be divided into compilation and interpretation.

Compiled language: there is a dedicated compiler for a specific platform (operating system) to translate the source code of a certain high-level language into the machine code executed by the platform at a time, and packaged into the format of executable programs that the platform can recognize. This conversion format is called compilation. Compiled executable files can run independently on a specific platform from the development environment.

However, some programs may need to link the compiled target code after compilation.

C and C ++ are all compiled languages with high execution efficiency.

Advantage: High execution efficiency

Disadvantage: cross-platform unavailable

Interpreted language: A special interpreter is used to explain the source program to the machine code of a specific platform and to execute the language immediately. In fact, every time an interpreted program is executed, a compilation is required, therefore, the execution efficiency is not high and cannot be run independently from the interpreter.

Advantage: cross-platform support, as long as the interpreter is provided

Disadvantage: The execution efficiency is not high. In fact, the execution efficiency is sacrificed in exchange for portability.

Ruby is an interpreter language.

The Java language is special. Compile and then explain it. However, after compilation, the machine code of a specific platform is not generated, but a platform-independent bytecode (class file) is generated. The generated bytecode needs to be explained by the Java interpreter.

The Java language is responsible for interpreting that the class bytecode file is a Java Virtual Machine-JVM

The bytecode generated by the Java language is not platform-oriented, but JVM-oriented. different platforms have different JVMs, but the JVM provides the same upstream interface. The interface for downloading is different.

Since JVM is a virtual machine running Java programs, what is the relationship between the JDK and JRE we installed?

In fact, JVM is the core Virtual Machine for running Java programs, but other things are required to run Java programs, such as class libraries and loaders. The runtime environment JRE contains not only JVM, but also other environments that run Java programs. Therefore, JRE is used to run Java programs.

 

What is the relationship between JDK and JRE?

JDK: development environment. When JDK is installed, the JRE folder is included in the directory.

However, when installing JDK, you will still be prompted whether to select public JRE, which is installed on drive C by default.

 

Why does Sun have two JRE installed?

As mentioned above, JRE is a running program. If it is only a Java program, you only need to install an independent JRE.

This is because many Java-compiled development tools (such as javac.exe‑jar.exe) are available in JDK installation directory \ Lib \ tools. jar. As shown in the following example, change tools.jarto tools1.jar, and then run javac.exe. the following result is displayed:

Exception in thread "Main" Java. Lang. noclassdeffounderror: COM/Sun/tools/javac/main

In this case, you enter javac.exe and

Java-CP c: \ JDK \ Lib \ tools. jarcom. Sun. Tools. javac. Main

The results are the same.

From this we can prove that javac.exe is just a wrapper, and the purpose is to prevent developers from entering too long fingers. We can also find that the program in the <JDK installation directory> \ lib directory is very small, not greater than 29 K. Here we can draw a conclusion. That is, JDK tools are almost written in Java, so they are also Java applications. Therefore, to use the tools attached to JDK to develop Java programs, you must also attach a set of JRE, therefore, the JRE located in the c: \ Program Files \ Java directory is used to run general Java programs.

 

What is the difference between JRE in JDK and independent public JRE?

In JRE under JDK, the bin contains the JVM. cfg e Under the server and client, while the public only has the client.

If a computer installs more than two sets of JRE after JDK, who decides?

This major task falls on java.exe. The job of java.exe is to find the appropriate JRE to run the Java program.

Java.exe searches for jre in the following order:

Is there any JRE under your own directory;

Does the parent directory contain JRE;

Query the registry:

[HKEY_LOCAL_MACHINE \ SOFTWARE \ javasoft \ Java Runtime Environment]

The running result of java.exe has a great relationship with which JRE is executed on your computer.

The above also said that there will be multiple JVM. dll in the JDK's built-in JRE. Which one is called? What is the JVM principle call process? Please refer to the next blog

 

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.