java tutorial series two: Java JDK, JRE and JVM are what?

Passionate Court only spring months, according to Utah for the falling away from the people.

Here Insert Picture Description

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.

  1. We use the editor Simple.Javato write the source code file.
  2. It must be compiled into bytecode program. Compiler ( javac) compiling the source code for the Simple.classfile.
  3. This suffix .classclass files at any platform / operating system JVM( Javavirtual machine) execution.
  4. JVMIt is responsible for converting the byte code to native machine code executable by the machine.

Here Insert Picture Description

What is JVM?

JavaVirtual Machine ( JVM) is running Javabytecode virtual machine. By javaxthe .javafile compiled .classfiles. .classFile contains JVMresolvable bytecode.

In fact, JVMjust to Javaprovide a runtime environment and specification byte code. Different manufacturers offer different implementations of this specification. For example, this Wikipage lists the other JVM implementations .

The most popular JVMvirtual machine is Oracleprovided by Hostspota virtual machine, (formerly known as Sun Microsystems,Inc.).

JVMVirtual machine uses a lot of advanced technology, combined with the latest memory model, garbage collector and adaptive optimizer, to Javaprovide the best performance of the application.

JVMThe virtual machine has two different modes, clientmode and servermode. Despite serverand clientsimilar, but serverhas 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 -clientor -serverto select the desired mode.

JVMIt is called a virtual machine, because it provides APIdoes not depend on the underlying operating system and hardware architecture of the machine. This hardware and operating system independence with a Javaprogram write once, run anywhere necessary foundation.

JVM architecture

Here Insert Picture Description

Class loader

Class loader is used to load the class files into JVMthe. Divided into the following three steps to load, and link initialization.

  1. load
  • In order to load the class, JVMthere are three types loader. Bootstrap, extensionAnd application class loader.
  • When loading class files, JVMyou 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.
  • BootstrapIt is the root class loader, Bootstraploader tries to find the class. It scans the JRE libfolder rt.jar.
  • If you can not find the class, then the extensionloader will jre \ lib \ extsearch for class files package.
  • If you can not find a class, the application class loader system will CLASSPATHsearch all environment variables Jar files and classes
  • Any class loader finds the class, by the class loader loads the class; otherwise throw ClassNotFoundException.
  1. 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.
  2. 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

JVMThe 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 JVMstack, 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 JVMall 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.

Here Insert Picture Description

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

JVMExplained through predefined by JVMthe 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, JITthe compiler and the runtime JVMinteraction, and the appropriate sequence of byte code compiled to native machine code. Typically, JITthe 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, JITthe compiler is enabled. You can disable JITthe compiler, in this case, the interpreter will explain the whole Javaprocess. In addition to diagnosing or resolving JITcompilation issues, but does not recommend disabling JITcompiler.

What is the JRE

JavaRuntime Environment ( JRE) is a software package that will library ( jar) and JavaVirtual Machine, and other components that are bundled together to run with Javaapplications written. JREOnly JVMpart of it.

To execute Javathe application only needs to be installed on your computer JRE. This is executed on the computer Javaapplications are minimum requirements.

JREIt includes the following components -

  1. Java HotSpot client virtual machine to use DLL file.
  2. Java HotSpot Server Virtual Machine to use the DLL file.
  3. Code libraries used by the Java Runtime Environment, property settings, and resource files. For example rt.jar and charsets.jar.
  4. Java file extension, such as localedata.jar.
  5. It contains files used for security management. These include security policy (java.policy) and security properties (java.security) files.
  6. Jar file contains applet support classes.
  7. TrueType font file contains the platform for use.

JREAs JDKpart of the download, a separate download. JREPlatform-dependent. You can choose to import and install depending on the type of your computer (operating system and architecture) JREsoftware package.

For example, you can not 32install on your computer bit 64position JRE. Similarly, for Windowsthe JRErelease version Linuxwill not run. vice versa.

What is JDK

JDKThan JREmore comprehensive. JDKIt includes JREall sectors have and develop, debug and monitor for Javaapplication development tools. When the need to develop Javaan application, you need to JDK.

JDKSeveral 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 JREthe same JDKis 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.

Here Insert Picture Description

In short, if you are writing code for Javaan application developer, you need to install on your computer JDK. However, if you want to run with the Javabuilt-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 jarthe 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?

JVMWhen you run a specification for running Java applications environment. Hotspot JVMSuch an implementation is a specification. It loads the class file, and using an interpreter and a JITcompiler 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. JITOptimizing compiler to add a process for the analysis of the code blocks, and then prepare more optimized machine code.

JDK and JRE downloads


Here Insert Picture Description

??? attention to micro-channel public number java dry
from time to time information sharing Dry

原文链接:What is Java JDK, JRE and JVM – In-depth Analysis

Published 112 original articles · won praise 90 · Views 350,000 +

Guess you like

Origin blog.csdn.net/dandandeshangni/article/details/101287026