Hello World in Java

Hello World in Java

In the previous tutorial, you learned how to install Java on your computer. Now, let’s write your first Java program: “Hello, World”.

				
					public class Main {

    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
				
			

The above program prints Hello, World! on the screen. 

Output
				
					Hello, World!
				
			

Congratulations! You’ve just written your very first program. Keep coding! Now, let’s understand the code that you have just written.

Basic Structure of a Java Program

1. public class main (Class Definition)

Every Java program must have at least one class. The class keyword is used to define a class in Java, and Main is the name of the class. The public keyword in Java is an access modifier. We will learn more about access modifiers later in the upcoming tutorials.     

				
					public class Main {

    public static void main(String[] args) {
        //Code Goes Here
    }
}
				
			

2. main Method in Java

In Java, every application must have a main method, which is the entry point of the program where the execution of the program begins. We will learn more about methods (Methods are functions defined inside of a class.) in the upcoming tutorials.
				
					

    public static void main(String[] args) {
    }
				
			
  • public: Allows the method to be accessed from anywhere. 
  • static: A method can run without creating an object.
  • void: It’s a return type that means a method is not returning anything.
  • main: main is the name of the method.
  • String[] args: Arguments of the method.    

3. System.out.println()

System.out.println() prints output to the console.
				
					System.out.println("Hello, World");
				
			
  • System: Built in class.  
  • out: out is a static object inside the System class.
  • println(): The println() method prints output to the console and moves to the next line.    

How Java Executes Program

Java programs execute in two steps: first is compilation, and second is execution.  

  1. Compilation(source code to byte code).
  2. Execution(byte code to native code).

1. Compilation

In this step, the Java compiler (javac) converts the Java source code (.java files) into the bytecode (.class files). This bytecode is platform-independent and can run on any system with a JVM(Java Virtual Machine). That’s why we call Java a portable language.     
Java Code Compilation Step

The Java compiler is a development tool included in the JDK(Java Development Kit) that converts Java source code into bytecode.

Java Development Kit

2. Execution

In this step, the JVM(Java Virtual Machine) converts the Java bytecode(.class files) into the native code (binary code) that the machine can understand and execute.    
Java Code Execution Steps

JVM(Java Virtual Machine) is part of JRE(Java Runtime), and JRE is part of JDK(Java Development Kit). 

Java Development Kit

JVM(Java Virtual Machine) is part of JRE(Java Runtime), and JRE is part of JDK(Java Development Kit). 

In the next tutorial, we’ll learn about comments in Java and how they help make code more readable and easier to understand.       

Conclusion

Congratulations! You’ve successfully written and understood your first Java program, the classic Hello World example.

This small program might look simple, but it introduces you to some of the most important building blocks of Java, such as the main method, class structure, and how Java executes code. Every professional Java developer started their journey right here.

From this point forward, you can begin exploring:

  • Variables and data types
  • Conditional statements
  • Loops
  • Object-Oriented Programming concepts

At VairagiCodes, our goal is to make programming easy, practical, and beginner-friendly. Keep practicing, experiment with the code, and don’t be afraid to make mistakes, that’s how real learning happens.

Next Step: Try modifying the message inside System.out.println() or write multiple print statements to strengthen your understanding.

In the next tutorial, we’ll explore comments in Java, an essential concept that helps you write clear, readable, and well-documented code.

Java Tutorials

Stay Connected

Follow me on Instagram for Java tips, coding reels, and much more.
Subscribe to my YouTube Channel for learning the art of programming.

If you liked this article, then share it with your friends.

Related Tutorials

introduction to java programming
Introduction to Java Programming
  • June 27, 2025
  • Com 0

Introduction to Programming Programming is a process to communicate with electronic devices like computers, phones, etc. As a beginner, you…

Getting started with Java
Getting Started with Java
  • July 1, 2025
  • Com 0

Getting Started with Java Programming Java is one of the most popular and powerful programming languages. Java is a high-level,…

Hello World in Java Write Your First Program
Hello World in Java: Write Your First Java Program
  • January 17, 2026
  • Com 0

Hello World in Java In the previous tutorial, you learned how to install Java on your computer. Now, let’s write your…

Get Your Free Java
Data Structures Cheat Sheet! 🎁

Download the ultimate cheat sheet covering the Top 10 Data Structures every Java developer must know — with real-life examples! Just enter your email and get the free pdf.

We respect your privacy. No spam. Read our privacy policy for more information.