You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coding standards and conventions for Java projects. Covers Google Java Style, Spring Boot conventions, Lombok usage, exception handling, and modern Java idioms.
Use Lombok to reduce boilerplate, but avoid overuse:
// Good@Data@Builder@NoArgsConstructor@AllArgsConstructorpublicclassUserDto {
privateStringid;
privateStringemail;
privateUserRolerole;
}
// Good — immutable value object@ValuepublicclassMoney {
BigDecimalamount;
Currencycurrency;
}
// Bad — @Data on entity (equals/hashCode can be problematic with JPA)@Entity@Data// Avoid: can cause LazyInitializationException with @EqualsAndHashCodepublicclassUser { ... }
// Good — entity@Entity@Getter@Setter@NoArgsConstructorpublicclassUser { ... }
4. Spring Boot Conventions
Constructor Injection (mandatory)
// Good@ServicepublicclassUserService {
privatefinalUserRepositoryuserRepository;
privatefinalEmailServiceemailService;
publicUserService(UserRepositoryuserRepository, EmailServiceemailService) {
this.userRepository = userRepository;
this.emailService = emailService;
}
}
// Bad — field injection@ServicepublicclassUserService {
@AutowiredprivateUserRepositoryuserRepository; // Do not use
}
/** * Authenticates a user by credentials and returns a JWT token. * * @param username the user's login name (case-insensitive) * @param password the user's plain-text password * @return a JWT token valid for 24 hours * @throws AuthenticationException if credentials are invalid * @throws AccountLockedException if the account is temporarily locked */publicStringauthenticate(Stringusername, Stringpassword) { ... }
9. Build and Tooling
Use Maven or Gradle with Kotlin DSL.
Pin dependency versions; do not use LATEST or RELEASE.