What does ‘public static void main’ mean in Java?

Swaroop Nadella
2 min readOct 3, 2024

--

created by Swaroop Nadella using Microsoft Designer

In Java, the main method is the entry point of any standalone Java application.

Here’s a breakdown of the basic components:

Syntax:

public static void main(String[ ] args) {
// code to be executed
}

Explanation:

1. public: This means the method is accessible from outside the class. It must be public because the JVM needs to call it from outside.

2. static: This means the method belongs to the class itself rather than an instance of the class. The JVM can call this method without creating an object of the class.

3. void: This specifies that the method does not return any value.

4. main: This is the name of the method that is predefined in Java. The JVM looks for this method as the starting point for execution.

5. String[ ] args: This is an array of strings that stores command-line arguments passed to the program. If no arguments are passed, the array is empty.

Example:

public class Main {
public static void main(String[ ] args) {
System.out.println(“Hello Swaroop”);
}
}

In this example,
System.out.println(“Hello Swaroop”); is the code that gets executed when you run the program.

Output: Hello Swaroop is printed on the Console window.

Would you like to try this out in a Java Coding IDE?

Swaroop Nadella
Test Automation Engineer, Tech Educator

Subscribe here, to Get an email whenever I publish article on Medium.

Core Java and Coding for Automation Testers — Udemy Course

Swaroop Nadella Academy Store — Quizzes and Courses

--

--