How to Write Bad Java Code
summary
Shows concrete bad-Java patterns and concrete fixes: using string concatenation in a loop creates O(n^2) allocations—use StringBuilder; boxing/unboxing in hot loops wastes objects, prefer primitives; compiling regex inside a loop is slow—compile regex once; method calls can be inlined by the JIT but avoid hot-path indirection; ArrayList random access is orders of magnitude faster than LinkedList; AI pitfalls include missing equals/hashCode keys causing OOM, hallucinated libraries, and SQL with no LIMIT causing million-row queries; recommends multi-model checks and strict prompts like “no third-party libs outside Spring Boot.”
AI-written summary · about
chapters (18)
- 0:00Introduction and AI in coding
- 1:26Inefficient string concatenation
- 5:18Pyramid of doom with null checks
- 8:08Boxing and unboxing overhead
- 10:36Regex compilation in loops
- 12:00Method call overhead in loops
- 15:29Invariant code in loops
- 16:52ArrayList vs LinkedList performance
- 21:07AI-generated optimizations
- 26:07Exception-driven flow control
- 28:13Missing equals and hashCode
- 32:08Unlimited SQL query results
- 35:00AI hallucinated libraries
- 36:47Synchronization pitfalls
- 38:12Virtual threads and locks
- 39:35AI confidence and pitfalls
- 42:22Prompt engineering for AI
- 45:11Q&A and closing
