编者注:本文为历史博文归档;涉及 JDK、框架与工具链版本请以当前官方文档为准。引用外链图片可能失效,阅读时请注意时效性。

Introduction

They say a diagram is worth a thousand words. The following diagrams are curated from the Java tutorials on Program Creek and represent the most voted content to date. Hopefully, they will help you review core concepts you already know. If a concept is not entirely clear from the diagram itself, you may want to visit the corresponding article for a deeper look.

1. String Immutability

The following diagram illustrates what happens when executing the code below:

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

String Immutability Diagram

2. The equals() and hashCode() Contract

The hashCode() method is designed to improve performance. The contract between equals() and hashCode() is defined as follows:

  1. If two objects are equal, then they must have the same hash code.
  2. If two objects have the same hash code, they may or may not be equal.

Java HashCode Contract

3. Java Exception Class Hierarchy

In the hierarchy diagram, items colored in red represent checked exceptions, which must either be caught or declared in the method's throws clause.

Exception Hierarchy Diagram

4. Collections Class Hierarchy

Please note the distinction between the Collections utility class and the Collection interface.

Collection Vs Collections

Java Collection Hierarchy

5. Java Synchronization

The Java synchronization mechanism can be illustrated by an analogy to a building monitor.

Java Monitor

6. Aliasing

Aliasing occurs when there are multiple references (aliases) to a memory location that can be updated, and these aliases may have different types.

Java Aliasing

7. Stack and Heap

This diagram demonstrates where methods and objects reside in run-time memory.

Java Array in Memory

8. JVM Run-Time Data Areas

This diagram provides an overview of the JVM run-time data areas.

JVM Runtime Data Area


说明:本文内容基于历史资料整理,部分图示可能未涵盖 Java 最新版本(如 Java 9+ 模块化机制或新版 GC 特性)的变更,请以官方最新文档为准。