Java Core¶
1. Java Virtual Machine (JVM)¶
Java虚拟机(JVM)
- The JVM is the cornerstone of Java technology, enabling Java programs to be platform-independent. The JVM converts compiled Java bytecode (.class files) into machine code and executes it at runtime. The JVM is responsible for memory management, garbage collection, and performance optimization.
- JVM是Java技术的基石,它使得Java程序具有跨平台的能力。JVM将编译后的Java字节码(.class文件)转换为机器代码并在运行时执行。JVM负责内存管理、垃圾收集和性能优化等关键任务。
2. Java Programming Language¶
Java编程语言
- Java is an object-oriented programming language known for its simplicity, portability, security, and efficiency. It supports the four fundamental principles of Object-Oriented Programming (OOP): Encapsulation, Inheritance, Polymorphism, and Abstraction. Java is widely used in enterprise applications, mobile development, big data, and embedded systems.
- Java是一种面向对象的编程语言,具有简洁、可移植、安全和高效的特点。它支持面向对象编程(OOP)的四大基本原则:封装、继承、多态和抽象。Java广泛应用于企业级应用、移动开发、大数据、嵌入式系统等领域。
3. Java Standard Library (Java API)¶
Java标准类库(Java API)
- The Java Standard Library is a foundational library used by Java developers, covering a wide range of functionalities such as Collections Framework, Input/Output (I/O), Networking, Concurrency, and Database Connectivity (JDBC). The standard library greatly enhances development efficiency and code reusability.
- Java标准类库是Java开发者使用的基础库,涵盖了广泛的功能模块,如集合框架(Collections Framework)、输入输出(I/O)、网络编程(Networking)、并发(Concurrency)、数据库连接(JDBC)等。标准类库极大地提高了开发效率和代码的可重用性。
4. Java Platform¶
Java平台
- The Java platform consists of multiple editions, each providing different APIs and tools for various application scenarios:
- Java SE (Standard Edition): For desktop applications and general-purpose programming.
- Java EE (Enterprise Edition): Targeted at enterprise application development, providing components like Servlets, JSP, and EJB for building distributed, multi-tier applications.
- Java ME (Micro Edition): Aimed at embedded systems and mobile devices, offering a streamlined API.
- Java平台由多个版本组成,针对不同应用场景提供不同的API和工具:
- Java SE (Standard Edition): 用于桌面应用和通用编程。
- Java EE (Enterprise Edition): 针对企业级应用开发,提供了如Servlets、JSP、EJB等组件,用于构建分布式、多层应用。
- Java ME (Micro Edition): 针对嵌入式系统和移动设备的开发,提供了精简的API。
5. Java Development Tools¶
Java开发工具
- Java development tools include the compiler (javac), runtime environment (java), debugger (jdb), and documentation generator (javadoc). Additionally, popular Integrated Development Environments (IDEs) like Eclipse, IntelliJ IDEA, and NetBeans significantly enhance development productivity.
- Java开发工具包括编译器(javac)、运行时环境(java)、调试器(jdb)、文档生成器(javadoc)等。此外,开发者常用的IDE(集成开发环境)如Eclipse、IntelliJ IDEA、NetBeans也极大地提升了开发效率。
6. JVM Garbage Collection¶
JVM垃圾收集
- Garbage collection is a core mechanism of the JVM for managing memory, automatically reclaiming objects that are no longer in use to free up memory. The JVM provides various garbage collectors, such as Serial GC, Parallel GC, CMS (Concurrent Mark-Sweep) GC, and G1 (Garbage-First) GC, each suited for different application scenarios.
- 垃圾收集是JVM管理内存的核心机制,它自动回收不再使用的对象以释放内存。JVM提供了多种垃圾收集器,如Serial GC、Parallel GC、CMS(Concurrent Mark-Sweep)GC和G1(Garbage-First)GC,分别适用于不同的应用场景。
7. Java Multithreading and Concurrency¶
Java多线程与并发
- Java provides built-in thread support and a rich set of concurrency utilities (such as the
java.util.concurrent
package), allowing developers to easily create multithreaded applications. Java's thread synchronization mechanisms (like thesynchronized
keyword andReentrantLock
class) and advanced concurrency tools (like thread pools and blocking queues) help build efficient and thread-safe applications. - Java通过内置的线程支持和丰富的并发工具类(如
java.util.concurrent
包),使得开发者可以方便地开发多线程应用。Java的线程同步机制(如synchronized
关键字、ReentrantLock
类)和高级并发工具(如线程池、阻塞队列)有助于构建高效、线程安全的应用程序。
8. Java Memory Model (JMM)¶
Java内存模型(Java Memory Model, JMM)
- The Java Memory Model defines the visibility of variables and the interaction between threads in a Java program. The JMM ensures memory consistency in a multithreaded environment, preventing data race issues. Key concepts include the
volatile
keyword, instruction reordering, and memory barriers. - Java内存模型定义了Java程序中变量的可见性和线程之间的交互方式。JMM确保了在多线程环境下内存的一致性,避免了数据竞争问题。关键概念包括
volatile
关键字、指令重排序、内存屏障等。
9. Java Reflection¶
Java反射
- Java Reflection allows for inspecting and manipulating classes, methods, fields, and other structures at runtime, enhancing the dynamic nature and flexibility of programs. Reflection is commonly used in framework development, dependency injection, and proxy patterns for advanced use cases.
- Java反射机制允许在运行时检查和操作类、方法、字段等结构,增强了程序的动态性和灵活性。反射通常用于框架开发、依赖注入、代理模式等高级应用场景。
10. Java Serialization¶
Java序列化
- Java Serialization allows converting an object's state into a byte stream, enabling object persistence, network transmission, and other functionalities. Java supports serialization through the
Serializable
interface and offers the ability to customize serialization processes. - Java序列化机制允许将对象的状态转换为字节流,从而实现对象的持久化、网络传输等功能。Java通过
Serializable
接口支持序列化,同时提供了自定义序列化的能力。
11. Java Generics¶
Java泛型
- Java Generics allow the definition of classes, interfaces, and methods with type parameters, making code more general and type-safe. Generics are widely used in the Collections Framework and other libraries, reducing runtime type casting errors.
- Java泛型机制允许定义具有类型参数的类、接口和方法,使得代码更加通用和类型安全。泛型广泛应用于集合框架和其他类库中,减少了运行时的类型转换错误。
12. Java Security¶
Java的安全性
- The Java platform includes robust security mechanisms, such as the sandbox model of the class loader, bytecode verification, encryption APIs, access control, code signing, and Role-Based Access Control (RBAC). These features make Java an ideal choice for developing secure applications.
- Java平台内置了强大的安全机制,包括类加载器的沙箱模型、字节码验证、加密API、访问控制、代码签名和基于角色的访问控制(RBAC)。这些特性使Java成为开发安全应用程序的理想选择。
13. Java Streams and I/O¶
Java的流(Streams)与I/O
- Java provides a rich set of Input/Output (I/O) functionalities, including file operations, network programming, byte streams, and character streams. The Stream API introduced in Java 8 offers a declarative way to process collections, supporting parallel streams, filtering, mapping, and reduction operations, greatly simplifying data processing code.
- Java提供了丰富的输入输出(I/O)功能,包括文件操作、网络编程、字节流和字符流处理。Java 8引入的Stream API则提供了对集合类的声明式处理方式,支持并行流、过滤、映射和归约操作,极大地简化了数据处理的代码。