1. public: It is a keyword and denotes that any other class (JVM) can call the main() method without any restrictions.
2. static: It is a keyword and denotes that any other class (JVM) can call the main() method without the help of an object
3. void: It is a keyword and denotes that the main() method does not return a value.
4. main(): It is the name of the method.
5. String args[]: The parameter is a String array by name args. The string array is used to access command-line arguments.
JVM is in another context area. To call the main(), the JVM requires an object. When the JVM has not entered into the program, how it can create an object or get an object. To overcome this, allow the JVM to access the main() without object just by declaring static. Once the JVM enters, it can create hundreds of objects.
Whether you pass right now command-line arguments or not, you must have the string array as parameter as it is the part of syntax.
Any word is missed in the above statement, the program compiles, but does not execute.
EXAMPLE :
class First
{
// A java program will start from here.
public static void main(String args[])
{
System.out.println(" Welcome to Javamadelife...!!! ");
}
{
// A java program will start from here.
public static void main(String args[])
{
System.out.println(" Welcome to Javamadelife...!!! ");
}
No comments:
Post a Comment