# Java Fundamentals

> Master core Java programming - syntax, OOP, collections, streams, and exception handling

- **Type:** Skill
- **Install:** `agentstack add skill-linlannet-agent-skills-java-fundamentals`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [linlannet](https://agentstack.voostack.com/s/linlannet)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [linlannet](https://github.com/linlannet)
- **Source:** https://github.com/linlannet/agent-skills/tree/main/skills/java-fundamentals

## Install

```sh
agentstack add skill-linlannet-agent-skills-java-fundamentals
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Java 基础技能

掌握具有生产质量模式的核心Java编程。

## 概述

此技能涵盖Java基础，包括语法、面向对象编程、集合、流API和异常处理，适用于Java 8-21。

## 何时使用此技能

当您需要：
- 编写干净、地道的Java代码
- 遵循面向对象原则设计类
- 选择合适的集合类型
- 实现函数式编程模式
- 正确处理异常

## 涵盖的主题

### 核心语法（Java 8-21）
- 变量、数据类型、运算符
- 控制流、方法、类
- 记录（Java 16+）、密封类（Java 17+）
- 模式匹配（Java 21）

### 面向对象编程
- 类、继承、多态
- 接口和抽象类
- SOLID原则

### 集合框架
- List: ArrayList, LinkedList
- Set: HashSet, TreeSet
- Map: HashMap, ConcurrentHashMap
- Queue: ArrayDeque, PriorityQueue

### 流API
- filter, map, flatMap, reduce, collect
- Optional处理
- 并行流

### 异常处理
- 检查型与非检查型异常
- Try-with-resources
- 自定义异常

## 快速参考

```java
// 记录（Java 16+）
public record User(String name, String email) {}

// 模式匹配（Java 21）
String format(Object obj) {
    return switch (obj) {
        case Integer i -> "Int: %d".formatted(i);
        case String s -> "String: %s".formatted(s);
        default -> obj.toString();
    };
}

// 流操作
List names = users.stream()
    .filter(User::isActive)
    .map(User::getName)
    .sorted()
    .toList();

// Optional处理
String name = Optional.ofNullable(user)
    .map(User::getName)
    .orElse("Unknown");
```

## 集合选择

| 需求 | 使用 | 原因 |
|------|-----|------|
| 索引访问 | ArrayList | O(1) 随机访问 |
| 唯一元素 | HashSet | O(1) 包含检查 |
| 排序唯一 | TreeSet | O(log n) 排序 |
| 键值对 | HashMap | O(1) 获取/放入 |

## 故障排除

| 问题 | 原因 | 解决方案 |
|------|------|----------|
| NullPointerException | 空引用 | 使用 Optional |
| ConcurrentModificationException | 迭代期间修改 | 使用 Iterator.remove() |
| ClassCastException | 类型错误 | 使用泛型 |

## 使用

```
Skill("java-fundamentals")
```

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [linlannet](https://github.com/linlannet)
- **Source:** [linlannet/agent-skills](https://github.com/linlannet/agent-skills)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-linlannet-agent-skills-java-fundamentals
- Seller: https://agentstack.voostack.com/s/linlannet
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
