Java & Spring Boot Enterprise Mastery · Chapter 1 · ~15 min · Beginner
Your First Java Program & How Java Runs
Demystify the world's most battle-tested enterprise programming language. Write your first program, understand how Java enforces strict types, and see how the Java Virtual Machine runs your code anywhere.
- Deconstruct the anatomy of a Java program line by line
- Store numbers, text, and true/false values with strict types
- Understand why Java compiles to bytecode (.class)
- Run code and inspect variables in the live JVM simulator
1Why Java Runs the World's Enterprise Systems
Java was created with a revolutionary promise: "Write Once, Run Anywhere". Before Java, if you wrote a program on Windows, it would crash on a Mac or a Linux server without being rewritten and recompiled for that specific processor.
Today, Java powers global banking systems (where losing a penny is unacceptable), Android smartphones, massive streaming backends (like Netflix), and games like Minecraft.
Type Safety
Java checks all data types before running. If you accidentally pass text to a math calculation, Java stops you at compile time.
The JVM
Your code compiles into universal Bytecode that runs identically on any device with a Java Virtual Machine installed.
Garbage Collection
You never have to manually allocate or delete memory blocks; the Java runtime cleans up unused objects automatically.
What does Java's slogan 'Write Once, Run Anywhere' mean in practice?
2Anatomy of Your First Java Program
Here is the standard Java program that every developer learns first:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}At first glance, it looks like a lot of words just to print one line of text! Let's break down each part:
1. public class Main
In Java, every line of code must live inside a class. By convention, the class name matches the file name (Main.java).
2. public static void main(String[] args)
This is the front door of your program. Whenever Java starts, it searches for this exact method name to begin execution.
3. System.out.println("Hello, World!");
Prints the text inside quotes to the console screen and starts a new line (ln = line).
Why is 'public static void main(String[] args)' required in a standalone Java application?
3Variables and Strict Data Types
A variable is a named storage container for holding data in memory. Because Java is statically typed, you must tell Java what kind of data the container holds when you create it:
int age = 21; // Whole numbers (-2 billion to +2 billion)
double price = 19.99; // Decimals and fractional numbers
boolean isStudent = true; // Only true or false
char grade = 'A'; // Single character in single quotes
String name = "Alex"; // Text string in double quotesJoining Words and Numbers (Concatenation)
You can combine variables and text using the + operator:
System.out.println("Hello, " + name + "! You are " + age + " years old.");Which line of code correctly stores the price $9.95 in Java?
4How Java Runs: javac and the JVM
When you run Python or JavaScript, the interpreter reads your code directly line by line. Java works differently using a 2-step process:
You run javac Main.java. The compiler checks for errors and translates your code into compact Bytecode (Main.class).
You run java Main. The Java Virtual Machine loads the .class file and executes it blazingly fast on your machine.
What file does the 'javac Main.java' command produce?
5Hands-On: Test Java Code Live
Click through the starter programs below to simulate compiling and running Java code. Watch the console output and inspect how variables are stored in RAM:
Live Java Compilation & Execution Simulator
Select a starter Java program:
Java Source File (Main.java):
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
System.out.println("Welcome to Java programming.");
}
}Hello, World! Welcome to Java programming.
This program only prints text. No variables declared.
6Chapter Knowledge Challenge
Test your Java syntax, typing, and compilation foundations before moving to Chapter 2:
Which data type should you choose to store a bank customer's exact balance of $1250.75?
What is the key role of the Java Virtual Machine (JVM)?
7Recap
- Java is a statically typed, class-based programming language designed for extreme reliability and portability.
- Every standalone Java program starts execution inside
public static void main(String[] args). - Statements must always terminate with a semicolon (
;). - Basic data types include
int(integers),double(decimals),boolean(true/false), andString(text). - Java compiles human code (
.java) into bytecode (.class) withjavac, which the JVM runs anywhere.
Ready for Chapter 2? Mark this chapter as complete to proceed: