A Java program follows a fixed and well-defined structure. Understanding this structure is essential to write, read, and debug Java applications effectively. Every Java program starts execution from the main() method.
Java programs are written inside classes. The class name must match the filename. Execution begins from the public static void main(String[] args) method.
// This is the basic structure of a Java program
class HelloWorld {
// Main method is the entry point of the program
public static void main(String[] args) {
// Printing output to the console
System.out.println("Hello, Java!");
}
}
The program prints Hello, Java! on the screen. The JVM starts execution from the main method and runs statements line by line.
println()