whether class contains main method or not and weather main method is declared
according to requirement or not
these things wont be checked by compiler at runtime jvm is responsible to check
these things if jvm unable to
find main method then we will get runtime exception saying no such method
error:main
at runtime jvm always searches for the following prototype
1.public:to call by jvm from anywhere
2.static:without exeisting object also jvm has to call this method
3.void:jvm wont return anything to the jvm
4.main:this is the name which is configure inside jvm
5.arguments is string array-commandline argument
the above syntax is very strict and if we perform any change then we will get
runtime exeception saying no such method error:main
even though above syntax is very strict the following changes are acceptable
1.insted of public static we can take static public i.e the order of modifiers is
not importent
2.we can declare string array in any acceptable form
main(string [] args)
main(string []args)
main(string args[])
3.instead of args we can take any valid java identifier
ex:main(string durga)
4.we can replace string[] with var-org parameter
main(String...args)
in which of the above cases we will get compile time error
we wont get compile time error anywhere but except last two cases in remaining we
will get
runtime execption saying no such method exception error:main
class Test
{
public static void main(String args[]){
System.out.print("string[]");
}
oublic static void main(int[] args){
System.Out.Print("int[]");
}
}
o/p==>string[]
overloading of the main method is possible but jvm will always call string array
orgument main method ob=nly other overloaded method we have to call explicitlylike
normal method call