mcpbeat Sign in

Java Coding Standards Skill for Claude

Spring Bootサービス向けのJavaコーディング標準:命名、不変性、Optional使用、ストリーム、例外、ジェネリクス、プロジェクトレイアウト。

1k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
265
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/loulanyue/awesome-claude-notes --skill java-coding-standards

The instruction itself

4 sections, as written by the author

Javaコーディング標準

Spring Bootサービスにおける読みやすく保守可能なJava(17+)コードの標準。

核となる原則

  • 巧妙さよりも明確さを優先
  • デフォルトで不変; 共有可変状態を最小化
  • 意味のある例外で早期失敗
  • 一貫した命名とパッケージ構造

命名

// ✅ クラス/レコード: PascalCase
public class MarketService {}
public record Money(BigDecimal amount, Currency currency) {}

// ✅ メソッド/フィールド: camelCase
private final MarketRepository marketRepository;
public Market findBySlug(String slug) {}

// ✅ 定数: UPPER_SNAKE_CASE
private static final int MAX_PAGE_SIZE = 100;

不変性

// ✅ recordとfinalフィールドを優先
public record MarketDto(Long id, String name, MarketStatus status) {}

public class Market {
  private final Long id;
  private final String name;
  // getterのみ、setterなし
}

Optionalの使用

// ✅ find*メソッドからOptionalを返す
Optional<Market> market = marketRepository.findBySlug(slug);

// ✅ get()の代わりにmap/flatMapを使用
return market
    .map(MarketResponse::from)
    .orElseThrow(() -> new EntityNotFoundException("Market not found"));

ストリームのベストプラクティス

// ✅ 変換にストリームを使用し、パイプラインを短く保つ
List<String> names = markets.stream()
    .map(Market::name)
    .filter(Objects::nonNull)
    .toList();

// ❌ 複雑なネストされたストリームを避ける; 明確性のためにループを優先

例外

  • ドメインエラーには非チェック例外を使用; 技術的例外はコンテキストとともにラップ
  • ドメイン固有の例外を作成(例: MarketNotFoundException)
  • 広範なcatch (Exception ex)を避ける(中央でリスロー/ログ記録する場合を除く)
throw new MarketNotFoundException(slug);

ジェネリクスと型安全性

  • 生の型を避ける; ジェネリックパラメータを宣言
  • 再利用可能なユーティリティには境界付きジェネリクスを優先
public <T extends Identifiable> Map<Long, T> indexById(Collection<T> items) { ... }

プロジェクト構造(Maven/Gradle)

src/main/java/com/example/app/
  config/
  controller/
  service/
  repository/
  domain/
  dto/
  util/
src/main/resources/
  application.yml
src/test/java/... (mainをミラー)

フォーマットとスタイル

  • 一貫して2または4スペースを使用(プロジェクト標準)
  • ファイルごとに1つのpublicトップレベル型
  • メソッドを短く集中的に保つ; ヘルパーを抽出
  • メンバーの順序: 定数、フィールド、コンストラクタ、publicメソッド、protected、private

避けるべきコードの臭い

  • 長いパラメータリスト → DTO/ビルダーを使用
  • 深いネスト → 早期リターン
  • マジックナンバー → 名前付き定数
  • 静的可変状態 → 依存性注入を優先
  • サイレントなcatchブロック → ログを記録して行動、または再スロー

ログ記録

private static final Logger log = LoggerFactory.getLogger(MarketService.class);
log.info("fetch_market slug={}", slug);
log.error("failed_fetch_market slug={}", slug, ex);

Null処理

  • やむを得ない場合のみ@Nullableを受け入れる; それ以外は@NonNullを使用
  • 入力にBean Validation(@NotNull@NotBlank)を使用

テストの期待

  • JUnit 5 + AssertJで流暢なアサーション
  • モック用のMockito; 可能な限り部分モックを避ける
  • 決定論的テストを優先; 隠れたsleepなし

覚えておく: コードを意図的、型付き、観察可能に保つ。必要性が証明されない限り、マイクロ最適化よりも保守性を最適化します。

原文

  • 英語版の原文

ナビゲーション

  • 日本語ドキュメント一覧
  • skills/README.md
  • 貢献ガイド

Other skills for the same job

different authors, same section of the catalogue
Protocolsio Integration
by christophacham
×4

Integration with protocols.io API for managing scientific protocols. This skill should be used when working with protocols.io to search, create, update, or publish protocols; manage protocol steps and materials; handle discussions and comments; organize workspaces; upload and manage files; or integrate protocols.io functionality into workflows. Applicable for protocol discovery, collaborative protocol development, experiment tracking, lab protocol management, and scientific documentation.

16k tokens
Tailored Resume Generator
by frostant
×4

Analyzes job descriptions and generates tailored resumes that highlight relevant experience, skills, and achievements to maximize interview chances

3k tokens
Excalidraw Diagram Generator
by github
vendor ×3

Generate Excalidraw diagrams from natural language descriptions. Use when asked to "create a diagram", "make a flowchart", "visualize a process", "draw a system architecture", "create a mind map", or "generate an Excalidraw file". Supports flowcharts, relationship diagrams, mind maps, and system architecture diagrams. Outputs .excalidraw JSON files that can be opened directly in Excalidraw.

36k tokens scripts
Expo Dev Client
by openai
vendor ×3

Build and distribute Expo development clients locally or via TestFlight

961 tokens
Executing Plans
by ZhanlinCui
×3

Use when you have a written implementation plan to execute in a separate session with review checkpoints

542 tokens
Anndata
by christophacham
×3

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

16k tokens
Benchling Integration
by christophacham
×3

Benchling R&D platform integration. Access registry (DNA, proteins), inventory, ELN entries, workflows via API, build Benchling Apps, query Data Warehouse, for lab data management automation.

14k tokens
Biopython
by christophacham
×3

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

24k tokens

How to use it

Copy the folder

Take loulanyue/java-coding-standards from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.