JA

Java Defaults

Core Java coding conventions

Details

Language / Topic
javaJava
Category
Style Guide

Rules

balanced
- Follow Java naming conventions: `camelCase` for methods/variables, `PascalCase` for classes, `UPPER_SNAKE_CASE` for constants.
- Use Java 17+ features: records, sealed classes, pattern matching, text blocks.
- Use `Optional<T>` for method returns that may be empty — never return null from methods. Use `Optional.of()`, `Optional.empty()`, `Optional.ofNullable()`.
- Use records (`record Point(int x, int y) {}`) for simple data carriers — they auto-generate constructor, equals, hashCode, toString.
- Prefer immutable objects. Use `final` on fields, parameters, and local variables by default.
- Use `Optional<T>` for return types that may be absent — never return `null` from public methods.
- Prefer composition over inheritance. Use interfaces for abstraction.
- Use `try-with-resources` for all `AutoCloseable` resources (streams, connections, files).
- Use `var` for local variables when the type is obvious from the right-hand side.