Your First Java Program
Site Admin
· 11 Sep 2026
· 14 views
Hello, World
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}Save, Compile, Run
- Save the file as
HelloWorld.java. The file name must match the public class name exactly. - Compile with
javac HelloWorld.java. This producesHelloWorld.classcontaining bytecode. - Run with
java HelloWorld(without the .class extension). The output isHello, world!
Understanding Each Line
public class HelloWorld: declares a public class named HelloWorld. In Java the top-level structure of a program is a class.public static void main(String[] args): the entry point.publicmeans the JVM may call it,staticmeans it belongs to the class rather than an object, andvoidmeans it returns nothing.argsholds any command-line arguments passed to the program.System.out.println(...): prints the given text followed by a new line to the console.
Passing Arguments
public class Greet {
public static void main(String[] args) {
System.out.println("Hello, " + args[0] + "!");
}
}Run it as java Greet Priya and the program prints Hello, Priya!

- The filename must equal the public class name.
- Compile with
javac, run withjava. mainis where the JVM begins executing your program.