java-expert

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

java-expert

java-expert

Keyword: java | Platforms: gemini,claude,codex
High-Performance Modern Java Expert Skill - Specialized in Java 21+ and cloud-native architecture.
关键词:java | 支持平台:gemini、claude、codex
高性能现代Java专家技能 - 专注于Java 21+和云原生架构。

Core Mandates

核心要求

  • Java 21+ First: Mandate
    var
    (LVTI) where readable, Records for DTOs, and Pattern Matching for
    instanceof
    and
    switch
    .
  • Concurrency: Prefer Virtual Threads (
    @RunOnVirtualThread
    in Quarkus or
    Executors.newVirtualThreadPerTaskExecutor()
    ) over traditional Thread Pools for I/O-bound tasks.
  • Immutability: Use
    record
    ,
    final
    fields, and
    unmodifiable
    collections (
    List.of
    ,
    Map.of
    ).
  • Functional Style: Leverage Streams,
    Optional
    , and Functional Interfaces to reduce boilerplate and side effects.
  • Visibility: Default to
    package-private
    or
    private
    . Only
    public
    what must be exposed (API/SPI).
  • 优先使用Java 21+: 在可读性允许的情况下强制使用
    var
    (LVTI),用Records实现DTO,以及在
    instanceof
    switch
    中使用模式匹配。
  • 并发处理: 对于I/O密集型任务,优先使用Virtual Threads(Quarkus中的
    @RunOnVirtualThread
    Executors.newVirtualThreadPerTaskExecutor()
    )而非传统线程池。
  • 不可变性: 使用
    record
    final
    字段和不可修改集合(
    List.of
    Map.of
    )。
  • 函数式风格: 利用Streams、
    Optional
    和函数式接口减少样板代码和副作用。
  • 可见性: 默认使用包私有或私有访问修饰符。仅对外暴露必须公开的内容(API/SPI)。

Architectural Patterns

架构模式

Hexagonal / Clean Architecture

六边形架构/整洁架构

  • Domain: Pure Java, zero external dependencies (no Quarkus/Spring in domain classes).
  • Ports (Interfaces): Define input (Use Cases) and output (Repositories, Gateways) interfaces.
  • Adapters: Infrastructure implementations (Quarkus/Hibernate/REST) reside outside the domain.
  • 领域层: 纯Java实现,无外部依赖(领域类中不引入Quarkus/Spring)。
  • 端口(接口): 定义输入(用例)和输出(仓库、网关)接口。
  • 适配器: 基础设施实现(Quarkus/Hibernate/REST)位于领域层之外。

Performance & Memory

性能与内存

  • Garbage Collection: Favor G1GC for typical workloads or ZGC for ultra-low latency (<1ms).
  • Memory Management: Minimize object allocation in hot loops. Use
    StringBuilder
    instead of
    +
    in loops.
  • Profiling: Use JFR (Java Flight Recorder) for production-safe profiling and bottleneck analysis.
  • 垃圾回收: 典型工作负载优先选择G1GC,超低延迟场景(<1ms)优先选择ZGC
  • 内存管理: 减少热循环中的对象分配。在循环中使用
    StringBuilder
    替代
    +
    拼接字符串。
  • 性能分析: 使用JFR (Java Flight Recorder) 进行生产环境安全的性能分析和瓶颈排查。

Testing Strategy

测试策略

  • JUnit 5 & AssertJ: The industry standard for fluent, readable assertions.
  • Mockito: Deep stubbing and spying for complex dependencies.
  • ArchUnit: Enforce architectural rules (e.g., "Domain must not depend on Infrastructure").
  • Testcontainers: Real-world integration testing for databases (PostgreSQL, MySQL) and brokers (Kafka, Redis).
  • JUnit 5 & AssertJ: 行业标准的流畅、易读断言库。
  • Mockito: 用于复杂依赖的深度存根和间谍测试。
  • ArchUnit: 强制执行架构规则(例如“领域层不得依赖基础设施层”)。
  • Testcontainers: 针对数据库(PostgreSQL、MySQL)和消息中间件(Kafka、Redis)的真实集成测试。

Bytecode & Classloading

字节码与类加载

  • Jandex: Understand Jandex indexing for Quarkus's fast annotation scanning.
  • Bytecode Manipulation: Familiarity with ASM or ByteBuddy for runtime/build-time enhancement.
  • ClassLoader Isolation: Debugging issues related to "parent-first" vs "child-first" delegation.
  • Jandex: 理解Jandex索引在Quarkus快速注解扫描中的作用。
  • 字节码操作: 熟悉ASM或ByteBuddy用于运行时/构建时增强。
  • 类加载器隔离: 排查“父优先”与“子优先”委托机制相关的问题。

Expert Tips

专家建议

  • Avoid
    System.out.println()
    ; always use a logger (SLF4J/Logback).
  • Prefer
    Interface-based
    design for testability.
  • Use
    Sealed Classes
    to define closed hierarchy types for better exhaustiveness checking in
    switch
    .
  • 避免使用
    System.out.println()
    ;始终使用日志框架(SLF4J/Logback)。
  • 优先采用基于接口的设计以提升可测试性。
  • 使用
    Sealed Classes
    定义封闭层次类型,以在
    switch
    中实现更完善的穷尽性检查。

References

参考资料

Skill Interoperability

技能互操作性

The java-expert ☕ skill provides the foundational language expertise (JDK 21+, Virtual Threads) required by:
  • vertx-expert 🌀: Uses modern Java for high-performance reactive programming.
  • quarkus-expert ⚡: Leverages the JVM features for the Quarkus framework.
java-expert ☕技能提供了以下技能所需的基础语言专业知识(JDK 21+、Virtual Threads):
  • vertx-expert 🌀:利用现代Java实现高性能响应式编程。
  • quarkus-expert ⚡:借助JVM特性适配Quarkus框架。