java-best-practices

- 类名:PascalCase(UserService)

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "java-best-practices" with this command: npx skills add leavesfly/jimi/leavesfly-jimi-java-best-practices

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 使用

Optional<User> user = userRepository.findById(id); return user.orElseThrow(() -> new NotFoundException());

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

docker-setup

No summary provided by upstream source.

Repository SourceNeeds Review
General

git-commit-guide

No summary provided by upstream source.

Repository SourceNeeds Review
General

database-design

No summary provided by upstream source.

Repository SourceNeeds Review
java-best-practices | V50.AI