This episode covers Java primitive data 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.

Every program ultimately works with data. Episode 4 covers data types, variables, and operators — the raw materials you will use in every line of Java code. You will get to know the eight primitive types, how to declare variables and constants, and the various operators for processing values.
Java is a statically typed language, which means the type of every variable is determined at compile time. This requires you to think about data types from the very beginning. After this episode, you will choose the right type and write correct expressions with confidence.
Java has eight primitive types that store values directly, not objects:
byte: 8-bit, range -128 to 127.short: 16-bit, range roughly -32 thousand to 32 thousand.int: 32-bit, the default type for whole numbers.long: 64-bit for very large numbers, suffix with the letter L.float: 32-bit single precision, suffix with the letter F.double: 64-bit double precision, the default for fractions.char: 16-bit, a single Unicode character in single quotes.boolean: only true or false.int umur = 30;
long populasi = 8_000_000_000L;
double harga = 19.99;
float diskon = 0.1F;
char inisial = 'A';
boolean aktif = true;Notice the literal 8_000_000_000L — underscores make large numbers easier to read, and the L suffix marks it as a long type.
A local variable is declared inside a method and only lives while the method runs. A field is a variable belonging to a class or object, declared at the class level. Example:
public class Akun {
private double saldo; // field
public void setor(double jumlah) {
double biaya = 1000; // variabel lokal
saldo = saldo + jumlah - biaya;
}
}A constant is a value that cannot be changed once set, using the final keyword. If static is added, the constant belongs to the class, not to an instance:
public class Konfigurasi {
public static final int MAX_RETRIES = 3;
public static final String APP_NAME = "AplikasiKu";
}Konfigurasi.MAX_RETRIES is accessed without creating an object because it is static. The convention for writing constants is UPPER_SNAKE_CASE.
Arithmetic operators work on numbers: +, -, *, /, and % for modulus (remainder). Example:
int a = 17;
int b = 5;
System.out.println(a + b); // 22
System.out.println(a % b); // 2The comparison operators ==, !=, <, >, <=, >= produce boolean results. The logical operators &&, ||, and ! combine conditions:
boolean dewasa = umur >= 17;
boolean punyaKTP = true;
boolean bolehMasuk = dewasa && punyaKTP;Bitwise operators work per-bit on whole numbers: &, |, ^, ~, plus the shifts <<, >>. The ternary operator is a short form of if-else that produces a value:
int nilai = 85;
String status = nilai >= 75 ? "Lulus" : "Tidak Lulus";The expression nilai >= 75 ? "Lulus" : "Tidak Lulus" evaluates a condition, then returns the first value if it is true and the second if it is false.
Every primitive type has a matching wrapper class: Integer, Long, Double, Float, Byte, Short, Character, and Boolean. Wrappers are needed when data must be an object, for example in generic collections.
Autoboxing converts a primitive into a wrapper automatically, and unboxing converts it back. Example:
Integer angka = 42; // autoboxing
int nilaiPrimitif = angka; // unboxing
System.out.println(angka + 8);Wrapper classes can be null, whereas primitives cannot. Calling a method on a null wrapper triggers a NullPointerException. Checking for null is an important habit:
Integer bonus = null;
if (bonus != null) {
System.out.println(bonus + 100);
} else {
System.out.println("Bonus tidak tersedia");
}The pattern above is the basis of null-safety. Episode 7 will discuss more complete null handling through exception handling and Optional.
Episode 4 builds the foundation of data management: getting to know the eight primitive types, understanding the differences between local variables, fields, and constants with final and static, mastering arithmetic, logical, bitwise, and ternary operators, and understanding boxing, unboxing, wrapper classes, and null-safety.
Key takeaways:
final makes a value immutable; static makes a member belong to the class.null; always check before using them.In the next episode, episode 5, we will discuss control flow and basic data structures — conditional statements if, else, and modern switch expressions, for, while, do-while, enhanced for, and iterator loops, the basic collections array, ArrayList, LinkedList, Set, and Map, and an introduction to the Stream API for iterating collections.