Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Java

Project Jigsaw trong Java 9 là gì?

Mục tiêu chính của Project Jigsaw: Mang tính modularity vào Java 9 và áp dụng cho JDK.

Lợi ích của Modularity (Jigsaw)

Các JEP (JDK Enhancement Proposal) của Jigsaw

Lợi íchMô tả
Strong EncapsulationModule chỉ truy cập phần được export rõ ràng trong module-info.java. Public class trong package không export → không public bên ngoài.
Clear DependenciesModule khai báo phụ thuộc qua requires. Kết hợp module tạo runtime nhỏ gọn, scale xuống thiết bị nhỏ dễ dàng.
Reliable ConfigurationLoại bỏ runtime error do thiếu class (ClassNotFoundException, NoClassDefFoundError). Phát hiện lỗi dependency ở compile-time/link-time.

Kiến trúc Module System

Application Modules (app code)
    ↓ requires
Platform Modules (java.*, jdk.*)
    ↓
java.base (foundation module - implicit requires)

Tác động

  • JDK 9+: rt.jar, tools.jar không còn – thay bằng jmod files / jimage.
  • Classpath → Module-path cho modular app.
  • Internal API (sun.misc.Unsafe, com.sun.*) bị encapsulate – migration cần thiết.
  • Custom JRE cho microservice, container, IoT.

Project Jigsaw là thay đổi lớn nhất từ Java 5, định hình Java hiện đại: modular, secure, scalable.

JEPTênMô tả
JEP 200Modular JDKDùng JPMS module hóa JDK thành tập module kết hợp tại build/compile/runtime.
JEP 201Modular Source CodeModule hóa source code JDK, nâng cấp build tools compile module.
JEP 220Modular Run-Time ImagesRestructure JRE/JDK runtime images cho module, cải thiện security, performance, maintainability.
JEP 260Encapsulate Most Internal APIsChặn truy cập internal API (sun.misc...). Chỉ internal API quan trọng vẫn khả dụng qua module.
JEP 261Module SystemTriển khai module system spec: thay đổi JVM, Java language, standard APIs.
JEP 282JLink: The Java LinkerĐóng gói module + dependencies thành custom runtime nhỏ gọn.