3 Ways of writing main() in Java

I say there are actually three ways of writing the main method. This sentence might look weird so is this post. The public static void main(String args[]) can be written in 2 more ways. I mean in accordance with the parameter and not with the change of either the modifier or being non-static or change in the return type and/or parameter or the name. It's all about the changing the syntax of the parameter. When such a question occurs, this might be helpful. Here are those three ways.


Routine way..


public static void main(String args[]){}

Pushing the square before


 public static void main(String[] args){}

Three dot's can make it!


public static void main(String ...args){}

Hmm, you might also know that you can also change the parameter name if you don't like keeping it args whatsoever, this is a common known fact and i think i don't need to tell you.


Posted by at on

Tags: Interview, Java Introduction, Tips,