Linkbar

>> Thursday, May 1, 2014

In most of the java interviews either for freshers or experience guys frequently facing this question. This will be easy when you have full idea about access specifiers and modifiers in java. Lets discuss about our mantra

public static void main(String args[]).

What is the Importance of the public static void main(String args[ ])

Whether a class contains main( ) or not and whether the main( ) is declared based on requirement, these all are things are won't be checked by compiler,these things are checked by JVM at Runtime.Note: If JVM is unable to find main( ) then we will get a Runtime Exception saying : Exception in thread "main" java.lang.NoSuchMethodError: main

Here we can observe that's why the main( ) prototype must be public static void main(String args[]) Let's see .

public: JVM calls main( ) from anywhere, so it should be public

static: without creating object also JVM has to call this method.

void: here main( ) won't return anything to JVM

main( ): this is the method which has configured already in the JVM

String[] args: commandline- arguments in the form of array of instances of the class String

In this we can have several possibility changes to form main method

Change 1: The Order of the modifiers is not important, i.e instead of public static ,we can use static public also.Change 2: We can declare String array in any acceptable form i.e