Main method in Java is used by JVM to start execution of any Java program.
This method must appear within a class.
Main method is entry point of Core.
Java application.But In case of server related applications like EJB,Servlet these Java programs have there own life-cycle methods like init(), service() or destory().
Syntax: public static void main(String[] args)
Java Main Method Example :
Hey I am in Technical Updates Hub main Method
Hey I am in Technical Updates Hub Overloaded main Method
Java main method is static because JVM can call it without creating any instance of class. main method is public in Java because JVM can easily access and execute it.
Main method in Java is not supposed to return any value. Note: JVM throws NoSuchMethodException:main. if it doesn't find main method of predefined signature in class.
Main method is run by a special thread called "main" thread in Java. Main method in Java can be overloaded like any other method in Java but JVM will only call main method with specified signature.
Java application.But In case of server related applications like EJB,Servlet these Java programs have there own life-cycle methods like init(), service() or destory().
Java Main Method:
The main() method in C++, C# and Java are static because they can then be invoked by the runtime engine without having to instantiate an instance of the parent class.Syntax: public static void main(String[] args)
Java Main Method Example :
Source Code:
class TechnicalUpdatesHub {
public static void main(String args[])
{
System.out.println("Hey I am in Technical Updates Hub main Method");
}
public static void main(int i)
{
System.out.println("Hey I am in Technical Updates Hub Overloaded main Method");
}
}
Output:
Hey I am in Technical Updates Hub main Method
Hey I am in Technical Updates Hub Overloaded main Method
Java main method is static because JVM can call it without creating any instance of class. main method is public in Java because JVM can easily access and execute it.
Main method in Java is not supposed to return any value. Note: JVM throws NoSuchMethodException:main. if it doesn't find main method of predefined signature in class.
Main method is run by a special thread called "main" thread in Java. Main method in Java can be overloaded like any other method in Java but JVM will only call main method with specified signature.
![Java Main Method and Why it's declared as public static void main(String args[]) Java Main Method and Why it's declared as public static void main(String args[])](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCuzo4LTMopaDCmGDRNwkTV5XB15UqSSZOiFpRWJ5qMK-I0ns-OmBAwBkH8TeppPi58SwyBFnA4xndMlQHM9mtGpIkrDCL4834T_fiMJH4eq8raGTGeFMrLDLXGn1RRRkqZ-Jy8GcgjlU/s400/FB_IMG_1436207974228.jpg)

0 comments:
Post a Comment