Java Runtime Environment and mechanism, java Runtime Environment
First, we will introduce three concepts:
JVM----JAVA virtual machine
Java Virtual Machine: provides the same interface for bytecode and different interfaces for the operating system to adapt to various operating systems
JRE----JAVA runtime environment
Java Runtime Environment
JDK ---- java SE Development kit
Java Standard Edition
This is the three most basic concepts of learning java. Their relationships are as follows:
| JDK (required for development) |
-| ----- JAVA class library |
|
|
| |
| ----- JAVA compiler |
|
|
| |
| ----- JRE (required to run Java) |
-| ----- JVM |
|
| |
|
| ----- Class Loader |
-| |
| |
|
| ----- Bytecode validator |
| --- Other environment support for running java programs |
| |
|
| ----- Base class library |
_ | |
| |
|
|
|
You can run the java program to install the corresponding JRE. If you need to develop jkd, it is meaningless to simply use jvm (no official download is available)
Java from code to running:
Java source file (. java file) -----> java compiler (Compiled using javac) -----> bytecode file (. class file) --- |
Machine code of a specific platform (which can be run by the OS) <-- java Virtual Machine (which can be interpreted and executed using java) <--- |
The java compiler generates bytecode irrelevant to each platform. These bytecode are not oriented to any platform, but only to JVM. At the same time, the JVM on different platforms is different, however, they all provide the same interface to process bytecode. At the same time, different interfaces are generated corresponding to different platforms (linux/win). JVM can be said to be a converter.
In addition, the jar package:
We will also encounter. jar packages. Jar (Java Archive File is translated into a java Archive File ). To put it bluntly, it is a zip package for compressing. class, but because it contains a file
META-INF/MANIFEST. MF (generated jar package), so that the. class file inside has a certain structure. Our program can directly reference these jar packages (a bit like the dll file in C #), or directly run this jar package.
Note that
(1 ). the name of the java file is random, but if the java file contains a public class, then. the java file name must be consistent with the class name, so there can be only one public class at most.
(2) 1. When the name is large, the lower case is sensitive (remember that all keywords are lower case ).
2. The default path (jdk's default path) contains spaces in the program files. It is best to select a path without spaces (and do not contain Chinese characters to avoid inexplicable errors)
Environment variable:
Why do we need to set environment variables?
After installing jdk, if you do not set it, the prompt "java" or "javac" is not an internal or external command when you type the java or javac command, it is not a program or batch processing file that can be run. This is because: Although JDK has been installed on the computer, and the JDK path contains the java and javac commands, however, the computer does not know where to find these two commands (in other words, the computer does not know that it has these two functions), so we need to set a guide (PATH) to tell the OS to go here.
Path: directory of the java compilation and running Tool
ClassPath: Address of the tool class required for java calls
The public name of the JAVA_Home java installation directory (that is, the JDK installation directory)
Java memory collection mechanism (GC)
This is similar to C #, so I will not go into details here. Just to mention
(1) do not recycle the memory in time ---> The amount of memory available will decrease ---> the recovery frequency will increase ---> the performance will decrease
(2) java cannot forcibly recycle the memory. We recommend that you only recycle the memory by jvm.