java-clean-code
Skill22 starsChanged 3 months agoMITView on GitHub
Modern Java 21 LTS engineering standards, Effective Java design patterns, clean code conventions, and build quality gates.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- CasLubbers/code-design-skillstheir own version, first seen Aug 25, 2026
- nxd1184/java-clean-code-skilltheir own version, first seen Apr 27, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- CasLubbers/code-design-skills★ 2same name
- nxd1184/java-clean-code-skill★ 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 repository3 other files it gives its agents.
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 3 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 40
Every .java file must follow this exact section sequence (100-character line limit, 2-space indentation, no tabs):
- Very specific: line 50
Virtual Threads (JEP 444): Use Executors.newVirtualThreadPerTaskExecutor() for high-concurrency I/O-bound tasks.
- Very specific: line 51
Records (JEP 395/440): Use record for immutable data carriers and DTOs.
- Very specific: line 52
Sealed Classes (JEP 409): Use sealed interface / sealed class to define closed type hierarchies and enable compiler-enforced exhaustive …
- Very specific: line 63
Sequenced Collections (JEP 431): Use getFirst(), getLast(), and reversed() on ordered collections instead of manual index calculations.
- Distinctive: line 71
Composition over Inheritance: Use delegation and Decorator wrappers rather than extending concrete classes.
- Very specific: line 72
Generics (PECS): Use Producer-Extends, Consumer-Super (Collection<?
- Very specific: line 73
Null Safety: Never pass or return null for collections/arrays (return List.of() or empty arrays).
- Very specific: line 80
Resource Management: Always use try-with-resources for AutoCloseable types.
- Distinctive: line 81
No Empty Catches or Log & Rethrow: Never leave catch blocks empty.
- Very specific: line 82
Preserve Root Causes: Always pass the original exception as the cause when throwing custom domain exceptions (throw new …
- Distinctive: line 83
Protect PII: Never log passwords, API keys, or personally identifiable information (PII) in error logs.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Java 21 Clean Code & Engineering Standards
Overview
This skill instructs AI agents to author, refactor, and review enterprise Java code targeting Java 21 LTS. It enforces clean code, Effective Java principles, modern language capabilities (Virtual Threads, Records, Pattern Matching), and automated quality gates (Checkstyle & JaCoCo).
When to Apply
- Writing new Java classes, records, interfaces, or unit tests.
- Refactoring legacy Java codebases.
- Conducting code reviews or static analysis remediation.
1. Core Architectural & Naming Standards
Naming Conventions & Anti-Patterns
| Identifier | Style | Format / Rule | Good Example | Bad Anti-Pattern |
| Class / Interface / Record / Enum | PascalCase | Specific, intention-revealing nouns. | OrderProcessingService | ❌ Manager, Data, IOrderService |
| Method | lowerCamelCase | Verb or verb phrase describing the action. | calculateTotal() | ❌ process(), doSave() |
| Variable / Field / Parameter | lowerCamelCase | Concise, mnemonic nouns. Avoid custom abbreviations. | customerName | ❌ mName, custMngSys |
| Constant | UPPER_SNAKE_CASE | static final deeply immutable values. | MAX_RETRY_ATTEMPTS | ❌ maxRetry |
| Package | Lowercase | Hierarchical, concise, no underscores. | com.example.order | ❌ com.example.order_service |
Source File Layout & Ordering
Every .java file must follow this exact section sequence (100-character line limit, 2-space indentation, no tabs):
- Package Declaration: Single line, never line-wrapped.
- Import Statements: Alphabetical. Group static imports first, followed by standard imports. Wildcard imports (
import java.util.*) are strictly prohibited. - Class Body Member Order:
static finalconstants -> Static fields -> Instance fields (private finalprioritized) -> Constructors -> Static factory methods -> Public methods -> Overloaded methods (must be contiguous) -> Private helper methods.
2. Modern Java 21 LTS Features
- Virtual Threads (JEP 444): Use
Executors.newVirtualThreadPerTaskExecutor()for high-concurrency I/O-bound tasks. Never pool virtual threads. PreferReentrantLockoversynchronizedto avoid thread pinning during blocking I/O. - Records (JEP 395/440): Use
recordfor immutable data carriers and DTOs. - Sealed Classes (JEP 409): Use
sealed interface/sealed classto define closed type hierarchies and enable compiler-enforced exhaustive pattern matching. - Pattern Matching for Switch (JEP 441):
public double calculateArea(Shape shape) { return switch (shape) { case Circle(double radius) -> Math.PI * radius * radius; case Rectangle(double w, double h) when w > 0 && h > 0 -> w * h; case Square(double side) when side > 0 -> side * side; }; } - Sequenced Collections (JEP 431): Use
getFirst(),getLast(), andreversed()on ordered collections instead of manual index calculations.
3. Object Design & Clean Code Practices
- Immutability by Default: Declare fields
private final. Minimize mutable state. Return unmodifiable collections (List.of(),Set.of()) and defensive copies. - Creation Patterns: Favor static factory methods (
of(),from()) or Builders for objects with >3 optional parameters. Implement Singletons using single-elementenum. - Composition over Inheritance: Use delegation and Decorator wrappers rather than extending concrete classes.
- Generics (PECS): Use
Producer-Extends, Consumer-Super(Collection<? extends T>for reading,Collection<? super T>for writing). - Null Safety: Never pass or return
nullfor collections/arrays (returnList.of()or empty arrays). UseOptional<T>strictly for method return values (never as fields or parameters).
4. Exception Handling Best Practices
- Throw Early, Handle Late: Validate arguments at boundaries (
Objects.requireNonNull(),IllegalArgumentException). Handle exceptions at boundary layers. - Resource Management: Always use
try-with-resourcesforAutoCloseabletypes. - No Empty Catches or Log & Rethrow: Never leave catch blocks empty. Choose to either log and resolve OR wrap and rethrow—never both (prevents log duplication).
- Preserve Root Causes: Always pass the original exception as the cause when throwing custom domain exceptions (
throw new OrderException("Failed", cause)). - Protect PII: Never log passwords, API keys, or personally identifiable information (PII) in error logs.
5. Documentation & Quality Gates
- Javadoc: Required for all
publicandprotectedAPIs. First sentence must be a concise summary ending in a period. Tag order:@param,@return,@throws,@deprecated. Always use@Override. - Checkstyle Enforcement: Code must compile with zero style violations (Google Style Guide, 2-space indent, K&R braces).
- JaCoCo Quality Gates: Unit tests (JUnit 5 + AssertJ/Mockito) must maintain minimum 80% Line Coverage and 75% Branch Coverage on business logic.
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.

