본문으로 건너뛰기
cccskills
무료GitHub에 공개

java-best-practices

Modern Java 25 LTS patterns from Virtual Threads, Pattern Matching, Records, and Sealed Classes

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md5.1 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Purpose

Apply modern Java 25 LTS patterns and best practices leveraging the latest language features for clean, performant, and maintainable Java code.

Core Principles

Embrace modern Java features over legacy patterns
Prefer immutability and data-centric design
Leverage Virtual Threads for scalable concurrency
Use Pattern Matching for expressive type handling

Rules

1. Naming Conventions (Google Java Style)

packages:
  style: lowercase, no underscores
  example: com.example.project

classes:
  style: UpperCamelCase
  example: OrderProcessor, UserRecord

methods_variables:
  style: lowerCamelCase
  example: processOrder(), itemCount

constants:
  style: UPPER_SNAKE_CASE
  example: static final int MAX_RETRIES = 3

records:
  style: UpperCamelCase (same as class)
  example: record Point(int x, int y) {}

Reference: guides/java/java-style-guide.md

2. Virtual Threads (JEP 444)

principles:
  - Use Virtual Threads for I/O-bound tasks
  - Avoid pooling Virtual Threads (they are lightweight)
  - Replace thread pools for blocking I/O with Virtual Thread executors

patterns:
  executor: "Executors.newVirtualThreadPerTaskExecutor()"
  direct: "Thread.ofVirtual().start(() -> { ... })"
  structured: "StructuredTaskScope.ShutdownOnFailure() for fork/join"

antipatterns:
  - "Executors.newFixedThreadPool() for I/O tasks — use Virtual Threads instead"
  - "Thread.sleep() on platform threads for rate limiting — use Virtual Threads"
  - "synchronized blocks in Virtual Thread code — use ReentrantLock instead"

Reference: guides/java/modern-java.md

3. Pattern Matching

instanceof_patterns:
  rule: "Use pattern variable binding instead of explicit casts"
  guard: "Combine with && for conditional matching"

switch_patterns:
  rule: "Pattern matching for switch (JEP 441) — use case Type var syntax"
  guards: "Use 'when' clause for conditional cases"
  null_handling: "case null supported in switch"

Reference: guides/java/modern-java.md

4. Records (JEP 395)

principles:
  - Use Records for immutable data carriers
  - Prefer Records over POJOs with getters/setters for pure data
  - Compact constructors for validation

features:
  validation: "Compact constructor (no parens) for input validation"
  methods: "Custom methods allowed alongside auto-generated accessors"
  interfaces: "Records can implement interfaces"

antipatterns:
  - "Mutable state in records — records are inherently immutable"
  - "Using records for entities with behavior — prefer classes"

Reference: guides/java/modern-java.md

5. Record Patterns (JEP 440)

patterns:
  instanceof: "Deconstruct record components in instanceof check"
  switch: "Deconstruct in switch case labels"
  nested: "Nested record patterns for deep destructuring"

Reference: guides/java/modern-java.md

6. Sealed Classes (JEP 409)

principles:
  - Use Sealed Classes for closed type hierarchies
  - Combine with Pattern Matching switch for exhaustive handling
  - Prefer sealed interfaces for behavior-focused hierarchies

pattern: "sealed interface with record implementations, exhaustive switch (no default needed)"

Reference: guides/java/modern-java.md

7. Sequenced Collections (JEP 431)

principles:
  - Use SequencedCollection for ordered access
  - getFirst()/getLast() replace get(0) and get(size-1)

methods: "getFirst(), getLast(), addFirst(), addLast(), reversed(), firstEntry()"

Reference: guides/java/modern-java.md

8. Text Blocks and String Features

patterns:
  text_blocks: "Triple-quote \"\"\" for multi-line strings (since Java 15)"
  formatted: "String.formatted() for template substitution (since Java 15)"

Reference: guides/java/modern-java.md

9. Error Handling

principles:
  - Prefer checked exceptions for recoverable conditions
  - Use unchecked exceptions for programming errors
  - Never swallow exceptions silently
  - Use specific exception types

patterns:
  optional: "orElseThrow(() -> new SpecificException(msg)) for missing values"
  multi_catch: "catch (IOException | SQLException e) for related exceptions"

Reference: guides/java/java-style-guide.md

10. Documentation

best_practices:
  - Use @param and @return for public API
  - Link related types with {@link}
  - Document checked exceptions with @throws
  - Keep Javadoc focused on "what", not "how"

Reference: guides/java/java-style-guide.md

Application

When writing or reviewing Java 25 LTS code:

  1. Use Records for pure data classes over verbose POJOs
  2. Use Sealed Classes + Pattern Matching for type hierarchies
  3. Use Virtual Threads for I/O-bound concurrency
  4. Use instanceof pattern matching over explicit casts
  5. Prefer switch expressions over switch statements
  6. Use getFirst()/getLast() for sequenced collections
  7. Write exhaustive switch for sealed types (no default)
  8. Document public APIs with proper Javadoc

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Pre-action boundary checking — validates agent tool calls against declared capabilities and task contracts

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

baekenough/second-brain152026년 10월 8일 업데이트

Auto-detect project context and optimize harness — deactivate unused agents/skills, suggest missing experts, generate project profile

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

baekenough/second-brain152026년 10월 8일 업데이트

Adversarial code review using attacker mindset — trust boundary, attack surface, business logic, and defense evaluation

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

baekenough/second-brain152026년 10월 8일 업데이트

Apache Airflow best practices for DAG authoring, testing, and production deployment

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

baekenough/second-brain152026년 10월 8일 업데이트

Alembic migration patterns for naming conventions, safety checks, expand-contract, env.py configuration, and CI integration

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

baekenough/second-brain152026년 10월 8일 업데이트

Pre-routing ambiguity analysis — scores request clarity and asks clarifying questions when needed (inspired by ouroboros)

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

baekenough/second-brain152026년 10월 8일 업데이트

baekenough의 스킬 모두 보기

이 스킬의 문제 신고