Command Palette

Search for a command to run...

EN·ES

Level 1 · 25 min

Java from Zero: Your First Application

Java is one of the most widely deployed languages in enterprise systems — banking, healthcare, e-commerce. Understanding it from first principles sets the foundation for everything else in this course.

What Java Actually Is

Java is a compiled + interpreted language. Your source code (.java) compiles to bytecode (.class files), which the JVM (Java Virtual Machine) then interprets and JIT-compiles to native machine code. This ''write once, run anywhere'' model is why Java powers Android devices, Linux servers, and Windows machines with the same .jar file. The JVM is not Java — it''s the engine. Java is one of many languages that run on it (Kotlin, Scala, Clojure also target the JVM).

Your First Program: Anatomy

Every Java program needs at minimum: 1. A class declaration matching the filename 2. A `public static void main(String[] args)` method — the entry point 3. Statements inside main that the JVM executes top to bottom Production insight from Effective Java: "Every class you write is a type, and types are the building blocks of your program''s structure." Getting class naming and package organization right from day one avoids expensive refactoring later.

Variables, Types, and the Type System

Java is statically typed — every variable has a declared type that the compiler checks at compile time. The eight primitive types (int, long, double, boolean, char, byte, short, float) store raw values directly. Reference types (String, arrays, and all objects) store a reference (pointer) to heap memory. Key rule: primitives cannot be null. Reference types can, which is the source of the infamous NullPointerException. Java 14+ has helpful NPE messages that tell you exactly which variable was null.

Key Takeaways

  • Java compiles to JVM bytecode — one binary runs on any OS with a JVM installed
  • Every Java program''s entry point is `public static void main(String[] args)` inside a public class
  • Primitives (int, boolean, double) live on the stack; Objects live on the heap and can be null

Code example

// HelloWorld.java
public class HelloWorld {
    public static void main(String[] args) {
        // Declare a variable
        String name = "trainee";
        int year = 2026;
        
        // String concatenation
        System.out.println("Hello, " + name + "!");
        
        // Formatted output (preferred in production)
        System.out.printf("Year: %d%n", year);
        
        // Conditional
        if (args.length > 0) {
            System.out.println("First arg: " + args[0]);
        } else {
            System.out.println("No arguments passed");
        }
        
        // Basic loop
        for (int i = 1; i <= 3; i++) {
            System.out.println("Iteration " + i);
        }
    }
}