Search code examples
javaprogramming-languages

Why does Java main() method accept an array of String args?


Since its possibly one of the most widely used methods of the Java language, why does it have to accept an array of Strings and doesn't work without it? For example, I could always live with:

public static void main() {}

over

public static void main(String[] args) {}

Is there a higher purpose to this than just being able to accept command-line arguments, especially since a vast majority of Java programs are GUI driven and don't need to receive args through command line?


Solution

  • even a gui driven java app will start with some main method. The "higher purpose" has never been to accept command line arguments.

    The purpose is just to accept arguments. Period. Whenever you start any program not just Java you will always need some syntax to pass arguments