{"skill":{"slug":"java","displayName":"Java","summary":"Write robust Java avoiding null traps, equality bugs, and concurrency pitfalls.","description":"---\nname: Java\nslug: java\nversion: 1.0.1\ndescription: Write robust Java avoiding null traps, equality bugs, and concurrency pitfalls.\nmetadata: {\"clawdbot\":{\"emoji\":\"☕\",\"requires\":{\"bins\":[\"java\",\"javac\"]},\"os\":[\"linux\",\"darwin\",\"win32\"]}}\n---\n\n## Quick Reference\n\n| Topic | File |\n|-------|------|\n| Nulls, Optional, autoboxing | `nulls.md` |\n| Collections and iteration traps | `collections.md` |\n| Generics and type erasure | `generics.md` |\n| Concurrency and synchronization | `concurrency.md` |\n| Classes, inheritance, memory | `classes.md` |\n| Streams and CompletableFuture | `streams.md` |\n| Testing (JUnit, Mockito) | `testing.md` |\n| JVM, GC, modules | `jvm.md` |\n\n## Critical Rules\n\n- `==` compares references, not content — always use `.equals()` for strings\n- Override `equals()` must also override `hashCode()` — HashMap/HashSet break otherwise\n- `Optional.get()` throws if empty — use `orElse()`, `orElseGet()`, or `ifPresent()`\n- Modifying while iterating throws `ConcurrentModificationException` — use Iterator.remove()\n- Type erasure: generic type info gone at runtime — can't do `new T()` or `instanceof List<String>`\n- `volatile` ensures visibility, not atomicity — `count++` still needs synchronization\n- Unboxing null throws NPE — `Integer i = null; int x = i;` crashes\n- `Integer == Integer` uses reference for values outside -128 to 127 — use `.equals()`\n- Try-with-resources auto-closes — implement `AutoCloseable`, Java 7+\n- Inner classes hold reference to outer — use static nested class if not needed\n- Streams are single-use — can't reuse after terminal operation\n- `thenApply` vs `thenCompose` — compose for chaining CompletableFutures\n- Records are implicitly final — can't extend, components are final\n- `serialVersionUID` mismatch breaks deserialization — always declare explicitly\n","tags":{"latest":"1.0.1"},"stats":{"comments":0,"downloads":3437,"installsAllTime":128,"installsCurrent":16,"stars":9,"versions":2},"createdAt":1770679276509,"updatedAt":1778486238781},"latestVersion":{"version":"1.0.1","createdAt":1771100274767,"changelog":"Initial release","license":null},"metadata":{"setup":[],"os":["linux","darwin","win32"],"systems":null},"owner":{"handle":"ivangdavila","userId":"s178jdk12x4qj3gs2se3etxf3h83h7ft","displayName":"Iván","image":"https://avatars.githubusercontent.com/u/81719670?v=4"},"moderation":null}