🎁 Get the FREE AI Skills Starter Guide β€” Subscribe β†’
BytesAgainBytesAgain
πŸ¦€ ClawHub

Java

by @ivangdavila

Write robust Java avoiding null traps, equality bugs, and concurrency pitfalls.

Versionv1.0.1
Downloads4,140
Stars⭐ 9
TERMINAL
clawhub install java

πŸ“– About This Skill


name: Java slug: java version: 1.0.1 description: Write robust Java avoiding null traps, equality bugs, and concurrency pitfalls. metadata: {"clawdbot":{"emoji":"β˜•","requires":{"bins":["java","javac"]},"os":["linux","darwin","win32"]}}

Quick Reference

| Topic | File | |-------|------| | Nulls, Optional, autoboxing | nulls.md | | Collections and iteration traps | collections.md | | Generics and type erasure | generics.md | | Concurrency and synchronization | concurrency.md | | Classes, inheritance, memory | classes.md | | Streams and CompletableFuture | streams.md | | Testing (JUnit, Mockito) | testing.md | | JVM, GC, modules | jvm.md |

Critical Rules

  • == compares references, not content β€” always use .equals() for strings
  • Override equals() must also override hashCode() β€” HashMap/HashSet break otherwise
  • Optional.get() throws if empty β€” use orElse(), orElseGet(), or ifPresent()
  • Modifying while iterating throws ConcurrentModificationException β€” use Iterator.remove()
  • Type erasure: generic type info gone at runtime β€” can't do new T() or instanceof List
  • volatile ensures visibility, not atomicity β€” count++ still needs synchronization
  • Unboxing null throws NPE β€” Integer i = null; int x = i; crashes
  • Integer == Integer uses reference for values outside -128 to 127 β€” use .equals()
  • Try-with-resources auto-closes β€” implement AutoCloseable, Java 7+
  • Inner classes hold reference to outer β€” use static nested class if not needed
  • Streams are single-use β€” can't reuse after terminal operation
  • thenApply vs thenCompose β€” compose for chaining CompletableFutures
  • Records are implicitly final β€” can't extend, components are final
  • serialVersionUID mismatch breaks deserialization β€” always declare explicitly