Why main() method is always static in Java?29 Nov 2025 | 5 min read In Java, the main() method plays a vital role in program execution. The main() method is the first method that encounters first during execution. So, it is an entry point of a program. We cannot modify the syntax of the main() method. The only thing which we can change is the name of the String array argument. The syntax of the main() method is as follows: ![]() Let's divide the syntax of the main() method into several parts and understand each one of them: 1) publicIt is not so complicated to understand. It is an access modifier of the main() method. We create main() method with public access specifier to execute it by any program. So, it is required to define main() method public and if we define the main() method as non-public, it will throw the following error: Output: Error: Main method is not static in class TestMain, please define the main method as: public static void main(String[] args) To read more public Keyword in Java 2) staticThe static is a keyword which we use in the main() method to define it as static. There is no object of the class available at the time of starting java runtime, and because of that, we have to define the main() method as static. By doing that, JVM can load the class into the main memory and call the main() method. So, if we define main() method as non-static method, JVM would not be able to call it and throws the following error: Output: Error: Main method not found in class TestMain, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application To read more Static Keyword in Java 3) voidAs we know that, each method provides some return type such as String, Boolean, Integer etc. The Java main() method does not return anything, and its return type is void. The main() method doesn't return anything to make things simple. The program will be terminated after executing the main() method, and returning anything from the main() method is worthless because JVM will be done nothing for the returned object. If we return something from the main() method, it will throw the following error: Output: Error: Main method must return a value of type void in class TestMain, please define the main method as: public static void main(String[] args) To read more void Keyword in Java 4) main()It is the name of the main() method. The name of the method is static and we cannot change it. If we try to change the name of the method(), it will throw the following error: Output: Error: Main method not found in class TestMain, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application To read more Java main() Method 5) String[] args or String args[]The Java main() method takes a single argument of type String array as a parameter also referred to as a command-line argument. Let's take an example and understand how the command-line argument works. Output: User entered command line argument is: Testing To read more String []args in Java Reasons for defining main() method as staticWe cannot call a method without creating an instance of its class, and we already told you before that at the time of starting JVM, there is no object of a class. We create the main() method as static so that JVM can load the class into the main memory.
Java main() Method MCQs1. Why is the main() method declared as static in Java?
Answer: B Explanation: The main() method is static because the JVM needs to call it without creating an object of the class. 2. What will happen if the main() method is not declared as static?
Answer: C Explanation: JVM will throw a runtime error saying it cannot find the main method because it expects a static method. 3. What is the correct syntax of the main() method in Java?
Answer: C Explanation: The correct and required syntax is: public static void main(String[] args). 4. Which of the following is true about the main() method?
Answer: D Explanation: The main() method is the entry point for every standalone Java application. 5. Why is the return type of the main() method void?
Answer: B Explanation: JVM does not use any return value from main(), hence void is used as return type. Next TopicWhat-are-java-buzzwords |
Polygonal Number in Java
A polygonal number is a number in mathematics represented by dots or pebbles organized in the shape of a regular polygon. The dots are referred to as alphas (units). These are two-dimensional figurate integers of a particular sort. Polygonal numbers are the numbers that represent dots organized...
5 min read
Difference Between Java.sql and Javax.sql
In the realm of Java programming, working with databases is an integral part of building robust and scalable applications. To facilitate database operations, Java offers two packages: java.sql and javax.sql. While both packages serve the same purpose of providing access to databases, they differ in their...
7 min read
Conditional Operator in Java
In Java, conditional operators check the condition and decides the desired result on the basis of both conditions. In this section, we will discuss the conditional operator in Java. Types of Conditional Operator There are three types of the conditional operator in Java: Conditional AND Conditional OR Ternary Operator Operator Symbol Conditional or Logical...
3 min read
Activity Selection Problem in Java
The activity selection problem serves as a fundamental greedy algorithm challenge that requires selecting the highest quantity of sequential activities. We need to choose the maximum number of activities from a given set because each activity specifies its start and finish times. The problem serves effectively in...
5 min read
Difference between BlueJ and JDK 1.3
Java is widely used programming language recognized for its object-oriented nature, although it doesn't adhere strictly to this approach since it also accommodates fundamental data types like integers (int) and characters (char). The article compares and contrasts two crucial instruments for Java development: BlueJ, a user-friendly...
2 min read
Collecting in Java 8
Java 8, released in 2014, was a game-changer for the Java programming language. Among its many new features and improvements, one of the most significant additions was the introduction of the Stream API and the versatile Stream Collectors. These enhancements made it much easier to work...
3 min read
Fibodiv Number in Java
A number N that can be split into parts f1 and f2, such that if we take f1 and f2 as the first two terms of a Fibonacci series, then one of the terms of the Fibonacci series is the number N itself. Let's understand it...
9 min read
Increment and Decrement Operators in Java
In Java, the increment and decrement operators are the type of unary operator. It is used to increments and decrements the value of a variable 1, respectively. The increment operator is represented by a pair of plus signs (++), and the decrement operator is represented...
6 min read
XOR Bitwise Operator in Java
The XOR bitwise operator, indicated by the symbol "^", is a binary operator in Java that performs a bitwise XOR operation between two operands. The XOR operation returns a value in which each bit in the result is set to 1 if and only if precisely...
3 min read
DecimalStyle withZeroDigit() Method in Java With Examples
The java.time.format.DecimalStyle class contains the withZeroDigit() method. The character that is used to represent zero for the Locale of this DecimalStyle is configured using the DecimalStyle class in Java. Upon receiving the character as an input, this function produces a DecimalStyle object containing the revised negative...
3 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India
