Java Coding Standards
Purpose
Progressive disclosure of Java coding standards for agents writing Java code.
Authoritative Source: docs/explanation/software-engineering/programming-languages/java/README.md
Usage: Auto-loaded for agents when writing Java code. Provides quick reference to the platform's conventions, testing contract, and error-handling rules.
Scope
Java is active for exactly one project — ose-lms-be, the Learning Management System backend. It is not the default for new backends; that remains F#. Introducing Java elsewhere needs its own recorded decision.
Prerequisite Knowledge
IMPORTANT: This skill provides OSE Platform-specific style guides, not educational tutorials.
You MUST understand Java fundamentals before using these standards. Complete the AyoKoding Java learning path first:
- Java Learning Path - Initial setup, language overview, quick start
- Java By Example - Annotated code examples, beginner to advanced
What this skill covers: OSE Platform naming conventions, framework choices, repository-specific patterns, how to apply Java knowledge in THIS codebase.
What this skill does NOT cover: Java syntax, language fundamentals, Spring tutorials, generic patterns (those are in ayokoding-web).
See: Programming Language Documentation Separation for content separation rules.
Quick Standards Reference
- Formatting is not a judgement call. Spotless with google-java-format runs on commit and is verified in CI. Never suppress it per file; never mix a reformat into a behavioural change.
- Package by feature, not by layer. Root
com.oseplatform.<product>, then health/, hello/. config/ is the one layer-named package allowed.
- Prefer
record and final. A setter on a domain type invites a defect.
- Constructor injection only. Never field
@Autowired — it defeats final, hides unsatisfiable dependencies until first use, and forces a framework boot to test.
- Keep decisions out of the framework. Anything worth testing goes in a class with no Spring imports, so its test starts no context.
PortResolver is the reference example.
- Declare configuration you depend on, even where the default already matches — Spring Boot defaults move between majors. Actuator exposure is declared narrowly and asserted by a test.
- Fail fast on misconfiguration. A malformed port override stops startup; it never falls back to the default.
- Catch narrowly, chain the cause, never catch
Throwable. Never swallow.
- Nothing internal reaches a client. No stack traces, class names, paths, hostnames, or configuration values in an error response.
Testing Contract
Java satisfies the repository-wide BDD and TDD contracts unchanged: Gherkin first, Unit always, a regression test with every bug fix.
- Cucumber-JVM on the JUnit Platform is the Unit adapter, with
cucumber-spring supplying the context. One suite class and exactly one @CucumberContextConfiguration per project.
- Cucumber-JVM resolves a step only against its own keyword, so a
@When and a @Then may share identical text — unlike the TypeScript adapter.
- MockMvc is the HTTP assertion boundary: real routing and serialization, no bound port. Process-level behaviour belongs to E2E.
- JaCoCo verification fails the build below the declared line floor. Never exclude a class to reach it, and never write a test whose only effect is to execute a line.
- Never sleep, retry, widen an assertion, skip, or quarantine. A flaky test is a defect.
Comprehensive Documentation
Authoritative Index: docs/explanation/software-engineering/programming-languages/java/README.md
- Coding Standards - Naming, package layout, records, controllers, configuration
- Testing Standards - Cucumber Unit adapter, MockMvc boundary, JaCoCo enforcement
- Error Handling Standards - Exception boundaries, fail-fast startup, what a client never sees
Related Skills
- docs-applying-content-quality
- repo-practicing-trunk-based-development
References
1---2name: swe-programming-java3description: Java coding standards from authoritative docs/explanation/software-engineering/programming-languages/java/ documentation4---56# Java Coding Standards78## Purpose910Progressive disclosure of Java coding standards for agents writing Java code.1112**Authoritative Source**: [docs/explanation/software-engineering/programming-languages/java/README.md](../../../docs/explanation/software-engineering/programming-languages/java/README.md)1314**Usage**: Auto-loaded for agents when writing Java code. Provides quick reference to the platform's conventions, testing contract, and error-handling rules.1516## Scope1718Java is active for exactly one project — `ose-lms-be`, the Learning Management System backend. It is **not** the default for new backends; that remains F#. Introducing Java elsewhere needs its own recorded decision.1920## Prerequisite Knowledge2122**IMPORTANT**: This skill provides **OSE Platform-specific style guides**, not educational tutorials.2324**You MUST understand Java fundamentals before using these standards.** Complete the AyoKoding Java learning path first:25261. **[Java Learning Path](../../../apps/ayokoding-www/content/en/learn/legacy/software-engineering/programming-languages/java/_index.md)** - Initial setup, language overview, quick start272. **[Java By Example](../../../apps/ayokoding-www/content/en/learn/legacy/software-engineering/programming-languages/java/by-example/)** - Annotated code examples, beginner to advanced2829**What this skill covers**: OSE Platform naming conventions, framework choices, repository-specific patterns, how to apply Java knowledge in THIS codebase.3031**What this skill does NOT cover**: Java syntax, language fundamentals, Spring tutorials, generic patterns (those are in ayokoding-web).3233**See**: [Programming Language Documentation Separation](../../../repo-governance/conventions/structure/programming-language-docs-separation.md) for content separation rules.3435## Quick Standards Reference3637- **Formatting is not a judgement call.** Spotless with google-java-format runs on commit and is verified in CI. Never suppress it per file; never mix a reformat into a behavioural change.38- **Package by feature, not by layer.** Root `com.oseplatform.<product>`, then `health/`, `hello/`. `config/` is the one layer-named package allowed.39- **Prefer `record` and `final`.** A setter on a domain type invites a defect.40- **Constructor injection only.** Never field `@Autowired` — it defeats `final`, hides unsatisfiable dependencies until first use, and forces a framework boot to test.41- **Keep decisions out of the framework.** Anything worth testing goes in a class with no Spring imports, so its test starts no context. `PortResolver` is the reference example.42- **Declare configuration you depend on**, even where the default already matches — Spring Boot defaults move between majors. Actuator exposure is declared narrowly and asserted by a test.43- **Fail fast on misconfiguration.** A malformed port override stops startup; it never falls back to the default.44- **Catch narrowly, chain the cause, never catch `Throwable`.** Never swallow.45- **Nothing internal reaches a client.** No stack traces, class names, paths, hostnames, or configuration values in an error response.4647## Testing Contract4849Java satisfies the repository-wide BDD and TDD contracts unchanged: Gherkin first, Unit always, a regression test with every bug fix.5051- **Cucumber-JVM on the JUnit Platform** is the Unit adapter, with `cucumber-spring` supplying the context. One suite class and exactly one `@CucumberContextConfiguration` per project.52- Cucumber-JVM resolves a step **only against its own keyword**, so a `@When` and a `@Then` may share identical text — unlike the TypeScript adapter.53- **MockMvc** is the HTTP assertion boundary: real routing and serialization, no bound port. Process-level behaviour belongs to E2E.54- **JaCoCo verification fails the build** below the declared line floor. Never exclude a class to reach it, and never write a test whose only effect is to execute a line.55- Never sleep, retry, widen an assertion, skip, or quarantine. A flaky test is a defect.5657## Comprehensive Documentation5859**Authoritative Index**: [docs/explanation/software-engineering/programming-languages/java/README.md](../../../docs/explanation/software-engineering/programming-languages/java/README.md)60611. **[Coding Standards](../../../docs/explanation/software-engineering/programming-languages/java/coding-standards.md)** - Naming, package layout, records, controllers, configuration622. **[Testing Standards](../../../docs/explanation/software-engineering/programming-languages/java/testing-standards.md)** - Cucumber Unit adapter, MockMvc boundary, JaCoCo enforcement633. **[Error Handling Standards](../../../docs/explanation/software-engineering/programming-languages/java/error-handling-standards.md)** - Exception boundaries, fail-fast startup, what a client never sees6465## Related Skills6667- docs-applying-content-quality68- repo-practicing-trunk-based-development6970## References7172- [Java README](../../../docs/explanation/software-engineering/programming-languages/java/README.md)73- [Behaviour-Driven Development](../../../repo-governance/development/behaviour-driven-development.md)