The first lecture talks about your understanding of the Java platform
Answer
Java itself is an object-oriented language. The most notable features are two aspects. One is that it is very easy to obtain cross-platform capabilities, and the other is GC. Java reclaims and allocates memory through the garbage collector.
JRE
That is, the Java runtime environment, including JVM
and Java class libraries, as well as some modules.
JDK
Can be seen as JRE
a superset, providing more tools, such 编译器
as 各种诊断工具等
.
Java is to explain the implementation of this sentence is not very accurate .
Java source code—compiled into bytecode by javac —converts the bytecode into final machine code bytecode
at runtime by an embedded interpreter.JVM
But common ones JVM
, such as Oracle JDK
provided ones Hotspot JVM
, all provide JIT(Just-In-Time)
compilers, that is 动态编译器
, they can compile hot code into machine code at runtime. In this case, some hot codes belong 编译执行
, not 解释执行
.
expand
For the understanding of the Java platform, we can talk about it from many aspects:
- Java Language Features - Generics, Lambda
- Basic class libraries - collections, IO/NIO, networking, concurrency, security, etc.
- JVM basic concepts and mechanisms - Java class loading mechanism, basic principles of garbage collection
Dig deeper into the issue of interpreted execution and compiled execution:
Java is usually divided into compile time and runtime. The compilation of javac, the compilation of Java source code .class
is actually in the generated file 字节码
, not directly executable 机器码
. Java shields the details of the operating system and hardware through the cross-platform abstraction of bytecode and the Java virtual machine . This is 一次编译,到处执行
the basis of implementation.
At runtime, the bytecode is loaded JVM
through the class loader , interpreted or compiled for execution. Class-Loader
When the Java virtual machine starts, you can specify different parameters to select the running mode.
For example -Xint
- JVM only interprets execution. This mode discards the advantages brought by JIT, because the interpreter is read one by one, and interpreted and executed one by one. For example -Xcomp
- the JVM closes the interpreter and does not interpret the execution, which may cause JVM
the startup to be much slower.
In addition to the common Java usage patterns, there are new compilation methods - AOT(Ahead-of-Time-Compilation)
directly compiling bytecode into machine code, which avoids the JIT
overhead of warm-up and other aspects. Oracle JDK
Support layered compilation and AOT collaborative use.