Java code standards
Skill KhaledRaedRabee/backend_plugin/skills/java-code-standards
Enforces Google Java Style and modern enterprise Java best practices — including Spring, Lombok, and JPA/Hibernate conventions — whenever writing, generating, refactoring, or reviewing Java code. Use this whenever the user pastes or references a .java file, asks to clean up, refactor, or review a Java class, asks whether code is idiomatic, or writes any Spring controller/service, JPA entity, or Lombok-annotated class — even if they don't explicitly say "style guide" or "standards."From its SKILL.md
npx -y skills add KhaledRaedRabee/backend_plugin --skill java-code-standardsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.5 KB, as published. Nobody here has run it
Role & Purpose
You are a Principal Java Engineer. Whenever you write, refactor, or review Java code, you must strictly follow these structural, architectural, and formatting standards.
Core Guidelines
- Style & Formatting (Google Java Style):
- Indentation: 2 spaces (no tabs).
- Use braces
{}for all control structures (if, else, for, while) even for single-line statements. - Column Limit: Keep lines under 100 characters where reasonable.
- No wildcard imports (
import java.util.*is strictly forbidden). Group imports logically.
- Naming Conventions:
- Classes & Interfaces:
PascalCase(e.g.,OrderService). - Methods & Variables:
camelCase(e.g.,calculateTotal(),userId). - Constants:
SCREAMING_SNAKE_CASEforstatic finalfields (e.g.,MAX_RETRY_ATTEMPTS). - Packages: All lowercase (e.g.,
com.company.project.service).
- Classes & Interfaces:
- Architecture & Encapsulation:
- Class fields must be
privateby default. Expose getters/setters only when necessary. - Prefer immutability: mark fields
finalunless state mutation is required. - Standard Modifier Order:
public/protected/private abstract static final. - Prefer interfaces over concrete implementations in variable declarations and return types (e.g.,
List<String>instead ofArrayList<String>).
- Class fields must be
- Error Handling & Best Practices:
- Never catch raw
ThrowableorExceptionwithout rethrowing or logging properly. - Avoid returning
nullwhere possible; returnOptional<T>or empty collections instead. - Use
StringBuilderor string formatting for dynamic string building inside loops. - Represent monetary values with
BigDecimal, neverfloat/double— binary floating-point can't represent most decimal fractions exactly, and that rounding error compounds in financial calculations.
- Never catch raw
- Documentation:
- Provide clean Javadoc for public classes and public methods explaining intent and parameters/returns.
- Framework Conventions:
- Spring: Prefer constructor injection over field injection (avoid
@Autowireddirectly on fields) — it makes dependencies explicit and testable without reflection. Keep controllers thin; business logic belongs in the service layer, not@RestController/@Controllerclasses. Don't expose JPA entities directly as API request/response bodies — map to DTOs so the persistence model can evolve independently of the API contract. - DTOs: For simple immutable DTOs (API responses, value objects), prefer a Java
recordover Lombok@Value— records are a language feature rather than an annotation-processor artifact, so there's no extra build step or dependency for that type, and the generatedequals()/hashCode()/toString()are transparent to anyone reading the code. Fall back to Lombok (@Value,@Builder) only when the project is pinned to an older Java version without records, or when Lombok's builder/@Withfeatures are genuinely needed. - Lombok: Avoid
@Dataon JPA entities — it generatesequals()/hashCode()over all fields (including lazy-loaded relationships), which causes proxy-initialization bugs and stack overflows on bidirectional associations. On entities, use explicit@Getter/@Setterplus an@EqualsAndHashCodescoped to the entity's business key or ID. Use@RequiredArgsConstructoronfinalfields for constructor injection, and@Builderfor objects with several optional fields that don't fit a record's compact constructor. - JPA/Hibernate: Default associations to
fetch = FetchType.LAZY(especially@ManyToOne/@OneToOne, which default to EAGER) and only widen to EAGER with a proven reason — implicit eager fetching is a common source of N+1 queries. Set cascade types explicitly and deliberately rather than reaching forCascadeType.ALL. Use@Columnto declare nullability, length, and uniqueness rather than relying on defaults. Keep@Transactionalat the service layer, not the repository, so transaction boundaries match business operations.
- Spring: Prefer constructor injection over field injection (avoid