← SEARCHABLE ARCHIVE
Java · 2026-07-13

Java from Basics to Mastery — Part 1

Starting Java with the JVM, classes, and collections

INTERACTIVE READING MODE →

The articles written on this blog were created with the goal of teaching. Also, the information in the article may be incorrect, so please be careful.

Java is a statically typed programming language that runs on the JVM. Each operating system has a JVM implemented, so the same bytecode can be executed in multiple environments.

Source code becomes bytecode

Java source files are compiled into .class bytecode files. The JVM reads this bytecode and executes it in the current environment.

Main.java
   ↓ javac
Main.class
   ↓ JVM
run program

Start a program in a class

public class Main {
    public static void main(String[] args) {
        Player player = new Player("Rose");
        player.takeDamage(25);
        System.out.println(player.getHealth());
    }
}

class Player {
    private final String name;
    private int health = 100;

    Player(String name) {
        this.name = name;
    }

    void takeDamage(int amount) {
        health = Math.max(0, health - amount);
    }

    int getHealth() {
        return health;
    }
}

private fields can only be accessed directly from inside the class. The constructor receives the initial values needed when the object is created, and methods express the object's behavior.

Specify a type for a collection

List<String> items = new ArrayList<>();
items.add("Potion");
items.add("Key");

for (String item : items) {
    System.out.println(item);
}

The generic type String specifies the type of value stored in the list. The compiler can check in advance whether a value of the wrong type is entered.

The memory used by Java objects is managed by the garbage collector. However, resources that need to be closed, such as database connections or files, should have their lifetimes managed with try-with-resources.

When starting Java, the priority is to complete a small program using classes, methods, exceptions, and collections rather than all the internal structures of the JVM. After that, you can manage the project and external libraries with Gradle or Maven.