toolchains-java-core
БесплатноБез исполняемых скриптовНе проверенJava 21+ core patterns for minimalism, efficiency, code reuse, and performance
от bobmatnyc★ 160 звёзд на GitHubОб этом скилле
Java Core Patterns
Modern Java development patterns targeting 21+ LTS for minimal, efficient, reusable, and performant code.
Quick Start
New code: Use records for DTOs/value objects, sealed classes + pattern matching for type-safe dispatch, virtual threads for I/O-bound concurrency, SequencedCollection for ordered access.
Performance: Profile first with JFR/async-profiler. Use JMH for benchmarks, Generational ZGC for low-latency, Stream API for declarative data transforms.
Minimalism Patterns
- Use
recordfor immutable data carriers — eliminates boilerplate (equals, hashCode, toString, accessors) - Prefer
switchexpressions over if-elif chains; leverage pattern matching withinstanceofto collapse cast+check - Use
sealedclasses/interfaces to restrict type hierarchies — compiler verifies exhaustiveness in switch - Use
varfor local variables when type is obvious from RHS — improves readability, not a replacement for field types - Unnamed variables (
_) for unused bindings in patterns, catch blocks, and lambdas (Java 22+) - Prefer
Optionalreturn types over nullable returns — never useOptionalas field or parameter type - Use text blocks (
""") for multi-line strings — SQL, JSON, HTML templates - Guard clauses (
when) in switch patterns eliminate nested if-conditions inside cases
Efficiency Patterns
- Stream API for declarative collection transforms; prefer
toList()(Java 16+) overcollect(Collectors.toList()) SequencedCollection(Java 21) forgetFirst()/getLast()/reversed()— replaces index-based access hacksMap.of(),List.of(),Set.of()for immutable collections — avoidCollections.unmodifiableX()wrappersString.formatted()or"".formatted()overString.format()for readability- Pre-size
ArrayListandHashMapwhen capacity is known — avoids rehashing/reallocation - Use
EnumMap/EnumSetfor enum-keyed collections — array-backed, faster than HashMap StringBuilderfor string concatenation in loops; single expressions use+(JIT optimizes)- Batch JDBC operations with
addBatch()/executeBatch()— never N+1 queries
Code Reuse
- Sealed interfaces for closed type hierarchies — records as implementations for algebraic data types
- Composition over inheritance — inject dependencies via constructor, use interfaces for contracts
- Default methods on interfaces for shared behavior without abstract classes
- Records as value objects — immutable, compact, pattern-matchable domain types
- Service interfaces with single responsibility — small contracts, easy to mock in tests
- Extract shared logic to static utility methods or dedicated service classes, not base classes
Function,Predicate,Supplierfunctional interfaces for composable behavior
Modern Java (21-23)
- Records (Java 16+, finalized): Immutable data carriers with auto-generated accessors, equals, hashCode, toString
- Sealed classes (Java 17+):
sealed interface Shape permits Circle, Rect— exhaustive pattern matching - Pattern matching for switch (Java 21): Type patterns, record patterns, guard clauses (
when), null handling - Virtual threads (Java 21):
Thread.ofVirtual().start()orExecutors.newVirtualThreadPerTaskExecutor()— millions of threads - Structured concurrency (preview):
StructuredTaskScopefor grouped subtask lifecycle — fork/join/throwIfFailed - Scoped values (preview): Immutable context propagation replacing ThreadLocal patterns
- Sequenced collections (Java 21):
SequencedCollection,SequencedSet,SequencedMapwith defined encounter order - Unnamed patterns (Java 22):
_for unused variables in patterns, catches, lambdas - Foreign Function & Memory API (Java 22, finalized): Native interop replacing JNI
Performance
- Profile first: JFR (Java Flight Recorder) for production profiling, async-profiler for low-overhead sampling, JMH for microbenchmarks
- Generational ZGC (Java 21): Sub-millisecond pauses regardless of heap size; tune
SoftMaxHeapSizefor predictable RSS - Shenandoah GC: Low-latency alternative;
ShenandoahGCHeuristics=adaptivefor containerized workloads - G1 GC (default): Best general-purpose choice; ZGC/Shenandoah for ultra-low-latency requirements
- Virtual threads for I/O: Replace thread pools for I/O-bound work — avoid
synchronizedblocks (causes pinning) - Use
ReentrantLockinstead ofsynchronizedwith virtual threads to prevent carrier thread pinning - JIT optimization:
-XX:+TieredCompilationfor startup/peak balance; warm up JVM before benchmarking - Avoid autoboxing in hot loops — use primitive specializations (
IntStream,LongStream,mapToInt) - Minimize object allocation in hot paths — reuse builders, use primitive arrays where possible
Testing
- JUnit 5:
@ParameterizedTestwith@MethodSource/@CsvSourcefor data-driven tests;assertAll()for grouped assertions - Mockito: `@Ext
Установить toolchains-java-core в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл toolchains-java-core?
Java 21+ core patterns for minimalism, efficiency, code reuse, and performance
Как установить скилл toolchains-java-core?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл toolchains-java-core запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic