Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Java Best Practices

ASecurity

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

15 stars
0 votes
0 copies
0 views
Added 9/23/2026
developmentgojavasqlexpressapidocumentation

Works with

api

Security Analysis

A100/100

Scanned 9/23/2026

Install to Claude Code

$npx -y skills add baekenough/second-brain --skill java-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Java Best Practices?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Java Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/baekenough-java-best-practices-second-brain/badge)](https://www.skillsdirectory.com/skills/baekenough-java-best-practices-second-brain)

More formats (shields.io, HTML) on the badges page.

Download with Pro
Files
SKILL.md
---
name: java-best-practices
description: Modern Java 25 LTS patterns from Virtual Threads, Pattern Matching, Records, and Sealed Classes
scope: core
user-invocable: false
---

## 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)

```yaml
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)

```yaml
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

```yaml
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)

```yaml
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)

```yaml
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)

```yaml
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)

```yaml
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

```yaml
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

```yaml
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

```yaml
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

Attribution

baekenoughbaekenough
View sourceMore from baekenough →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

284722 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2192 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

9881 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →