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
40kinput·32koutput
200kinput·8.192koutput
200kinput·8.192koutput

MCP Servers

Learn more

No MCP Servers configured

## 🧩 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.

Prompts

Learn more

No Prompts configured

Context

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