Passionate Court only spring months, according to Utah for the falling away from the people.
Outline
This chapter understand the difference between JDK, JRE and JVM. How the JVM works? What is the class loader, interpreter and JIT compiler. There are some interview questions.
Java program execution
Before delving into Java memory area, we first understand how the Java source file is executed.
- We use the editor
Simple.Java
to write the source code file. - It must be compiled into bytecode program. Compiler (
javac
) compiling the source code for theSimple.class
file. - This suffix
.class
class files at any platform / operating systemJVM
(Java
virtual machine) execution. JVM
It is responsible for converting the byte code to native machine code executable by the machine.
What is JVM?
Java
Virtual Machine ( JVM
) is running Java
bytecode virtual machine. By javax
the .java
file compiled .class
files. .class
File contains JVM
resolvable bytecode.
In fact, JVM
just to Java
provide a runtime environment and specification byte code. Different manufacturers offer different implementations of this specification. For example, this Wiki
page lists the other JVM implementations .
The most popular JVM
virtual machine is Oracle
provided by Hostspot
a virtual machine, (formerly known as Sun Microsystems,Inc
.).
JVM
Virtual machine uses a lot of advanced technology, combined with the latest memory model, garbage collector and adaptive optimizer, to Java
provide the best performance of the application.
JVM
The virtual machine has two different modes, client
mode and server
mode. Despite server
and client
similar, but server
has been specially tuned to maximize peak operating speed. It is used for long-running server applications, they need to speed as quickly as possible, rather than the quick start or a smaller memory footprint run-time. Developers can specify -client
or -server
to select the desired mode.
JVM
It is called a virtual machine, because it provides API
does not depend on the underlying operating system and hardware architecture of the machine. This hardware and operating system independence with a Java
program write once, run anywhere necessary foundation.
JVM architecture
Class loader
Class loader is used to load the class files into JVM
the. Divided into the following three steps to load, and link initialization.
- load
- In order to load the class,
JVM
there are three types loader.Bootstrap
,extension
And application class loader. - When loading class files,
JVM
you will find all the dependencies of this class. - First class loader will determine whether there is a current class loader parent, if the parent loader to load.
Bootstrap
It is the root class loader,Bootstrap
loader tries to find the class. It scans theJRE
lib
folderrt.jar
.- If you can not find the class, then the
extension
loader willjre \ lib \ ext
search for class files package. - If you can not find a class, the application class loader system will
CLASSPATH
search all environment variablesJa
r files and classes - Any class loader finds the class, by the class loader loads the class; otherwise throw
ClassNotFoundException
.
- Links: The class loader loads the class, will perform the link. Bytecode verification program verifies the generated byte code is correct, if the validation fails, we will receive a validation error. It would also have class Static variables and methods for performing memory allocation.
- Initialization: This is the last phase of class loading, where all static variables will be assigned the original value, and perform a static block.
JVM memory area
JVM
The memory area is divided into a plurality of portions to store a particular portion of the application data.
- Method Area: storage class structures, such as basic information such as, the runtime constant pool and method code.
- Heap: all objects stored during application execution created.
- Stack: storing local variables and intermediate results. All these variables to create their threads are private. Each thread has its own
JVM
stack, and at the same time create a thread is created. Accordingly, all such local variables are called thread-local variables. - PC register: storing physical memory address of the currently executing statement. In Java, each thread has its own separate PC register.
- Local area method: Many underlying code are written in C and C like language. Native method stacks retains instructions native code.
JVM execution engine
Assigned to JVM
all the code executed by the execution engine. Bytecode execution engine reads and 11 executed. It uses two built-interpreter and JIT compiler to convert byte code into machine code and executed.
Use JVM
, interpreter and compiler will generate native code. Except that they how native code, which is the degree of optimization and cost optimization.
Interpreter
JVM
Explained through predefined by JVM
the instruction mapping machine instructions, almost every byte code instructions into corresponding native instructions. It bytecode executed directly, does not perform any optimization.
JIT compiler
To improve performance, JIT
the compiler and the runtime JVM
interaction, and the appropriate sequence of byte code compiled to native machine code. Typically, JIT
the compiler uses a code (first interpreter and a statement is not the same), optimized code, which is then converted to machine code optimization.
By default, JIT
the compiler is enabled. You can disable JIT
the compiler, in this case, the interpreter will explain the whole Java
process. In addition to diagnosing or resolving JIT
compilation issues, but does not recommend disabling JIT
compiler.
What is the JRE
Java
Runtime Environment ( JRE
) is a software package that will library ( jar
) and Java
Virtual Machine, and other components that are bundled together to run with Java
applications written. JRE
Only JVM
part of it.
To execute Java
the application only needs to be installed on your computer JRE
. This is executed on the computer Java
applications are minimum requirements.
JRE
It includes the following components -
- Java HotSpot client virtual machine to use DLL file.
- Java HotSpot Server Virtual Machine to use the DLL file.
- Code libraries used by the Java Runtime Environment, property settings, and resource files. For example rt.jar and charsets.jar.
- Java file extension, such as localedata.jar.
- It contains files used for security management. These include security policy (java.policy) and security properties (java.security) files.
- Jar file contains applet support classes.
- TrueType font file contains the platform for use.
JRE
As JDK
part of the download, a separate download. JRE
Platform-dependent. You can choose to import and install depending on the type of your computer (operating system and architecture) JRE
software package.
For example, you can not 32
install on your computer bit 64
position JRE
. Similarly, for Windows
the JRE
release version Linux
will not run. vice versa.
What is JDK
JDK
Than JRE
more comprehensive. JDK
It includes JRE
all sectors have and develop, debug and monitor for Java
application development tools. When the need to develop Java
an application, you need to JDK
.
JDK
Several important components shipped with the following:
- appletviewer - This tool can be used to run without a Web browser circumstances and debugging Java applet
- apt - annotation processing tool
- extcheck - JAR file utility for detecting conflicts
- javadoc - documentation generator, can automatically generate the document from the source code comments
- jar - archive program that the relevant class library packaged in a JAR file. The tool also helps manage JAR file
- jarsigner - jar signing and verification tools javap - class file disassembler
- Java Web Start JNLP launcher application - javaws
- JConsole - Java Monitoring and Management Console
- jhat - Java heap analysis tool
- jrunscript - Java command-line shell script
- jstack - Print Java Java thread stack trace utility
- keytool - key tool for operating the library
- policytool - policy creation and management tool
- xjc - XML Binding Java API (JAXB) API part. It accepts XML schema and generate Java classes
And JRE
the same JDK
is also dependent on the platform. Therefore, for your computer to download JDK
, please pay more attention when the package.
The difference between JDK, JRE and JVM
Based on the above discussion, we can draw the following relationship between these three
JRE = JVM libraries to run Java application.
JDK = JRE tools to develop Java Application.
In short, if you are writing code for Java
an application developer, you need to install on your computer JDK
. However, if you want to run with the Java
built-in applications, only needs to be installed on the computer JRE
.
JDK, JRE and JVM-related interview questions
If you understand what we've discussed in this article, then we face any interview questions are not difficult. However, still we have to be prepared to answer the following questions:
What is the JVM architecture
As already explained in detail before.
There are several types of Java class loader
Bootstrap
, extension
, Application class loader and a custom class loader.
How class loader is working in Java?
Class loader will scan its predefined location in jar
the file and the class. All those types of documents they scan path, and find the required classes. If you find them, load, and link initialization class files.
Jre difference and the jvm?
JVM
When you run a specification for running Java applications environment. Hotspot
JVM
Such an implementation is a specification. It loads the class file, and using an interpreter and a JIT
compiler to convert byte code into machine code and executed.
The difference between interpreter and jit compiler?
Progressive interpreter bytecode interpretation and execution order. This can cause performance degradation. JIT
Optimizing compiler to add a process for the analysis of the code blocks, and then prepare more optimized machine code.
JDK and JRE downloads
- JDK:https://www.oracle.com/technetwork/java/javase/downloads/index.html
- JRE https://www.oracle.com/technetwork/java/javase/downloads/server-jre8-downloads-2133154.html
??? attention to micro-channel public number java dry
from time to time information sharing Dry