What is the meaning of " Public static void main (String args[])"???

                      Public static void main (String args[]):

This is the one of the polpular questions asked during interviews

This post may be ridiculous for some people but belive me if i ask you to explain each and every word in "Public static void main (String args[])"  many might go wrong.

I saw many pepole who were good at writing java codes but if i ask them to explain they fail. So please be aware of these minute details before getting embarrassed by someone.


Every word in the public static void main statement has got a meaning to the JVM. 




The above syntax is very strict if we perform any change we won't get any compile time exception but we will get run time exception saying "NO SUCH METHOD EXSITS."


The above syntax is very strict but some changes are acceptable as shown below.

⇨1)  static public void main(String[] args)✅
              The order of modifiers is not important. instead of "public               static" we can take "static public".

⇨2)  public static void main(String args[])
               -We can declare string in any acepatable form.
               -Instead of args you can even take any valid java                                identifier.




Is it possile to have two main methods inside a class?



Overloading (i.e two methods having same name but different arguments )of main method is possible but jvm will always look for standard syntax as mentioned above, and will execute that method only.

Comments

Popular posts from this blog

FC Barcelona vs Real Madrid -El Clasico Rivalry.

1NF,2NF, 3NF Normalization

Memory Management (Contiguous and Non-Contiguous ).