java

Java OOP with Spring ecosystem, Maven/Gradle, streams, and JVM optimization. Use for .java files.

7 stars

Best use case

java is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Java OOP with Spring ecosystem, Maven/Gradle, streams, and JVM optimization. Use for .java files.

Teams using java should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/java/SKILL.md --create-dirs "https://raw.githubusercontent.com/G1Joshi/Agent-Skills/main/skills/languages/java/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/java/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How java Compares

Feature / AgentjavaStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Java OOP with Spring ecosystem, Maven/Gradle, streams, and JVM optimization. Use for .java files.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Java

Modern Java development with Java 17+ features, streams, and enterprise patterns.

## When to Use

- Working with `.java` files
- Building enterprise applications with Spring Boot
- Android development with Kotlin interop
- Microservices architecture

## Quick Start

```java
// Modern record with validation
public record User(String id, String name, String email) {
    public User {
        Objects.requireNonNull(id, "id must not be null");
        Objects.requireNonNull(name, "name must not be null");
    }
}
```

## Core Concepts

### Records (Java 17+)

```java
// Immutable data carriers
public record User(String id, String name, String email) {
    // Compact constructor for validation
    public User {
        Objects.requireNonNull(id, "id must not be null");
    }

    // Additional methods
    public String displayName() {
        return name.toUpperCase();
    }
}
```

### Sealed Classes

```java
public sealed interface Result<T> permits Success, Failure {
    T getOrThrow();
}

public record Success<T>(T value) implements Result<T> {
    @Override
    public T getOrThrow() { return value; }
}

public record Failure<T>(Exception error) implements Result<T> {
    @Override
    public T getOrThrow() { throw new RuntimeException(error); }
}
```

## Common Patterns

### Streams & Collections

```java
// Immutable collections
var list = List.of("a", "b", "c");
var map = Map.of("key1", "value1", "key2", "value2");

// Stream operations
List<String> names = users.stream()
    .filter(User::active)
    .map(User::name)
    .sorted()
    .toList();

// Collectors grouping
Map<String, List<User>> byRole = users.stream()
    .collect(Collectors.groupingBy(User::role));
```

### Optional

```java
Optional<User> user = Optional.ofNullable(findUser(id));

String name = user
    .map(User::name)
    .orElse("Unknown");

user.ifPresentOrElse(
    u -> process(u),
    () -> handleMissing()
);
```

## Best Practices

**Do**:

- Use `var` for local variables with obvious types
- Prefer records for data transfer objects
- Use Optional instead of null checks
- Use virtual threads for I/O-bound tasks (Java 21+)

**Don't**:

- Use raw types for collections (use generics)
- Use `Optional.get()` without checking
- Catch generic `Exception` (be specific)
- Create mutable DTOs unnecessarily

## Troubleshooting

| Error                             | Cause                      | Solution                         |
| --------------------------------- | -------------------------- | -------------------------------- |
| `NullPointerException`            | Null value access          | Use Optional or null checks      |
| `ClassCastException`              | Invalid type cast          | Use instanceof pattern matching  |
| `ConcurrentModificationException` | Modifying during iteration | Use Iterator.remove() or streams |

## References

- [Java Official Docs](https://docs.oracle.com/en/java/)
- [Baeldung](https://www.baeldung.com/)