java-clean-code
Skill1 starsChanged 7 months agoMITView on GitHub
Use when writing, reviewing, or refactoring Java code — services, controllers, libraries, batch jobs, CLIs (Spring Boot, Quarkus, plain Java). Triggers: "clean this up", "is this idiomatic?", code review on Java files, code-smell or technical-debt concerns, SOLID/DRY/SRP questions, TDD setup for Java.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- CasLubbers/code-design-skillstheir own version, first seen Aug 25, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- CasLubbers/code-design-skills★ 2same 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 repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
Files
Java Clean Code
Overview
20 high-ROI rules for Java, with topic references for depth. Same checklist for writing, reviewing, and refactoring.
When to Apply
Writing, reviewing, or refactoring Java classes/methods/endpoints/services; or answering principle questions about Java design.
Skip when: trivial edits, build/config files, non-Java code, or when the user opts out.
The Top 20 Rules
Each rule links to a reference file for depth. A subset keeps a Check hint where the name alone is ambiguous.
- Names reveal intent. naming
- Functions do one thing. functions
- ≤3 arguments per function. functions
- No flag (boolean) arguments. functions
- Command-Query Separation. Method either does OR answers, not both. functions
- One abstraction level per function. functions
- Stepdown rule (newspaper metaphor). High-level entry points at top, helpers below. formatting
- No hidden side effects. functions
- Exceptions over error codes. functions
- Law of Demeter — no trainwrecks. No
a.getB().getC().doD()chains on objects (chains on data structures OK). objects-and-data - Objects hide data; expose behavior. objects-and-data
- Single Responsibility Principle. solid
- DRY. functions
- Consistent vocabulary. naming
- Write the test first (TDD). testing
- Tests are FIRST. Fast, Independent, Repeatable, Self-validating, Timely. testing
- No magic numbers or unexplained literals. naming
- Early returns over deep nesting. Max 2 levels of nesting inside a function. functions
- Constructor injection (DIP).
@Autowiredfield injection is a smell; inject viafinalconstructor params. solid - Comments earn their keep. Explain WHY, not WHAT. comments
Workflow
Writing: (1) Name the behavior — if you can't, the design isn't ready. (2) Write the failing test (JUnit 5). (3) Implement minimally, rules 2–6 in mind. (4) Self-check with the checklist below.
Reviewing: (1) Cite each violation by rule name (Demeter, SRP, DIP — never bare "R10") + file:line. (2) Prioritize severity — SRP/Demeter/testing gaps outrank naming nits. (3) Diff-style fixes, each naming the rule. (4) Open references/*.md for rationale.
References
Each rule links inline to the topic file. Additional depth: smells, architecture, concurrency, craftsmanship, creating-objects, generics, lambdas-and-streams, exceptions.
Pre-delivery checklist
- Verb+noun names; no flags; ≤3 args.
- Tests exist, run fast, written first.
Rationalizations
| Excuse | Counter |
| "One more arg" | Args/Flags: extract a record. |
"Use Lombok @Data" | DIP: write the explicit constructor. |
| "Fine for a demo" | SRP holds under pressure. |
| "Review with bare numbers (R10)" | Cite the rule name + references/*.md. |
Violating the letter of a rule is violating its spirit. Pressure (time, demo, sunk cost) does not suspend the rules — it makes them more valuable.
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.

