java-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesejava-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 (LVTI) where readable, Records for DTOs, and Pattern Matching for
varandinstanceof.switch - Concurrency: Prefer Virtual Threads (in Quarkus or
@RunOnVirtualThread) over traditional Thread Pools for I/O-bound tasks.Executors.newVirtualThreadPerTaskExecutor() - Immutability: Use ,
recordfields, andfinalcollections (unmodifiable,List.of).Map.of - Functional Style: Leverage Streams, , and Functional Interfaces to reduce boilerplate and side effects.
Optional - Visibility: Default to or
package-private. Onlyprivatewhat must be exposed (API/SPI).public
- 优先使用Java 21+: 在可读性允许的情况下强制使用(LVTI),用Records实现DTO,以及在
var和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 instead of
StringBuilderin 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 ; always use a logger (SLF4J/Logback).
System.out.println() - Prefer design for testability.
Interface-based - Use to define closed hierarchy types for better exhaustiveness checking in
Sealed Classes.switch
- 避免使用;始终使用日志框架(SLF4J/Logback)。
System.out.println() - 优先采用基于接口的设计以提升可测试性。
- 使用定义封闭层次类型,以在
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框架。