This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
There's a wee bit of magic involved. Really it's just a convention established by the inventors of the language. When you start a Java program at the commandline "java ClassName" the Java runtime loads the class and calls the main() method. The runtime also puts any parameters you entered on the commandline into the String parameter for main. So when you see a main() method, it means you can start the class from the command line. Sometimes that means it is "the program of interest" or the thing people actually want to start up from the command line. Sometimes the main method is just for testing. Some classes that you would never run as a program from the command line have test code or examples of how to call methods in the main. If you're using an IDE like Eclipse you usually have a "run" button of some kind instead of using the command line launch. hope that helped!
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by ashok ks: What is the use of using main() in the java class ?
Since others have already explained why main() is there, I'll just mention that it is required ONLY if you java class is the entry point to an application. If it is not an application entry point then it will not have main().