Lesson 1 • Beginner
Java Fundamentals – Getting Started
Beginner-Safe, No Assumptions — Learn Java from absolute zero. Every concept is explained before it's used.
What You'll Learn in This Lesson
- ✓What Java is and why it's the #1 enterprise language
- ✓How to check if Java is installed on your computer
- ✓How to write, compile, and run your first Java program
- ✓What System.out.println() does and how strings work
- ✓Java program structure: classes, main method, statements
- ✓What errors mean — and how to read them without panicking
🔧 Before You Start: Do You Have Java?
To write and run Java programs on your own computer, you need the JDK (Java Development Kit). Let's check if it's already installed.
Windows:
Open Command Prompt (search "cmd" in Start menu) and type:
java --version
macOS / Linux:
Open Terminal and type:
java --version
If you see something like "java 21.0.x" — you're ready!
📁 Running Java on Your Computer
Let's create and run your very first Java program. Follow these steps exactly:
Step 1: Create a file
Open any text editor (Notepad, VS Code, or IntelliJ). Create a new file and name it exactly:
HelloWorld.java
⚠️ The filename must match the class name exactly (including capitalization). This is a Java rule — not optional.
Step 2: Write this code
Type (or copy) this into your file:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Step 3: Save the file
Save it somewhere you can find it easily (like your Desktop).
Step 4: Open your terminal
- Windows: Search "cmd" in Start menu → open Command Prompt
- macOS: Open Finder → Applications → Utilities → Terminal
- Linux: Press Ctrl+Alt+T or search "Terminal"
Step 5: Navigate to your file
Use the cd command to go to where you saved your file:
cd Desktop
Step 6: Compile the program
Unlike Python, Java needs to be compiled first. This turns your code into something the computer can run:
javac HelloWorld.java
This creates a file called HelloWorld.class — that's the compiled version.
Step 7: Run the program
java HelloWorld
Notice: no .java or .class extension when running — just the class name.
✅ Expected Output:
Hello, World!
If you see this — congratulations! You just compiled and ran your first Java program.
1️⃣ What Is Java? (Plain English)
Java is a programming language.
A programming language is a way for humans to give instructions to a computer. Think of it like learning a new language — but instead of talking to people, you're talking to machines.
Computers do nothing by themselves. They only follow instructions exactly as written. Your job is to write those instructions clearly.
Java is designed so that:
- Your code runs on any computer — Windows, Mac, Linux, Android
- Errors are caught before your program runs (not during)
- Large teams can work on the same codebase without chaos
Java is used for:
- Android apps (Instagram, Spotify were built with Java)
- Banking and financial systems (nearly every bank uses Java)
- Web servers and APIs (Netflix, Amazon, LinkedIn)
- Big data processing (Hadoop, Apache Spark)
- Enterprise software and government systems
- Game development (Minecraft was written in Java!)
🧠 Key Fact:
Java consistently ranks in the top 3 most in-demand programming languages worldwide. As of 2024, over 9 million developers use Java, and the average Java developer salary is $100K+ in the US.
2️⃣ What Is a Program?
A program is simply a list of instructions that a computer follows, one by one, from top to bottom.
Example in human language:
- Show a message on the screen
- Add two numbers together
- Display the result
In Java, this looks like:
System.out.println("Let me add some numbers...");
int result = 5 + 3;
System.out.println("5 + 3 = " + result);Don't worry about understanding every word yet. The key idea is: each line is one instruction, and Java runs them in order, top to bottom.
3️⃣ Your First Java Instruction: System.out.println()
What does System.out.println() do?
System.out.println() tells Java: "Show this on the screen."
It's the most basic way to make Java display something to you.
Example:
System.out.println("Hello, World!");Let's break this down piece by piece:
System→ a built-in Java class that gives you access to system functionsout→ the output stream (where text goes — usually your screen)println→ "print line" — displays text and moves to the next line("Hello, World!")→ the text you want to display (must be in quotes!);→ the semicolon at the end — every statement in Java must end with one
🧠 println vs print:
println() prints text and moves to the next line.
print() prints text but stays on the same line.
System.out.print("Hello ");
System.out.print("World");
// Output: Hello World (all on one line)system.out.println with a lowercase "s". Java is case-sensitive — it must be System with a capital S.Try It: Your First Java Output
See how println and print work — run this to see the difference!
// 💡 Try modifying this code and see what happens!
// This simulates Java's System.out.println() and System.out.print()
console.log("=== Your First Java Program ===");
console.log("");
// In Java: System.out.println("Hello, World!");
console.log("Hello, World!");
// In Java: System.out.println("Welcome to Java!");
console.log("Welcome to Java!");
console.log("");
console.log("=== println vs print ===");
console.log("");
// println adds a new line after each message
console.log("This is pri
...4️⃣ Quotes and Strings — VERY IMPORTANT
This is one of the most important things to understand early:
Java must know what is text and what is code.
Text MUST be wrapped in double quotes. Without quotes, Java gets confused.
This works:
System.out.println("Hello"); // ✅ CorrectThis does NOT work:
System.out.println(Hello); // ❌ Error!
Why does this fail?
Without quotes, Java thinks Hello is a variable name (a container for data). But no variable called Hello exists yet — so Java throws an error:
error: cannot find symbol
symbol: variable Hello🧠 Rule (memorise this):
Text = must be in double quotes "like this"
Single quotes 'A' are for single characters only (we'll learn about char later).
In programming, text is called a "String":
"Hello" // This is a String "I love Java!" // This is a String "12345" // This is also a String (not a number!) "" // This is an empty String
Important: "123" is a String (text), but 123 (no quotes) is a number. They are completely different things in Java.
5️⃣ Semicolons — Every Statement Needs One
In Java, every instruction (called a statement) must end with a semicolon ;
Think of it like a period at the end of a sentence. Without it, Java doesn't know where one instruction ends and the next begins.
System.out.println("Line 1"); // ✅ Good
System.out.println("Line 2"); // ✅ Good
System.out.println("Line 3") // ❌ Missing semicolon!What happens without a semicolon?
The compiler gives you an error like:
error: ';' expected
This is the #1 most common error for beginners. If you see this error, just add the missing ; at the end of the line.
🧠 Tip:
Class declarations and method declarations do NOT end with semicolons — only statements inside them do.
public class MyApp { // No semicolon here
public static void main(String[] args) { // No semicolon here
System.out.println("Hi"); // Semicolon here ✅
}
}6️⃣ Curly Braces — Code Blocks
Curly braces { } group code together into blocks. Every opening brace { must have a matching closing brace }.
public class HelloWorld { // Opens the class
public static void main(String[] args) { // Opens the method
System.out.println("Hi"); // Inside both blocks
} // Closes the method
} // Closes the class💡 Analogy: Think of curly braces like nesting boxes. The class is the outer box, the method is the inner box, and your instructions go inside the innermost box. Every box that opens must close.
}.7️⃣ Comments — Notes for Humans
Comments are notes you leave in your code. Java completely ignores them — they exist only for you and other developers to read.
// This is a single-line comment
System.out.println("Hello"); // You can also put them after code
/* This is a multi-line comment.
It can span as many lines
as you need. */
/** This is a Javadoc comment.
* Used to generate documentation.
* You'll use these when you're more advanced.
*/When should you use comments?
- To explain why you did something (not what the code does)
- To leave notes for yourself or teammates
- To temporarily disable code while testing
❌ Bad comment:
// print hello
System.out.println("Hello");We can already see it prints hello!
✅ Good comment:
// Greet user before showing menu
System.out.println("Hello");Explains the purpose, not the code.
Try It: Comments and Multiple Outputs
Practice using comments and printing multiple lines. Try adding your own messages!
// 💡 Try modifying this code and see what happens!
// This simulates a Java program with comments and multiple outputs
// === EXERCISE: Add your own println statements! ===
// In Java, you would write:
// public class MyInfo {
// public static void main(String[] args) {
// Print your name
console.log("My name is Alice"); // Change "Alice" to your name
// Print your age
console.log("I am 25 years old"); // Change 25 to your age
// Print your favourite language
console.log("I'
...8️⃣ How Java Actually Runs: Compile → Run
Java is different from languages like Python or JavaScript. Java needs two steps to run:
.java file (e.g., HelloWorld.java). This is human-readable source code.javac HelloWorld.java converts your code into bytecode — a .class file. If your code has errors, they're caught here!java HelloWorld starts the JVM (Java Virtual Machine), which reads the bytecode and runs it on any platform.HelloWorld.java → javac → HelloWorld.class → JVM → Output (your code) (compile) (bytecode) (run) (screen)
💡 Analogy: Think of it like cooking a recipe. You write the recipe (code), then a translator converts it into a universal language (bytecode), and any kitchen in the world (JVM) can follow it. That's "Write Once, Run Anywhere."
9️⃣ When Things Go Wrong: Reading Error Messages
Errors are completely normal. Even experienced developers get errors constantly. The key is learning to read them.
Error 1: Missing semicolon
System.out.println("Hello") // forgot the ;HelloWorld.java:3: error: ';' expected
System.out.println("Hello")
^Java tells you: the file, the line number (3), and exactly where the problem is (^). Just add the ;!
Error 2: Wrong class name
// File is called HelloWorld.java but code says:
public class Helloworld { // lowercase 'w' — doesn't match!error: class Helloworld is public, should be declared in a file named Helloworld.java
Fix: make sure the class name matches the filename exactly (including uppercase/lowercase).
Error 3: Wrong capitalization
system.out.println("Hello"); // lowercase 's'!error: package system does not exist
Fix: it's System with a capital S. Java is case-sensitive!
🧠 How to read any Java error:
- Look at the line number — that's where the problem is
- Read the error message — Java usually tells you exactly what's wrong
- Look at the ^ arrow — it points to the exact character
- Fix that one thing, then compile again
Try It: Build a Personal Profile
Create a mini program that displays information about yourself. This combines everything you've learned!
// 💡 Try modifying this code and see what happens!
// === BUILD YOUR PERSONAL PROFILE ===
// In real Java, this would be in a file called Profile.java
console.log("╔══════════════════════════════════╗");
console.log("║ MY PERSONAL PROFILE ║");
console.log("╚══════════════════════════════════╝");
console.log("");
// Basic information
// In Java: System.out.println("Name: Alice");
console.log("Name: Alice");
console.log("Age: 25");
console.log("City: London");
console.log("Favourit
...Common Beginner Mistakes
- ❌ Filename doesn't match class name: If your class is
HelloWorld, the file MUST beHelloWorld.java— nothelloworld.javaorhello.java - ❌ Missing semicolons: Every statement must end with
;— this is the #1 beginner error - ❌ Wrong capitalization:
system.out.printlnwon't work — it must beSystem(capital S) - ❌ Using single quotes for strings:
'Hello'is wrong for strings. Use"Hello". Single quotes are only for single characters like'A' - ❌ Forgetting the main method: Without
public static void main(String[] args), Java doesn't know where to start - ❌ Mismatched braces: Every
{must have a matching}. Count them if you get errors!
💡 Pro Tips for Beginners
- 💡 Use an IDE: Download IntelliJ IDEA (Community Edition is free) or VS Code with the Java extension. They highlight errors as you type, saving you hours of debugging.
- 💡 Type, don't copy-paste: When learning, type the code yourself. Your fingers will memorize the patterns faster than your eyes.
- 💡 Read errors from the top: When you get multiple errors, fix the FIRST one and compile again. Often, fixing one error removes several others.
- 💡 Save often, compile often: Don't write 50 lines then compile. Write 3-4 lines, compile, fix errors, repeat. Small steps = fewer bugs.
📋 Quick Reference
| Concept | Syntax | Notes |
|---|---|---|
| Class | public class Name { } | Must match filename |
| Main method | public static void main(String[] args) | Entry point — JVM starts here |
| Print with newline | System.out.println("text") | Most common output method |
| Print without newline | System.out.print("text") | Stays on same line |
| Statement ending | ; | Required after every statement |
| Single-line comment | // comment | Ignored by Java |
| Multi-line comment | /* comment */ | For longer notes |
| Compile | javac FileName.java | Creates .class bytecode |
| Run | java FileName | Runs on JVM (no extension!) |
🎉 Lesson Complete!
Amazing work! You've learned how to set up Java, write your first program, use System.out.println(), add comments, and read error messages. You understand the compile → run process that makes Java special.
Next up: Variables & Data Types — learn how to store numbers, text, and other data so your programs can remember and work with information.
Sign up for free to track which lessons you've completed and get learning reminders.