This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
It is public because outside process(JVM) need to access it to run it. It is void because it doesn't return any value. It takes String array as argument so that it can take command line arguments. But, why it should be static?
By defining it as static, JVM can invoke it without creating object for the enclosing class. But, JVM can create an object for the corresponding class and can invoke the main method then? Is there any strong reason for this?
The reason I got when searched on Internet says "JVM can not create any object before program runs. So, to run the program main should be invoked without creating any object. That's why main should be static."
But, I'm thinking that when JVM can load a class, why it can not create object before calling main method? after all JVM only creates and maintains all objects in our program.
The JVM has no business creating objects of the application's classes unless the application specifically tells it to. Creating an object may have all kinds of consequences that the JVM knows nothing about.
Also, the class may not have a no-argument constructor, making it impossible easily to create an object.