Canonical reference for Java idioms, naming conventions, and code quality standards used across this project.
Java code follows the Google Java Style Guide enforced by Checkstyle (etc/checkstyle.xml).
Key rules:
- Indentation: 2 spaces (no tabs)
- Line length: 120 characters maximum
- Braces: Always use braces for
if,for,while,doblocks - Imports: Static imports first, then third-party packages; alphabetical within groups; no wildcard imports
- Use
varfor local variables when the type is clear from context:var uploadFile = new File(UPLOAD_FILE_NAME); var response = s3Client.getObject(...);
- Avoid
varwhen the inferred type would be ambiguous or unclear
list.size() == 0/list.size() > 0→list.isEmpty()/!list.isEmpty()- Use
List.of(...),Map.of(...)for immutable collections instead ofCollections.unmodifiableList(...) - Prefer streams over explicit loops for transformations:
buckets.stream().map(Bucket::name).collect(Collectors.toSet())
- Prefer switch expressions over
if-elsechains with 3+ branches
- Use text blocks for multi-line strings
| Anti-Pattern | Refactor To |
|---|---|
list.size() == 0 |
list.isEmpty() |
Collections.emptyList() |
List.of() |
Collections.unmodifiableList(new ArrayList<>(...)) |
List.copyOf(...) |
"" + value |
String.valueOf(value) or String.format(...) |
| Empty catch blocks | At minimum, log the exception |
| Magic numbers/strings | Named constants |
Follows Google Java Style:
- Classes/Interfaces/Enums:
UpperCamelCase - Methods/Variables:
lowerCamelCase - Constants (
static final):UPPER_SNAKE_CASE - Booleans:
is-/has-/should-/can-prefixes - Collections: plural nouns
- Avoid abbreviations:
bucketMetadatanotbktMd - Abbreviations in type names: at most 4 consecutive uppercase letters (e.g.,
KmsKeyRefnotKMSKeyRef)
- Method names: Use descriptive verb phrases —
shouldUploadAndDownloadObject,defaultBucketsGotCreated - Avoid: generic names like
testSomethingortest1 - Pattern: Arrange-Act-Assert
- Use
/** */for public APIs;//inline comments for rationale - Comments explain why, never what — remove comments that restate the code
- Javadoc tag order:
@param,@return,@throws,@deprecated - Add comments for edge cases, non-obvious S3 semantics, or workarounds
- Link to AWS API docs or GitHub issues where relevant
- Single-line Javadoc is allowed:
/** Short description. */