Alternate syntax of main() method

In Java, the standard entry point of any program is:

public static void main(String[] args)

However, Java provides flexibility in how the parameter is written. While the structure of main() must remain public static void main(...), the syntax of the String array can vary slightly without affecting the behavior.

Standard & Common Forms

public static void main(String[] args)
public static void main(String []args)
public static void main(String args[])
  • All are valid and functionally identical.
  • Only the position of brackets changes.

Using Varargs (Ellipsis)

public static void main(String... args)
  • ... (ellipsis) means variable-length arguments.
  • Treated internally as a String[].

Custom Parameter Names

public static void main(String[] Simran)
  • The name args is conventional but not mandatory.
  • You can use any legal variable name: data, input, Simran, etc.

With Additional Modifiers

final public static void main(String[] args)
strictfp public static void main(String[] args)
synchronized public static void main(String[] args)
public static final void main(String[] args)
  • These modifiers are allowed alongside public static.
  • The order of modifiers can vary (Java is flexible here).

Invalid or JVM-Ignored Forms (Not Executable)

public void main(String[] args)              // ❌ Missing static
static void main(String[] args)              // ❌ Missing public
public static int main(String[] args)        // ❌ Invalid return type
public static void main()                    // ❌ Missing parameter

These will compile (sometimes), but the JVM won’t recognize them as the program’s entry point.

Summary

Syntax Valid Notes
public static void main(String[] args) Yes Standard
public static void main(String args[]) Yes Brackets after name
public static void main(String... args) Yes Varargs
public static void main(String[] Simran) Yes Custom parameter name
final public static void main(String[] args) Yes With final modifier
strictfp public static void main(String[] args) Yes With strictfp
synchronized public static void main(String[] args) Yes With synchronized
public static final void main(String[] args) Yes Modifiers reordered

Welcome to ShikshaSanchar!

ShikshaSanchar is a simple and helpful learning platform made for students who feel stressed by exams, assignments, or confusing topics. Here, you can study with clarity and confidence.

Here, learning is made simple. Notes are written in easy English, filled with clear theory, code examples, outputs, and real-life explanations — designed especially for students like you who want to understand, not just memorize.

Whether you’re from school, college, or someone learning out of curiosity — this site is for you. We’re here to help you in your exams, daily studies, and even to build a strong base for your future.

Each note on this platform is carefully prepared to suit all levels — beginner to advanced. You’ll find topics explained step by step, just like a good teacher would do in class. And the best part? You can study at your pace, anytime, anywhere.

Happy Learning! – Team ShikshaSanchar