Search code examples
javaparameterscommand-line-argumentsprogram-entry-point

Can main function take a String instead of String[]


public static void main(String[] args) I know conventionally the main function takes in a parameter args that contains the supplied command line arguments as an array of String objects.

  • I have not see main takes in any parameter other than String[] args. Why not a String or an array of Integer?
  • If there is a way to specify input for the main function, please provide an example.

Solution

  • Answer to your question: NO

    Details:

    http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

    The java command starts a Java application. It does this by starting a Java runtime environment, loading a specified class, and calling that class's main method.

    The method must be declared public and static, it must not return any value, and it must accept a String array as a parameter. The method declaration has the following form:

    public static void main(String[] args)