java-coding-standards
适用于 Spring Boot 服务的 Java 编码规范:命名、不可变性、Optional 使用、流(Stream)、异常、泛型及项目布局。
Best use case
java-coding-standards is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. 适用于 Spring Boot 服务的 Java 编码规范:命名、不可变性、Optional 使用、流(Stream)、异常、泛型及项目布局。
适用于 Spring Boot 服务的 Java 编码规范:命名、不可变性、Optional 使用、流(Stream)、异常、泛型及项目布局。
Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.
Practical example
Example input
Use the "java-coding-standards" skill to help with this workflow task. Context: 适用于 Spring Boot 服务的 Java 编码规范:命名、不可变性、Optional 使用、流(Stream)、异常、泛型及项目布局。
Example output
A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.
When to use this skill
- Use this skill when you want a reusable workflow rather than writing the same prompt again and again.
When not to use this skill
- Do not use this when you only need a one-off answer and do not need a reusable workflow.
- Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/java-coding-standards/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How java-coding-standards Compares
| Feature / Agent | java-coding-standards | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
适用于 Spring Boot 服务的 Java 编码规范:命名、不可变性、Optional 使用、流(Stream)、异常、泛型及项目布局。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
SKILL.md Source
# Java 编码规范
适用于 Spring Boot 服务中易读且可维护的 Java (17+) 代码标准。
## 核心原则
- 清晰度优先于巧妙性
- 默认不可变;最小化共享的可变状态
- 抛出有意义的异常以实现早期失败(Fail fast)
- 一致的命名与包结构
## 命名
```java
// ✅ 类/记录(Record): PascalCase
public class MarketService {}
public record Money(BigDecimal amount, Currency currency) {}
// ✅ 方法/字段: camelCase
private final MarketRepository marketRepository;
public Market findBySlug(String slug) {}
// ✅ 常量: UPPER_SNAKE_CASE
private static final int MAX_PAGE_SIZE = 100;
```
## 不可变性
```java
// ✅ 优先使用 record 和 final 字段
public record MarketDto(Long id, String name, MarketStatus status) {}
public class Market {
private final Long id;
private final String name;
// 仅有 getter,没有 setter
}
```
## Optional 的使用
```java
// ✅ find* 方法返回 Optional
Optional<Market> market = marketRepository.findBySlug(slug);
// ✅ 使用 map/flatMap 代替 get()
return market
.map(MarketResponse::from)
.orElseThrow(() -> new EntityNotFoundException("Market not found"));
```
## 流(Stream)最佳实践
```java
// ✅ 使用流进行转换,保持流水线(Pipeline)简洁
List<String> names = markets.stream()
.map(Market::name)
.filter(Objects::nonNull)
.toList();
// ❌ 避免复杂的嵌套流;为了清晰起见,优先使用循环
```
## 异常
- 对于领域错误(Domain errors)使用非检查异常(Unchecked Exceptions);使用上下文包装技术异常
- 创建领域特定的异常(例如:`MarketNotFoundException`)
- 避免捕获过于宽泛的 `catch (Exception ex)`(除非在中心位置重新抛出或记录日志)
```java
throw new MarketNotFoundException(slug);
```
## 泛型与类型安全
- 避免使用原始类型(Raw types);声明泛型参数
- 优先在可重用的工具类中使用受限泛型(Bounded Generics)
```java
public <T extends Identifiable> Map<Long, T> indexById(Collection<T> items) { ... }
```
## 项目结构 (Maven/Gradle)
```
src/main/java/com/example/app/
config/
controller/
service/
repository/
domain/
dto/
util/
src/main/resources/
application.yml
src/test/java/... (镜像 main 目录)
```
## 格式与样式
- 始终一致地使用 2 或 4 个空格(遵循项目标准)
- 每个文件仅包含一个 public 顶级类型
- 保持方法短小且专注;提取助手方法(Helper methods)
- 成员顺序:常量、字段、构造函数、public 方法、protected、private
## 应避免的代码异味 (Code Smells)
- 过长的参数列表 -> 使用 DTO 或建造者模式(Builder)
- 过深的嵌套 -> 使用早期返回(Early Return)
- 魔术数字 -> 使用命名常量
- 静态可变状态 -> 优先使用依赖注入(Dependency Injection)
- 沉默的 catch 块 -> 记录日志并采取行动,或者重新抛出
## 日志记录
```java
private static final Logger log = LoggerFactory.getLogger(MarketService.class);
log.info("fetch_market slug={}", slug);
log.error("failed_fetch_market slug={}", slug, ex);
```
## Null 处理
- 仅在万不得已时接受 `@Nullable`;否则使用 `@NonNull`
- 对输入使用 Bean 校验(Bean Validation,如 `@NotNull`、`@NotBlank`)
## 测试预期
- JUnit 5 + AssertJ 实现流式断言(Fluent Assertions)
- 使用 Mockito 进行打桩;尽可能避免使用部分打桩(Partial mocks)
- 优先选择确定性测试;严禁隐藏的 `sleep`
**记住**:保持代码的意图清晰、类型安全且可观测。除非证明确有必要,否则应优先优化可维护性而非微小的性能优化。Related Skills
cpp-coding-standards
基于C++核心指南(isocpp.github.io)的C++编码标准。在编写、审查或重构C++代码时使用,以强制实施现代、安全和惯用的实践。
coding-standards
适用于 TypeScript、JavaScript、React 和 Node.js 开发的通用编码标准、最佳实践与模式。
plankton-code-quality
使用 Plankton 实现编写时代码质量强制执行 —— 通过钩子在每次文件编辑时进行自动格式化、代码检查,并由 Claude 驱动自动修复。
autonomous-loops
自主运行 Claude Code 循环的模式与架构 —— 从简单的顺序流水线到 RFC 驱动的多智能体 DAG 系统。
visa-doc-translate
将签证申请文件(图片)翻译成英文,并创建包含原文和译文的双语PDF
swiftui-patterns
SwiftUI 架构模式,使用 @Observable 进行状态管理,视图组合,导航,性能优化,以及现代 iOS/macOS UI 最佳实践。
swift-protocol-di-testing
基于协议的依赖注入,用于可测试的Swift代码——使用聚焦协议和Swift Testing模拟文件系统、网络和外部API。
swift-concurrency-6-2
Swift 6.2 可接近的并发性 — 默认单线程,@concurrent 用于显式后台卸载,隔离一致性用于主 actor 类型。
swift-actor-persistence
在 Swift 中使用 actor 实现线程安全的数据持久化——基于内存缓存与文件支持的存储,通过设计消除数据竞争。
skill-stocktake
用于审计Claude技能和命令的质量。支持快速扫描(仅变更技能)和全面盘点模式,采用顺序子代理批量评估。
search-first
研究优先于编码的工作流程。在编写自定义代码之前,搜索现有的工具、库和模式。调用研究员代理。
regex-vs-llm-structured-text
选择在解析结构化文本时使用正则表达式还是大型语言模型的决策框架——从正则表达式开始,仅在低置信度的边缘情况下添加大型语言模型。