Home  >  Article  >  Java  >  Share graphic examples about mechanisms in Java

Share graphic examples about mechanisms in Java

零下一度
零下一度Original
2017-07-18 14:34:571189browse

A picture is always worth a million words!

I hope this article can help you review the knowledge you already know. If the picture doesn't explain it clearly enough, you may need to read the detailed article or search.

1. The immutable characteristics of String objects

The following figure shows the process of running the following code:

String s = "abcd";  
s = s.concat("ef");

Chinese reference: Java String Detailed Explanation

##2. Equals() and hashCode() method collaboration agreement

HashCode(ha Hash code, hash code) is designed to improve performance.

The relationship between the equals() and hashCode() methods can be summarized as:
2.1 If two objects are equal (equal), then they must Have the same hash code(hash code)
2.2 Even if two objects have the same hash value(hash code), they are not necessarily equal.
Chinese Reference: Implementation Principle of HashMap


3. Java exception class hierarchyThe pink ones are checked exceptions (checked exceptions), which must be tried{} Caught by the catch statement block, or declared through the throws clause in the method signature.
Another type of exception is runtime exceptions (runtime exceptions), which require the programmer to analyze the code to decide whether to catch and handle it.
Those declared as Error are serious errors and require special processing based on business information. Error does not need to be captured.
Chinese example: Exception



4. Collection class hierarchy relationshipPay attention to Collections (tool class) and Collection (collection top-level interface ) difference:
Chinese reference: Collections

##5. Lock ——The basic idea of ​​Java synchronization
Java synchronization (synchronization) mechanism can be compared with a building:Chinese reference: Thread synchronization---synchronized



6.Java object reference processing mechanism
Alias ​​refers to multiple references pointing to the same memory address (the actual address of the object, which can be understood as the object), and even the names of these references The types are completely different.

7. The memory structure of Java objects in the heap
The following figure shows the operation The location of methods and objects in memoryIn most cases: objects (and their attribute fields) are stored in the heap, while method parameters, local variables (references, and 6 basic types) are stored in Inside the stack.
Of course, under very special circumstances (extreme optimization [object push], constant pool [String], static variable [method area], etc.), this unspoken rule will be broken.


8. JVM runtime data area

The following figure shows the overall data area of ​​the JVM (Java Virtual Machine) runtime Division

The above is the detailed content of Share graphic examples about mechanisms in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn