Section 11 · Stage 3: Master Java
JVM Internals & Memory Management
How the JVM loads and runs your code, how memory is organised, how garbage collection works and how to find memory problems.
What you will be able to do
- Explain how a .java file becomes running code: bytecode, class loading and the JIT
- Describe where the JVM keeps classes, objects, local variables and threads in memory
- Explain how garbage collection finds and removes unused objects
- Choose basic heap and garbage collector settings and read a GC log
- Find memory leaks and diagnose OutOfMemoryError and StackOverflowError with JDK tools
What you will learn
11.1From Source to Bytecode7 lessons
Follow a .java file to running code, look inside the class file and read the bytecode javac produces.
11.2Class Loading8 lessons
How and when the JVM finds, checks and prepares your classes, and what the common class loading errors mean.
- What class loading means35 min
- Loading, linking and initialization40 min
- The bootstrap, platform and application class loaders35 min
- Parent delegation40 min
- When a class is initialized40 min
- ClassNotFoundException versus NoClassDefFoundError40 min
- Custom class loaders and class identity45 min
- Class loading practice50 min
11.3Execution Engine & JIT7 lessons
How bytecode actually runs and why Java code gets faster after it warms up.
11.4JVM Memory Areas8 lessons
The parts of JVM memory, what lives in each one and which error you get when one runs out.
- The JVM memory map30 min
- Stack frames and local variables30 min
- Heap versus stack35 min
- Each thread's own stack35 min
- Metaspace, static fields and the String pool35 min
- StackOverflowError and OutOfMemoryError: which area ran out40 min
- Memory areas review: trace a whole program40 min
- Memory areas practice45 min
11.5Objects in Memory7 lessons
How much space objects really take and what that means for your code.
11.6Garbage Collection Basics8 lessons
How the JVM decides an object is garbage and cleans it up.
11.7Garbage Collectors & JVM Options7 lessons
The main collectors and the few JVM options an entry-level developer should know.
11.8References & Memory Leaks8 lessons
How Java programs leak memory even with a garbage collector, and the reference types that help.
- What a memory leak means in Java35 min
- Strong, soft, weak and phantom references40 min
- WeakHashMap and safe caches40 min
- Cleaner and cleaning up resources40 min
- Leaks from static collections and caches35 min
- Leaks from listeners, resources and ThreadLocal40 min
- Inner classes that hold the outer object35 min
- Memory leaks practice45 min
11.9Diagnosing Memory Problems9 lessons
Use the JDK's own tools to see what the JVM is doing and find the cause of a problem.
- Find and inspect a JVM with jps and jcmd35 min
- Watch the heap with jstat35 min
- Taking a heap dump35 min
- Reading a heap dump40 min
- Reading a thread dump35 min
- VisualVM and JDK Mission Control35 min
- Reading an OutOfMemoryError message35 min
- A step-by-step diagnosis workflow40 min
- Diagnosing memory problems practice45 min
11.10JVM Practice & Case Studies5 lessons
Work through broken programs with JDK tools and find out what went wrong inside the JVM.
