Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/nedcodes-ok/cursorrules-collection/javagit clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collectionWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.01083 | $0.01083 |
| Opus 5 | $0.00541 | $0.00541 |
| Sonnet 5 | $0.00217 | $0.00217 |
| Haiku 4.5 | $0.00108 | $0.00108 |
Grade A, and why
java scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 55 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Java Cursor Rules
You are an expert Java developer (17+, preferably 21+). Follow these rules:
Modern Java Features
- Target Java 17+ minimum: records, sealed classes, pattern matching for instanceof, text blocks, switch expressions
- Java 21+: virtual threads, record patterns, sequenced collections, pattern matching for switch
record UserDTO(String name, String email) {}for immutable data carriers — replaces POJOs with equals/hashCode/toString generated. Don't add mutable fields or setters to recordssealed interface Shape permits Circle, Rectangle {}for closed type hierarchies — the compiler ensures all subtypes are handled in switch/pattern matching- Text blocks (
""") for multi-line strings (SQL, JSON, HTML templates) — no more string concatenation hell - Switch expressions:
var label = switch(status) { case ACTIVE -> "Active"; case INACTIVE -> "Disabled"; };— exhaustiveness checked by compiler with sealed types
Design
- Composition over inheritance —
extendscreates tight coupling. Use interfaces + delegation Optional<T>for return types that may be absent. Never use Optional as a method parameter, field, or collection element — it's a return type signal, not a general-purpose wrapper- Immutable by default:
finalfields, no setters, constructor initialization. Userecordor manually immutable classes. Mutable state is the source of most concurrency bugs - Dependency injection via constructor, not field injection (
@Autowiredon fields) — constructor injection is explicit, testable, and fails fast on missing dependencies
Collections & Streams
List.of(),Map.of(),Set.of()for immutable collections — they throw on modification attempts.List.copyOf()for defensive copies- Stream API for transformations, keep chains to 4-5 operations max. Beyond that, extract intermediate variables or helper methods — unreadable streams are worse than loops
varfor local variables when the type is obvious from the right side:var users = repository.findAll(). Don't usevarwhen the type isn't clear:var result = process(data)— what's result?EnumMap/EnumSetfor enum-keyed collections — faster and more memory-efficient than HashMap/HashSet with enum keystoList()(Java 16+) over.collect(Collectors.toList())— shorter and returns an unmodifiable list
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- yesterday First seen · 55 lines · 1,083 tokens per session scan A 9cfe72f7a647
java is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 1,083 tokens to every session, about $0.0054 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.