saravanan-paramasivam/java-spring-dev icon
public
Published on 7/10/2025
java_spring_dev

A curated set of rules for Java developers working with Core Java and Spring Boot applications. This rule set enforces best practices for code structure, testing, defensive programming, and modern Java optimizations. It helps maintain clean, secure, and efficient code while leveraging the latest language features and Spring Boot conventions.

Rules
Models
Context
relace Relace Instant Apply model icon

Relace Instant Apply

relace

40kinputยท32koutput
anthropic Claude 3.7 Sonnet model icon

Claude 3.7 Sonnet

anthropic

200kinputยท8.192koutput
anthropic Claude 3.5 Sonnet model icon

Claude 3.5 Sonnet

anthropic

200kinputยท8.192koutput
mistral Codestral model icon

Codestral

mistral

voyage voyage-code-3 model icon

voyage-code-3

voyage

voyage Voyage AI rerank-2 model icon

Voyage AI rerank-2

voyage

## ๐Ÿงฉ Java Development Rules 

### โœ… General Coding Standards
- Use meaningful and descriptive variable, method, and class names.
- Follow camelCase for variables and methods, PascalCase for classes.
- Avoid magic numbers and hardcoded values; use constants or enums.
- Keep methods short and focused on a single responsibility.
- Prefer composition over inheritance where applicable.
- Avoid deep nesting; use early returns to simplify logic.

---
### ๐Ÿงช Testing Best Practices
- Always write unit tests for public methods using JUnit 5.
- Use Mockito for mocking dependencies in unit tests.
- Follow AAA (Arrange-Act-Assert) pattern in tests.
- Ensure tests are independent and repeatable.
- Use parameterized tests for multiple input scenarios.
- Validate edge cases and exception handling in tests.
- Use integration tests for Spring Boot controllers and services.

---
### ๐Ÿ›ก๏ธ Defensive Programming
- Validate method inputs using `Objects.requireNonNull()` or custom checks.
- Use `Optional` to handle nullable return values safely.
- Catch and log exceptions with meaningful messages.
- Avoid exposing internal implementation via public APIs.
- Use assertions only for development, not production logic.
- Handle external API failures gracefully with retries or fallbacks.

---
### ๐Ÿš€ Optimization & Modern Java Features
- Use `var` for local variables where type is obvious (Java 10+).
- Prefer `switch` expressions over traditional switch (Java 14+).
- Use `record` for immutable data carriers (Java 14+).
- Use `Stream` API for collection processing, but avoid overuse.
- Use `CompletableFuture` for async operations.
- Use `Pattern Matching for instanceof` (Java 16+) for cleaner type checks.
- Use `Text Blocks` for multi-line strings (Java 15+).
- Avoid unnecessary object creation; reuse where possible.
- Profile and benchmark critical code paths before optimizing.

---
### ๐ŸŒฑ Spring Boot Specific Rules
- Use constructor injection over field injection.
- Annotate configuration classes with `@Configuration`.
- Use `@Service`, `@Repository`, and `@Controller` appropriately.
- Avoid business logic in controllers; delegate to services.
- Use `@Transactional` for methods that modify data.
- Externalize configuration using `application.yml` or `application.properties`.
- Use `@Value` or `@ConfigurationProperties` for config binding.
- Validate request payloads using `@Valid` and `@NotNull`, etc.
- Use pagination and filtering for large data sets.
- Secure endpoints using Spring Security best practices.

No Docs configured

Prompts

Learn more

No Prompts configured

Context

Learn more
@diff
Reference all of the changes you've made to your current branch
@codebase
Reference the most relevant snippets from your codebase
@url
Reference the markdown converted contents of a given URL
@folder
Uses the same retrieval mechanism as @Codebase, but only on a single folder
@terminal
Reference the last command you ran in your IDE's terminal and its output
@code
Reference specific functions or classes from throughout your project
@file
Reference any file in your current workspace

No Data configured

MCP Servers

Learn more

No MCP Servers configured