leavesfly avatar

Java Best Practices

A solid reference card for modern Java patterns and idioms. You get naming conventions,Enum-based singletons, factory and builder patterns with actual snippets, plus practical examples for Streams, Optional, and ExecutorService. The code samples use current Java syntax like switch expressions, which is good to see. It's basically the cheat sheet you'd want open when doing code review or onboarding someone to a Java codebase. The pattern examples are brief but real, not pseudocode. Worth having around if you're enforcing standards across a team or just want quick reminders of idiomatic ways to handle common scenarios without Googling.

skills.sh installs
164
GitHub stars
238
last updated
Aug 21, 2026

Install

$ npx -y skills add leavesfly/jimi --skill java-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Files

Java 最佳实践技能包

编码规范

命名规范

  • 类名:PascalCase(UserService)
  • 方法/变量:camelCase(getUserById)
  • 常量:UPPER_SNAKE_CASE(MAX_SIZE)
  • 包名:小写(com.example.service)

常用设计模式

单例模式(枚举实现):

public enum Singleton {
    INSTANCE;
    public void doSomething() {}
}

工厂模式:

public class UserFactory {
    public static User createUser(String type) {
        return switch (type) {
            case "admin" -> new AdminUser();
            case "guest" -> new GuestUser();
            default -> new RegularUser();
        };
    }
}

Builder 模式:

User user = User.builder()
    .name("张三")
    .age(25)
    .build();

Stream API

List<String> names = users.stream()
    .filter(u -> u.getAge() > 18)
    .map(User::getName)
    .collect(Collectors.toList());

异常处理

try {
    // 业务逻辑
} catch (SpecificException e) {
    log.error("Error: {}", e.getMessage(), e);
    throw new BusinessException("操作失败");
} finally {
    // 清理资源
}

并发编程

ExecutorService executor = Executors.newFixedThreadPool(10);
executor.submit(() -> {
    // 异步任务
});

Optional 使用

Sponsors

Details

Repository
github.com/leavesfly/jimi
Category
Java & JVM
First seen
Jun 3, 2026

Recommended

More Java & JVM
1raphaelsalaja avatarto-spring-or-not-to-springraphaelsalaja/userinterface-wikiAudit animation code for correct timing function selection. Use when reviewing motion implementations, debugging animations that feel wrong, or choosing between152skills.sh installs
2jabrena avatar124-java-secure-codingjabrena/cursor-rules-java124 java secure coding146skills.sh installs
3jabrena avatar125-java-concurrencyjabrena/cursor-rules-java125 java concurrency135skills.sh installs
4jabrena avatar128-java-genericsjabrena/cursor-rules-java128 java generics135skills.sh installs
5jabrena avatar141-java-refactoring-with-modern-featuresjabrena/cursor-rules-java141 java refactoring with modern features135skills.sh installs
6jabrena avatar131-java-testing-unit-testingjabrena/cursor-rules-java131 java testing unit testing134skills.sh installs