If you’re looking for a clear Java tutorial for beginners, you’ve come to the right place — this guide walks you through writing, compiling, and running your very first Java program: the classic “Hello, World!” example. Java remains one of the most powerful, widely-used, and beginner-friendly languages in 2025–2026 — it powers Android apps, enterprise backends, big data tools (Hadoop, Spark), web servers (Spring Boot), desktop applications, games, and much more. Java’s biggest strengths for beginners are its strong typing, clear syntax, excellent error messages, massive community, and cross-platform nature: write once, run anywhere.
In this Java tutorial for beginners, you’ll:
- Set up a simple project folder
- Write your first Java class and main method
- Understand every line of code
- Compile with javac
- Run with java
- Troubleshoot common beginner mistakes
By the end, you’ll have confidence to start real Java projects.
Prerequisites
- Java 11, 17, 21 or 23 installed (LTS versions recommended)
- Ubuntu/Debian: sudo apt install openjdk-21-jdk
- Windows/macOS: Download from https://adoptium.net/ or Oracle
- A terminal (Command Prompt, PowerShell, Terminal, Bash)
- A text editor: VS Code (recommended), Notepad++, Sublime, or nano/vim
- Optional: IntelliJ IDEA Community (free) — great for beginners later
Step 1 – Create Your Project Folder
Open your terminal and create a dedicated folder:
mkdir hello-java
cd hello-java
This keeps your first Java tutorial for beginners project organised.
Step 2 – Write Your First Java Program
Create a file called Hello.java (file name must match the class name):
nano Hello.java # or use VS Code: code Hello.java
Paste this code:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World! Welcome to Java!");
}
}
Save and exit (nano: Ctrl+O → Enter → Ctrl+X).
Line-by-line explanation (key for Java tutorial for beginners):
- public class Hello → Defines a public class named Hello (must match filename)
- { and } → Curly braces contain the class body
- public static void main(String[] args) → Special method — Java’s entry point
- public: accessible from anywhere
- static: can run without creating an object
- void: returns nothing
- main: exact name Java looks for
- String[] args: array for command-line arguments
- System.out.println(…) → Prints text to console + newline
- ; → Every Java statement ends with semicolon
Step 3 – Compile Your Java Program
Compile the source code into bytecode:
javac Hello.java
No errors? You now have Hello.class (bytecode file) in the folder.
If you see errors:
- Check filename matches class name exactly (Hello.java)
- Check for missing ; or wrong braces
- Run javac –version to confirm Java is installed
Step 4 – Run Your Java Program
Execute the compiled bytecode:
java Hello
Output:
Hello, World! Welcome to Java!
Success! You’ve written, compiled, and run your first Java program in this Java tutorial for beginners.
Step 5 – Experiment & Learn More
Try these changes in Hello.java (recompile with javac Hello.java each time):
// Change message
System.out.println("Hi Zain! I'm learning Java in 2026!");
// Multiple lines
System.out.println("Line 1");
System.out.println("Line 2");
// Variables
String name = "Zain";
int age = 25;
System.out.println("My name is " + name + " and I am " + age + " years old.");
Re-run: java Hello
Step 6 – Common Beginner Mistakes & Fixes
- Error: class Hello is public, should be declared in a file named Hello.java → Filename must match public class name exactly (case-sensitive)
- Error: cannot find symbol → Missing ; or typo in code
- Error: main method not found → Check method signature is exactly public static void main(String[] args)
- No output after java Hello → Make sure you compiled first (javac Hello.java)
Next Steps After This Java Tutorial for Beginners
- Learn variables, data types, operators
- Work with conditionals (if, else) and loops (for, while)
- Understand methods and parameters
- Explore arrays and ArrayList
- Start using classes & objects (OOP basics)
- Try IntelliJ IDEA Community — free, beginner-friendly IDE
- Build small projects: calculator, to-do list, number guessing game
Summary
You now know exactly how to write, compile, and run your first Java program — the foundation of every Java tutorial for beginners.
You’ve mastered:
- Creating a Java class
- Writing the main method
- Printing to console
- Compiling with javac
- Running with java
You’re officially coding in Java!