java-coding-standards
Skill43 starsChanged 10 months agoMITView on GitHub
Spring Boot 服务的 Java 编码规范:命名、不可变性(Immutability)、Optional 使用、流(Streams)、异常处理、泛型(Generics)和项目布局。
17 other projects use a version of this, 10 of them edited.
Adopted by
Most recently taken up by
- Lukk17/agent-standardstheir own version, first seen Oct 5, 2026
- templetongroup/radianttheir own version, first seen Sep 17, 2026
- qingtiandamowang/alibaba-java-guidelines-skillstheir own version, first seen Aug 15, 2026
- SamuelNDCE/claude-super-skill-librarytheir own version, first seen Aug 1, 2026
- JunMystery/Agent-Guidance-Pythontheir own version, first seen Jul 21, 2026
- Snailclimb/AIGuidetheir own version, first seen Jul 7, 2026
Used with
Projects with it also use everything-claude-code, swift-protocol-di-testing and 4 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
InfopibeSkilleverything-claude-code
Also in 3 projects that use this
InfopibeSkillswift-protocol-di-testing
Protocol-based dependency injection for testable Swift code — mock file system, network, and external APIs using focused protocols and Swift Testing.
Also in 5 projects that use this
saxon-ySkillconfigure-ecc
Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.
Also in 5 projects that use this
- +3 more from Infopibe
Other versions17 projects use a version of this.
Word for word · 0
None found.
Edited · 10
- xu-xiang/everything-claude-code-zh★ 2k40% same
- loulanyue/awesome-claude-notes★ 27222% same
- tpavanipradeep/everything-claude-code★ 13422% same
- Jamkris/everything-gemini-code★ 8725% same
- FaisalAlqarni/sp-ecc★ 925% same
- Infopibe/everything-claude-code★ 822% same
- Lukasbrujula/claude-code-framework★ 425% same
- ashutoshrathi0909-oss/everything-claude-code★ 122% same
- royaluniondesign-sys/claude-os★ 122% same
- mryeastcode/ClaudeCode★ 022% same
Wrote their own version · 7
- Snailclimb/AIGuide★ 664same name
- templetongroup/radiant★ 113same name
- yanhaoluo0/AlibabaDevelopmentManualSkills★ 57same name
- JunMystery/Agent-Guidance-Python★ 2same name
- Lukk17/agent-standards★ 1same name
- qingtiandamowang/alibaba-java-guidelines-skills★ 1same name
- SamuelNDCE/claude-super-skill-library★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository30 other files it gives its agents.
- rules/agents.mdAGENTS.md
- examples/CLAUDE.mdCLAUDE.md
- oneskillSkill
- backend-patternsSkill
- clickhouse-ioSkill
- coding-standardsSkill
- continuous-learningSkill
- continuous-learning-v2Skill
- django-patternsSkill
- django-securitySkill
- django-tddSkill
- django-verificationSkill
- eval-harnessSkill
- frontend-patternsSkill
- golang-patternsSkill
- golang-testingSkill
- iterative-retrievalSkill
- jpa-patternsSkill
- postgres-patternsSkill
- project-guidelines-exampleSkill
- python-patternsSkill
- python-testingSkill
- security-reviewSkill
- springboot-patternsSkill
- springboot-securitySkill
- springboot-tddSkill
- springboot-verificationSkill
- strategic-compactSkill
- tdd-workflowSkill
- verification-loopSkill
The file
Files
Java 编码规范
适用于 Spring Boot 服务中易读、可维护的 Java (17+) 代码规范。
核心原则
- 清晰胜过奇巧
- 默认不可变(Immutable);尽量减少共享的可变状态
- 快速失败并抛出有意义的异常
- 保持一致的命名和包结构
命名
// ✅ 类(Classes)/ 记录(Records):大驼峰式(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;不可变性(Immutability)
// ✅ 优先使用记录(Records)和 final 字段
public record MarketDto(Long id, String name, MarketStatus status) {}
public class Market {
private final Long id;
private final String name;
// 仅提供 getter,不提供 setter
}Optional 使用
// ✅ find* 方法返回 Optional
Optional<Market> market = marketRepository.findBySlug(slug);
// ✅ 使用 map/flatMap 而不是 get()
return market
.map(MarketResponse::from)
.orElseThrow(() -> new EntityNotFoundException("Market not found"));流(Streams)最佳实践
// ✅ 使用流进行转换,保持流水线简短
List<String> names = markets.stream()
.map(Market::name)
.filter(Objects::nonNull)
.toList();
// ❌ 避免复杂的嵌套流;为了清晰起见,优先使用循环异常处理
- 领域错误使用非受检异常(Unchecked Exceptions);为技术异常包装上下文信息
- 创建领域特定的异常(例如
MarketNotFoundException) - 避免宽泛的
catch (Exception ex),除非是进行集中式重抛(Rethrow)或日志记录
throw new MarketNotFoundException(slug);泛型与类型安全
- 避免原始类型(Raw Types);声明泛型参数
- 可复用工具类优先使用有界泛型(Bounded Generics)
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 个空格(遵循项目标准)
- 每个文件仅包含一个公共顶层类型
- 保持方法简短且聚焦;提取辅助方法(Helper methods)
- 成员排序:常量、字段、构造函数、公共方法、受保护方法、私有方法
需避免的代码坏味道(Code Smells)
- 长参数列表 → 使用 DTO/构建器(Builders)
- 深层嵌套 → 尽早返回(Early returns)
- 魔法数字 → 具名常量
- 静态可变状态 → 优先使用依赖注入(Dependency Injection)
- 静默的 catch 块 → 记录日志并处理或重抛
日志记录
private static final Logger log = LoggerFactory.getLogger(MarketService.class);
log.info("fetch_market slug={}", slug);
log.error("failed_fetch_market slug={}", slug, ex);空值处理(Null Handling)
- 仅在不可避免时接受
@Nullable;否则使用@NonNull - 在输入上使用 Bean 校验(
@NotNull,@NotBlank)
测试预期
- 使用 JUnit 5 + AssertJ 进行流式断言(Fluent Assertions)
- 使用 Mockito 进行模拟(Mocking);尽可能避免部分模拟(Partial Mocks)
- 倾向于确定性测试;不要包含隐藏的 sleep 操作
记住:保持代码的意图清晰、类型安全且具有可观测性。除非证明有必要,否则应优先考虑可维护性而非微优化。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

