precipitation 、 Share 、 grow up , Let yourself and others have something to gain ！
One 、 Preface
As of now, it has been written 22 The manual of the book of the classics , How much did you see ？
In fact, brother Fu is talking about it under the guise of face Sutra
Java The core technology , Explore these core knowledge points, what are the questions behind the interview .
I want to ask some interviewers , It's because everyone is asking, so you ask , Or what do you want to ask from here ？ In fact, if many interviewers don't understand these techniques , Often will be the answer of the job seeker to break the heart , Ha ha ha ha ha ha . such as ：
Mason rotation algorithm 、
Open addressing 、
Fibonacci scattered 、
Heuristic cleanup 、
Javassist Agency mode 、
Disturbance function 、
Hash consistent wait .
remember , Let understand is really understand , Compare hydrology 、 It's much better to recite the answers ！ Um. , It's burning your brain sometimes ！
Two 、 Interview questions
Thank you plane , Notes ！, I don't know what happened , It always feels like an interview
Not very aggressive , But it's very insulting ！
interviewer ： Thank you for writing Java Do you ？
Thank you plane ： Of course it said , Yes 3 More than years ！
interviewer ： that ,
JVM What is the relationship between ？
Thank you plane ： Um. J J J,JDK There are JRE,JVM It's like JRE in ！？
interviewer ： that ,Client Pattern 、Server What is the pattern ？
Thank you plane ： Um. ！？ what ？
interviewer ： ok , Ask a simple question .JVM How it works ？ Did you recite the answer ？
Thank you plane ： bye , interviewer ！
3、 ... and 、JDK、JRE、JVM
1. Java Platform standards (JDK 8)
Oracle has two products that implement Java Platform Standard Edition (Java SE) 8: Java SE Development Kit (JDK) 8 and Java SE Runtime Environment (JRE) 8.
JDK 8 is a superset of JRE 8, and contains everything that is in JRE 8, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE 8 provides the libraries, the Java Virtual Machine (JVM), and other components to run applets and applications written in the Java programming language. Note that the JRE includes components not required by the Java SE specification, including both standard and non-standard Java components.
The following conceptual diagram illustrates the components of Oracle's Java SE products:
Description of Java Conceptual Diagram
About JDK、JRE、JVM What is the relationship between , stay Java Platform standards have clearly defined . That's the introduction part in English .
- Oracle There are two Java Platform standard products ,Java SE Development kit (JDK) and Java SE Runtime environment (JRE).
- JDK(Java Development Kit Java Development kit ),JDK Is provided to Java Used by developers , Which includes java Development tools , It also includes JRE. So it's installed JDK, No need to install it separately JRE 了 . The development tools include compiler tools (javac.exe) Packaging tools (jar.exe) etc. .
- JRE(Java Runtime Environment Java Running environment ) yes JDK Subset , That is to say, it includes JRE All contents , And the compiler and debugger tools needed to develop applications .JRE Provides a library 、Java virtual machine （JVM） And other components , Used to run the Java programing language 、 Applet 、 Applications .
- JVM(Java Virtual Machine Java virtual machine ),JVM Can be understood as a virtual computer , With the basic operation of the computer , It's mainly responsible for Java Program generated bytecode file , It's interpreted as machine instructions on a specific system platform , Let it run on all platforms .
Sum up , From this section of the official website platform standard introduction and concept map can be seen , We run the program JVM Yes, it has been installed to JDK in , It's just that you've been developing code for a long time , I didn't notice . The biggest reason I didn't notice was , I haven't developed some and JVM Related component code
About , various JDK Version of the platform standard , You can compare and learn by yourself , as follows ：
- Java SE 6 Documentation：https://docs.oracle.com/javase/6/docs/
- Java Platform Standard Edition 7 Documentation：https://docs.oracle.com/javase/7/docs/
- Java Platform Standard Edition 8 Documentation：https://docs.oracle.com/javase/8/docs/
2. JDK Directory structure and function
We install by default JDK There will be
jre1.8.0_45, Two folders . Actually in JDK There will be JRE Folder , Two of them JRE The structure of the folder is the same .
- bin： a pile EXE Executable file ,java.exe、javac.exe、javadoc.exe, Key management tools, etc .
- db： Built in Derby database , Small volume , Installation free .
- include：Java and JVM Interactive header file , For example, we JVMTI Written C++ Engineering time , You need to put this include Pack in
jvmti.h. for example ： be based on jvmti Design non intrusion monitoring
- jre：Java Running environment , Contains the executable files needed by the runtime , And what the runtime needs to rely on Java Class libraries and dynamic link libraries
- lib：Java Class library , for example dt.jar、tools.jar
that jvm In which folder ？
Maybe you haven't noticed before jvm So here it is ：C:\Program Files\Java\jdk1.8.0_45\jre\bin\server
- This part is the whole Java Realize the core content of cross platform , from Java Program compiled into .class The file will be executed on the virtual machine .
- In addition to JVM explain class File, you need to call the class library lib. stay JRE There are two folders in the directory lib、bin, and lib Namely JVM Class libraries needed to execute .
- jvm.dll You can't work on your own , When jvm.dll After starting , Will use explicit Method to load the auxiliary DLL and execute it together .
3. JDK What is it? ？
In conclusion, it is approved
Java Platform standards and
JDK Directory structure of ,JDK yes JRE Superset ,JDK Contains JRE All the development 、 Tools for debugging and monitoring applications . And the following important components ：
- java – Run the tool , function .class Bytecode
- javac– compiler , Name the suffix .java The source code is compiled into the suffix .class Bytecode
- javap – Decompiler
- javadoc – Document generator , Extract documents from source code annotations , The notes need to conform to the specification
- jar – Packaging tools , Package the relevant class files into a file
- jdb – debugger, Debugging tools
- jps – Show the current java The process state of the program running
- appletviewer – Operation and commissioning applet Program tools , No need to use a browser
- javah – from Java Class generation C Header files and C Source file . These documents provide bonding , send Java and C Code can interact .
- javaws – function JNLP Program
- extcheck – A test jar Package conflict tools
- apt – Annotation processing tools
- jhat – java Heap analysis tools
- jstack – Stack tracker
- jstat – JVM Testing statistical tools
- jstatd – jstat Daemon
- jinfo – Get running or crashing java Program configuration information
- jmap – obtain java Process memory mapping information
- idlj – IDL-to-Java compiler . take IDL Language is transformed into java file
- policytool – One GUI Policy file creation and management tool
- jrunscript – Command line script run
- appletviewer： Applet browser , An execution HTML On the paper Java Applet Java browser
4. JRE What is it? ？
JRE It's also a running in CPU Procedure on , Used to interpret execution Java Code .
It's usually like a work of implementation , It will be installed at the customer's site JRE, Because it's running Java The minimum requirements of the program .
- bin： Yes java.exe But there is no javac.exe. That is, it cannot be compiled Java Program , But it can run Java Program , You can put this bin The catalogue is interpreted as JVM.
- lib：Java Basics & The core library , contain JVM The class library and rt.jar. It also contains documents for security management , These files include security policies (security policy) And security properties (security properties) etc. .
5. JVM What is it? ？
In fact, to put it simply JVM Is to run Java The virtual machine of bytecode ,JVM It's a norm , Each supplier can realize itself JVM virtual machine . Just like Xiao Fu, he also follows the virtual machine specification and handwriting JVM The related books have realized , be based on Java Realized JVM virtual machine .
Source code address ：https://github.com/fuzhengwei/itstack-demo-jvm
Content abstract ： This code mainly introduces how to pass java Code to implement JVM The basic function of （ Search analytics class file 、 Bytecode command 、 Runtime data area, etc ）, So that java Programmers use the most familiar java Program , Study JVM How will java The program runs step by step .
Of course , We download Oracle The company's JVM Compared with what you've achieved , More advanced . Their design has an optimized memory model 、GC Recovery strategy 、 Adaptive optimizer, etc .
in addition ,JVM It's called a virtual machine , It's mainly because it's to achieve “write-once-run-anywhere”. It provides a running environment independent of the underlying operating system and machine hardware structure .
5.1 Client Pattern 、Server Pattern
stay JVM There are two different styles of startup modes in , Client Pattern 、Server Pattern .
- Client Pattern ： Load faster . Can be used to run GUI Interactive program .
- Server Pattern ： Loading is slow but running faster . Can be used to run server daemons .
Modify the configuration mode file ：
# List of JVMs that can be used as an option to java, javac, etc. # Order is important -- first in this list is the default JVM. # NOTE that this both this file and its format are UNSUPPORTED and # WILL GO AWAY in a future release. # # You may also select a JVM in an arbitrary location with the # "-XXaltjvm=<jvm_dir>" option, but that too is unsupported # and may not be available in a future release. # -server KNOWN -client IGNORE
- If you need to adjust , You can put client Set to KNOWN, And adjust to server front .
- JVM Default in Server In mode ,-Xms128M、-Xmx1024M
- JVM Default in Client In mode ,-Xms1M、-Xmx64M
5.2 JVM Structure and actuator
This part belongs to JVM The core knowledge of , But it's not the point of this article , It will be mentioned in the following chapters . This chapter only makes some introduction .
- Class Loader： Class loader is a subsystem used to load class files , It has three main functions ：loading( load ）,linking（ link ）,initialization（ initialization ）.
- JVM Memory Areas： Method area 、 Heap area 、 The stack area 、 Program counter .
- Interpreter( Interpreter )： By looking for predefined JVM Instruction to machine instruction mapping ,JVM The interpreter can convert each bytecode instruction into the corresponding local instruction . It directly executes bytecode , No optimizations .
- JIT Compiler( Just in time compiler )： In order to improve efficiency ,JIT Compiler At runtime with JVM Interaction , And properly compile the bytecode sequence into local machine code . Typically ,JIT Compiler Execute a piece of code , Not one sentence at a time . Optimize this code , And translate it into optimized machine code .JIT Compiler It's on by default
Four 、 summary
- The knowledge of this article is not complicated , The interview content involved is also less , What's more, we'll talk about JVM An introduction to the interview , Make a preparation for the following content .
- If you haven't paid attention to JDK、JRE、JVM The structure and corresponding component configuration and execution mode of , Then you can continue to learn on this basis to deepen your impression . In addition, I want to further study JVM It's not easy , We have to learn JVM Norms should also be applied in practice , So it's recommended to write first JVM, And then it is verified by practice JVM.
- Okay , This is where this chapter goes . These knowledge points can be shared with you , It's also my own learning 、 Included 、 Arrangement 、 The process of verification . learn from each other 、 Grow up with each other , If there are mistakes , Leave me a message , I will continue to correct . Make progress together ！
5、 ... and 、 Series recommendation
- HashMap Core knowledge , Disturbance function 、 Load factor 、 Split the expanded list
- ArrayList So much knowledge ？ A designated position will make Xie plane faint ！
- except JDK、CGLIB, also 3 Types of agency ？ Interview stuck again ！
- ReentrantLock The fair lock explains and realizes
- Introduction and use of thread pool , And based on jvmti Design non intrusion monitoring