with one click
java
Language-specific super-code guidelines for java.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Language-specific super-code guidelines for java.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.
AI-powered presentation generation via the 2slides API — create slides from text, match a reference image style, summarize documents into decks, add AI voice narration, and export pages/audio. Use for any "make slides", "create a deck", or "slides from this document" request.
Structured guide for setting up A/B tests with mandatory gates for hypothesis, metrics, and execution readiness.
When the user wants to plan, design, or implement an A/B test or experiment, or build a growth experimentation program. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "should I test this,"...
Diff a live page's accessibility violations against a baseline — by default compares uncommitted changes (stash-based), or pass --branch [<name>] to diff against a branch. Reports only new violations introduced, violations fixed, and pre-existing count. Use `scan` for a full audit with no diffing.
Add an iOS App Clip target to an Expo app. Use when the user mentions App Clip, AASA, apple-app-site-association, appclips, smart app banner, or wants to ship a lightweight iOS Clip invoked from a URL alongside their parent app.
| name | java |
| description | Language-specific super-code guidelines for java. |
| risk | safe |
| source | community |
| date_added | 2026-06-16 |
// ❌ 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()).
// ❌ 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); }
// ❌ 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.
// ❌ 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;
}
// ❌ 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.
// ❌ 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
public void process() throws IOException, SQLException, ParseException { ... }
// ✅ — wrap at the boundary; internal methods throw unchecked
| Anti-pattern | Preferred |
|---|---|
new ArrayList<String>() (Java 7+) | new ArrayList<>() (diamond) |
"string".equals(variable) (Yoda) | Objects.equals(variable, "string") |
for (int i = 0; i < list.size(); i++) | enhanced for or stream |
StringBuffer in single-threaded code | StringBuilder |
e.printStackTrace() | log.error("msg", e) |
null return for "not found" | Optional<T> return type |
| Public fields | private + accessor, or record |
Mutable static fields | avoid; use dependency injection |
instanceof + cast without pattern matching | pattern matching (Java 16+) |