This episode examines how Java works behind the scenes: the process of compiling source code into bytecode, the JVM architecture with the class loader, bytecode verifier, JIT compiler, and garbage collector, the roles of JVM, JRE, and JDK, the standard project structure, and classpath, module path, and JPMS.

Episode 1 explained why Java exists. Episode 2 discusses how Java works. This is the most fundamental episode in the entire series: you will dissect the JVM architecture, understand the differences between JDK, JRE, and JVM, and get to know the project structure and the class management mechanism.
This understanding is not just theory. When you face errors such as ClassNotFoundException or NoClassDefFoundError, or when you have to configure the classpath for external libraries, the knowledge from this episode will be your lifesaver.
Every Java program starts as a source file with the .java extension. The javac compiler turns it into bytecode with the .class extension. Bytecode is not native machine code; it is platform-neutral instructions for the JVM.
The flow is simple: source code .java is compiled into bytecode .class, then executed by the JVM. To see the result, create a file named Halo.java and run:
public class Halo {
public static void main(String[] args) {
System.out.println("Halo dari JVM");
}
}Compile and run:
javac Halo.java
java Halojavac Halo.java produces Halo.class, and java Halo loads and executes that class on the JVM. Notice that the java command uses the class name, not the file name.
To see the contents of the bytecode, use the javap tool:
javap -c Halojavap -c Halo shows bytecode instructions such as getstatic and invokevirtual. This proves that Java does not execute machine code directly, but virtual instructions run by the JVM.
The JVM works through several collaborating components:
.class files into memory when needed.When java is run, the class loader loads the main class along with its dependencies, the verifier checks the safety of the bytecode, then the interpreter or JIT compiler executes the instructions. The JVM also manages heap memory, monitors threads, and runs garbage collection periodically.
load class -> verify bytecode -> interpret / JIT compile -> run & collect garbagejavac compiler and development tools needed to create applications.JDK berisi JRE berisi JVMTo develop applications, you need the JDK. To simply run applications, the JRE is enough. That is why we installed the JDK in episode 0 — because this series also involves writing code.
Modern Java projects follow a standard structure that Maven and Gradle understand:
src/main/java: main source code.src/test/java: test source code.src/main/resources: configuration files and non-Java assets.This structure is a convention that makes projects easy to understand and automate.
A package groups classes into namespaces to avoid name conflicts. The convention uses reversed domain names, for example com.perusahaan.aplikasi. Packages are also the foundation of dependency management and modules.
The classpath tells the JVM where to find classes and libraries. When running a program with external dependencies, you set the classpath with the -cp flag:
java -cp .:lib/library.jar com.aplikasi.Main-cp .:lib/library.jar tells the JVM to look for classes in the current directory and in the JAR file. If a library is not found on the classpath, a ClassNotFoundException appears.
Java 9 introduced the Java Platform Module System (JPMS) as a modern dependency management feature. Modules are declared in a module-info.java file and run via the module path, not the classpath. JPMS provides stronger encapsulation because each module declares which packages it exports.
classpath: daftar direktori dan JAR, tidak ada batasan akses
module path: modul dengan deklarasi requires dan exportsEpisode 18 will cover JPMS in depth. For now, understand that the classpath is the classic mechanism, while the module path is its modern evolution.
Episode 2 dissects the technical foundations of Java: the compilation process from source code to bytecode, the JVM architecture with its four core components, the differences between JDK, JRE, and JVM, the standard project structure, and the classpath and module path mechanisms.
Key takeaways:
javac turns source code into .class bytecode, then java executes it on the JVM.src/main/java, src/test/java, and src/main/resources.ClassNotFoundException is usually caused by a wrong classpath.In the next episode, episode 3, we will discuss basic syntax and Java code structure — your first program, class declarations, methods, fields, and access visibility, statements, blocks, comments, naming rules, and running applications from the command line and IDE. Time to write real code!