java
What it does
This guide teaches how to write more efficient and modern Java code. It shows examples of using newer language features to make your code cleaner and easier to understand.
When to use it
- βWhen learning new ways to write Java code.
- βWhen reviewing or improving existing Java code.
- βWhen wanting to use modern Java features.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/java/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I use Streams to filter and transform a list of items in Java?β
5 new skills a week. 1 minute to read.
How it works
The AI compares your code with Java best practice examples. It suggests using features like Streams, Optional, and Records to simplify common tasks and avoid errors.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Java: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for java.
Table of Contents
- Streams & Collections
- Optional
- Records & Data Classes
- Switch Expressions
- Concurrency
- Error Handling
- Anti-patterns specific to Java
1. Streams & Collections {#streams}
// β Imperative accumulation
List<String> result = new ArrayList<>();
for (Item item : items) {
if (item.isActive()) result.add(item.getName().toUpperCase());
}
// β
List<String> result = items.stream()
.filter(Item::isActive)
.map(item -> item.getName().toUpperCase())
.toList(); // Java 16+; use .collect(Collectors.toList()) before
// β Manual grouping
Map<String, List<Item>> grouped = new HashMap<>();
for (Item item : items) {
grouped.computeIfAbsent(item.getCategory(), k -> new ArrayList<>()).add(item);
}
// β
Map<String, List<Item>> grouped = items.stream()
.collect(Collectors.groupingBy(Item::getCategory));
// β Manual sum
int total = 0;
for (Order o : orders) total += o.getAmount();
// β
int total = orders.stream().mapToInt(Order::getAmount).sum();
Prefer method references (Item::isActive) over equivalent lambdas (item -> item.isActive()).
2. Optional {#optional}
// β Null check chain
String city = null;
if (user != null && user.getAddress() != null) {
city = user.getAddress().getCity();
}
// β
String city = Optional.ofNullable(user)
.map(User::getAddress)
.map(Address::getCity)
.orElse(null);
// β Optional.get() without isPresent()
String name = optional.get(); // throws if empty
// β
String name = optional.orElse("default");
// or: optional.orElseThrow(() -> new IllegalStateException("name required"));
// β Optional as a field or parameter (anti-pattern)
class User { private Optional<String> nickname; }
// β
β Optional is for return types only
class User { private String nickname; } // nullable field
public Optional<String> getNickname() { return Optional.ofNullable(nickname); }
3. Records & Data Classes {#records}
// β Manual POJO
class Point {
private final int x, y;
public Point(int x, int y) { this.x = x; this.y = y; }
public int getX() { return x; }
public int getY() { return y; }
// + equals, hashCode, toString...
}
// β
(Java 16+)
record Point(int x, int y) {}
// β Builder pattern for a 2-field object
User user = new User.Builder().name("Alice").age(30).build();
// β
β use record or constructor directly for small objects
record User(String name, int age) {}
var user = new User("Alice", 30);
Use record for any immutable data carrier. Keep builders only for objects with many optional fields.
4. Switch Expressions {#switch}
// β Switch statement with fall-through and break
String label;
switch (status) {
case ACTIVE: label = "Active"; break;
case INACTIVE: label = "Inactive"; break;
default: label = "Unknown";
}
// β
(Java 14+)
String label = switch (status) {
case ACTIVE -> "Active";
case INACTIVE -> "Inactive";
default -> "Unknown";
};
// β instanceof + cast
if (shape instanceof Circle) {
Circle c = (Circle) shape;
return c.radius() * c.radius() * Math.PI;
}
// β
Pattern matching (Java 16+)
if (shape instanceof Circle c) {
return c.radius() * c.radius() * Math.PI;
}
5. Concurrency {#concurrency}
// β Raw Thread creation
Thread t = new Thread(() -> doWork());
t.start();
// β
ExecutorService exec = Executors.newVirtualThreadPerTaskExecutor(); // Java 21
exec.submit(() -> doWork());
// β synchronized on this for fine-grained state
synchronized(this) { counter++; }
// β
AtomicInteger counter = new AtomicInteger();
counter.incrementAndGet();
Prefer CompletableFuture.allOf() over blocking .get() chains for parallel async work.
6. Error Handling {#errors}
// β Catching Exception to log and swallow
try {
risky();
} catch (Exception e) {
log.error("error", e);
}
// β
β rethrow as unchecked if you can't handle it
try {
risky();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
// β Checked exceptions declared on every method
β¦
FAQ
What are 'Records' in Java?
Records are a simple way to create immutable classes that hold data, like an 'information container', without needing to write much repetitive code.
Why use 'Optional'?
Optional helps handle values that may or may not exist (avoiding 'null' errors), making the code safer and clearer about what to expect.
What are 'Streams'?
Streams are a way to process sequences of data (like lists) more declaratively and efficiently, allowing you to chain operations like filtering and transforming.
Details
Original description by the author
Language-specific super-code guidelines for java.
Popularity
- GitHub stars
- 48k
- Ranking position
- #5893
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.