👋 Hello : Your First Java 21 Program
So you’ve set up your Java 21 development environment — great job! 🎉 . If you have not done the setup, the you can follow the steps mentioned in Setting Up Java 21 Development Environment
Now, let’s write your first Java 21 program and understand how it works.
This tutorial is beginner-friendly and will help you learn by doing.

🧑💻 Step 1: Create a New Java File
Open your IDE (like IntelliJ or VS Code or Eclipse), or just use a text editor.
Create a new file and name it as :
HelloJava21.java
✍️ Step 2: Write Your First Java Code
Paste this code into the file or type it to get familiar with the keywords:
1 2 3 4 5 |
public class HelloJava21 { public static void main(String [] args) { System.out.println("Hello from Java 21!"); } } |
🧐 Step 3: Understand the Code
Let’s break it down in simple terms:
Line | What It Does |
---|---|
public class HelloJava21 | This defines a class (like a container) named HelloJava21 . The file name must match this. |
public static void main(String[] args) | This is the main method – the starting point of any Java program. |
System.out.println(...) | This line prints text to the screen. You’ll see it in your terminal or console. |
📌 Think of System.out.println()
as the Java way to say “show this message.”
▶️ Step 4: Run Your Program
If you’re using an IDE like IntelliJ:
- Right-click the file
- Click
Run HelloJava21.main()
If you’re using the terminal:
Make sure you’re in the folder where the file is saved, then run:
javac HelloJava21.java
java HelloJava21
You’ll see the output:
Hello from Java 21!
🎉 You just ran your first Java 21 program!
✅ What You Learned
- How to write and run a basic Java program
- How the
main()
method is where Java starts execution - How to display output using
System.out.println
🧠 Fun Fact: What’s New in Java 21?
Even though this is a basic program, Java 21 brings powerful features like:
- Virtual Threads
- Record Patterns
- String Templates (Preview)
- Pattern Matching
We’ll explore these in the upcoming posts!
In the next post we will see How Java Has Evolved: Java 8 to Java 21 in a Nutshell