Java language guardrails, patterns, and best practices for AI-assisted development.
Use when working with Java files (.java), pom.xml, build.gradle, or when the user mentions Java.
Provides modern Java patterns (records, sealed classes, streams), testing standards,
and Spring conventions specific to this project's coding standards.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Java language guardrails, patterns, and best practices for AI-assisted development.
Use when working with Java files (.java), pom.xml, build.gradle, or when the user mentions Java.
Provides modern Java patterns (records, sealed classes, streams), testing standards,
and Spring conventions specific to this project's coding standards.
Packages: com.company.project.module (lowercase, no underscores)
One top-level class per file (name matches filename)
Use var for local variables only when the type is obvious from the right side
No wildcard imports (import java.util.* is forbidden)
Records & Sealed Classes
Use record for immutable data carriers instead of manual POJOs
Use sealed classes/interfaces for restricted type hierarchies
Add compact constructors for validation in records
Sealed classes enable exhaustive switch expressions with pattern matching
publicrecordUserId(String value) {
public UserId {
Objects.requireNonNull(value, "UserId must not be null");
if (value.isBlank()) {
thrownewIllegalArgumentException("UserId must not be blank");
}
}
}
publicsealedinterfacePaymentResultpermits PaymentResult.Success, PaymentResult.Declined, PaymentResult.Error {
recordSuccess(String transactionId, BigDecimal amount)implementsPaymentResult {}
recordDeclined(String reason)implementsPaymentResult {}
recordError(Exception cause)implementsPaymentResult {}
}
Streams & Optional
Use streams for transformations, not for side effects
Never call Optional.get() -- use orElseThrow(), orElse(), map(), flatMap()
Do not use Optional as a method parameter or field type (only as a return type)
Avoid parallel streams unless measured to be faster (overhead is real)
Prefer toList() (Java 16+) over collect(Collectors.toList())
mvn clean install # Build and install locally
mvn test# Run all tests
mvn verify # Run tests + integration tests
mvn dependency:tree # Show dependency tree
mvn dependency:analyze # Find unused/undeclared deps
mvn spotbugs:check # Static analysis
mvn checkstyle:check # Style check
Gradle Commands
./gradlew build # Full build with tests
./gradlew test# Run unit tests
./gradlew check # Run all verification tasks
./gradlew dependencies # Show dependency tree
./gradlew jacocoTestReport # Generate coverage report
References
For detailed patterns and examples, see:
references/patterns.md -- Spring patterns, Stream API recipes, Optional chaining, builder patterns