"Is this reason correct?"
It is at some degree, although it was never specifically explained like that.
We could have the convention to also invoke the constructor with String...args
, that would imply you need at least an object to run, but ( probably ) the designers thought that wasn't needed.
For instance, there is no technical impediment to have something like this:
class Hello {
public void main(String...args){
System.out.println("Hello, world");
}
}
As a metter of fact, Java creates a no-arg constructor for you if you don't specify one, it would be very easy to include a var args constructor too, if the class contained a main method, and create under the hood the following code:
class Hello {
// created by the compiler
public Hello(){}
public Hello( String ... args ) {
this();
main( args );
}
// end of code created by the compiler
public void main( String ... args ) {
System.out.println("Hello, world!");
}
}
But that would create unneeded code, and extra allocated object that in this case wouldn't do anything; two constructors ( instead of one ) etc. At the end it would look like just too much magic.
Is up to the language designers. In this case they probably thought it would be simpler not to do it and just validate if the invoked class had the special signature of a method called public static void main( String [] args )
BTW you can have a Hello! world
program in Java without main method, but it throws java.lang.NoSuchMethodError: main
public class WithoutMain {
static {
System.out.println("Look ma, no main!!");
System.exit(0);
}
}
$ java WithoutMain
Look ma, no main!!
I know it is not an alternative, but yet, it is interesting isn't?