This episode covers Java syntax and code structure: creating your first program, declaring classes, methods, fields, and access visibility, understanding statements, blocks, comments, and naming rules, and running applications from the command line and IDE.

Episode 2 introduced the Java architecture; now it is time to write code. Episode 3 covers basic syntax and Java code structure — the language used throughout this entire series. You will create your first program and understand class declarations, methods, fields, and access visibility.
Java has explicit, structured syntax. Every program consists of classes, methods, and statements with strict rules. After this episode, you will be able to read and write simple Java programs with confidence.
Every Java program minimally has one class and one main method. The main method is the entry point of execution. Consider the following example:
public class Halo {
public static void main(String[] args) {
System.out.println("Halo, Java!");
}
}The structure above shows: the public keyword for visibility, class Halo for the class declaration, and a main method with a String[] args parameter that holds the arguments passed from the command line.
Save it as Halo.java then run:
javac Halo.java
java Halojavac Halo.java compiles it, and java Halo runs it. The file name must match the public class name exactly — this is an important rule that is often a source of beginner errors.
A class is the blueprint, a field is a variable that stores state, and a method is behavior. Field declarations can use different access levels:
public class Mahasiswa {
public String nama;
private int umur;
protected String jurusan;
public void perkenalkan() {
System.out.println("Nama: " + nama + ", umur: " + umur);
}
}Java has four access modifiers:
public: accessible from anywhere.protected: accessible within the same package and by subclasses.private: only within the same class.Choosing the right visibility is the foundation of encapsulation, which will be discussed in episode 6. The rule of thumb: fields should be private, and public methods only for the API you actually expose.
A statement is a single command ending with a semicolon. A block is a group of statements wrapped in curly braces, usually belonging to a method or control flow.
public class Contoh {
public static void main(String[] args) {
int nilai = 10; // statement
if (nilai > 5) { // awal blok
System.out.println(nilai);
} // akhir blok
}
}Comments are not executed by the compiler and are useful for documentation:
// Komentar satu baris
/*
* Komentar beberapa baris
* bisa memuat banyak penjelasan
*/
/** Javadoc untuk dokumentasi API */
public void metode() {
}Java follows consistent naming conventions:
Mahasiswa or OrderService.hitungTotal or namaLengkap.MAX_RETRIES.com.aplikasi.Following these conventions makes your code readable by the entire Java ecosystem.
The JDK provides jshell, a REPL for testing syntax without creating files. This is the best way to experiment with small pieces of code:
jshell
int a = 5;
int b = 10;
System.out.println(a + b);jshell evaluates each line immediately and shows the result. It is very useful for testing expressions or trying out APIs before writing them into a file.
In IntelliJ IDEA or VS Code with the Java extension, you just press the Run button next to the main method. The IDE handles compilation automatically behind the scenes. However, it is important to still understand the javac and java commands, because production pipelines usually run without an IDE.
Episode 3 builds the foundation of Java syntax: creating your first program with a main method, declaring classes, fields, and methods with four visibility levels, understanding statements, blocks, and comments, following naming rules, and running applications from the CLI and IDE.
Key takeaways:
main method.public, protected, package-private, and private.jshell is your best friend for testing syntax quickly.In the next episode, episode 4, we will discuss data types, variables, and operators — the primitive types byte, short, int, long, float, double, char, and boolean, local variables, fields, constants with final and static, arithmetic, logical, bitwise, and ternary operators, as well as boxing, unboxing, wrapper classes, and basic null-safety.