Article start
Java Programming: From Zero to Enterprise
1. Java Fundamentals

1. Getting Started with Java & the JVM

Understand how Java works under the hood and run your first program.

February 22, 2026·185

[!NOTE] Welcome to your first step into the Java ecosystem. By the end of this chapter, you will understand the fundamental architecture of the Java language, how its compilation process differs from languages like C++, and you will write your very first program.

The Core Philosophy of Java

Java was introduced by Sun Microsystems in 1995 with a revolutionary mantra: "Write Once, Run Anywhere" (WORA).

In previous decades, if you wrote a program in C or C++, you had to manually compile separate versions of your program for Windows, for Mac, and for Linux. Furthermore, you had to manage memory manually, leading to catastrophic system crashes if you accidentally caused a "memory leak".

Java solved this by introducing an abstraction layer over the operating system: The Java Virtual Machine (JVM).

The Lifecycle of Java Code

Unlike interpreted languages (like Python) that read code line-by-line, and unlike fully compiled languages (like C) that translate directly into raw machine code, Java takes a hybrid approach.

StepComponentActionOutput
1ProgrammerWrites human-readable code..java source file
2Compiler (javac)Checks syntax and translates to intermediate code..class bytecode file
3JVM (java)Reads bytecode and translates it to machine instructions.Execution on OS

[!TIP] TL;DR: Always remember the pipeline: Source -> Compiler -> Bytecode -> JVM -> OS.

Writing Your First Program

Let's look at the absolute minimum amount of code required to print something to the screen.

public class HelloWorld {
    // This is the entry point
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Let's break down this famously verbose syntax line by line:

  1. public class HelloWorld

Java is aggressively Object-Oriented. Everything must live inside a class (a blueprint). The keyword public means this class is accessible from anywhere.

[!CAUTION] If your class is public, the filename must exactly match the class name. This file must be saved as HelloWorld.java, matching the casing perfectly.

  1. public static void main(String[] args)

This is the Entry Point of your application. When the JVM starts your program, it specifically looks for a method with this exact, precise signature.

  • public: The JVM can access it from outside the class.
  • static: The JVM can run this method without needing to create an instance (object) of the HelloWorld class first.
  • void: This method does not return any data back to the JVM when it finishes.
  • String[] args: An array of Strings that allows you to pass command-line arguments into your program when you start it.

  1. System.out.println("Hello, World!");

This is the command that actually prints the text to your console.

  • System: A built-in class providing access to system resources.
  • out: A static member of the System class representing the standard output stream (your console/terminal).
  • println: A method that prints the text and then moves the cursor to a new line.

Summary

While Java may seem terribly wordy at first compared to Python (print("Hello")), this rigid, strictly typed structure is exactly what makes Java the backbone of massive enterprise architectures. It prevents silly mistakes and naturally forces you into organized design patterns.

How This Looks in a Real Java Setup

When you write Java professionally, you usually do not run only one tiny file forever. You write many classes, organize them into packages, compile them into bytecode, and run them with a chosen JDK. The important mental model is still the same: your .java source is compiled into .class bytecode, and the JVM executes that bytecode.

A beginner mistake is to think the JVM is only an interpreter. Modern JVMs are much smarter. They start by reading bytecode, then use a Just-In-Time compiler to optimize frequently executed code while the program runs. That is one reason Java can be both portable and fast for long-running server applications.

JDK vs JRE vs JVM

TermMeaningWhen you care
JVMRuns Java bytecodeWhen understanding execution and memory
JRERuntime environment for running Java appsWhen only executing an already-built app
JDKDeveloper kit with compiler, runtime, and toolsWhen writing and compiling Java code

Practice From the Terminal

javac HelloWorld.java
java HelloWorld

If compilation succeeds, you should see a HelloWorld.class file. If running succeeds, the JVM finds the main method and starts there.

Common Mistakes

  • Saving public class HelloWorld inside a file named helloWorld.java. Java class names are case-sensitive.
  • Running java HelloWorld.class. Use java HelloWorld without the .class extension.
  • Changing the main method signature. The JVM expects public static void main(String[] args).

Mini Practice

Create a file named Profile.java. Print your name, your learning goal, and one reason you want to learn Java. Compile it, run it, then intentionally rename the file incorrectly and observe the compiler error.

Practice Lab: Run Java Like a Developer

Build confidence with the compile-and-run flow instead of only reading about it.

  1. Create HelloProfile.java.
  2. Print your name, city, and current Java learning goal.
  3. Compile with javac HelloProfile.java.
  4. Run with java HelloProfile.
  5. Rename the class or file incorrectly and read the compiler error carefully.

Goal: You should be able to explain the difference between source file, bytecode file, and JVM execution.

Revision Checkpoint

  • Pipeline: .java source is compiled by javac into .class bytecode, then executed by the JVM.
  • JDK: Needed for development because it includes compiler tools.
  • JVM: Runs bytecode and provides portability across operating systems.
  • Main method: public static void main(String[] args) is the application entry point.
  • Filename rule: A public class name must match the filename exactly.

Before the quiz: Explain the difference between JDK, JRE, and JVM in your own words.

Lesson 1 of 10 in 1. Java Fundamentals