开发者

What does string[] args mean in public static void main(string[] args) in java? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

What does “String[] args” contain in java?

I want to know the significance of the term written inside the bracket in definition of main fu开发者_StackOverflow社区nction in java i.e.string[] args. What does it mean in public static void main(string[] args)? Is it always necessary to write it?

More over how many engines mysql server has and what is the default engine?


Public -> makes member accessible outside the class static -> allows main( ) to be called without having to instantiate a particular instance of the class void -> main() doesnt return value main(0 -> it is the method called when a Java application begins string[] args -> Its parameters. String args[ ] declares a parameter named args, which is an array of instances of the class String. In this case, args receives any command-line arguments present when the program is executed.


public class MainClass{ public static void main(String[] args){} } When we run in the command line java MainClass

The JVM here tries to find a method main, We are basically accessing the method main outside the class and package so the method is Public. We are running this program by referring the class name and we are not creating any object,so to access the method without creating an instance it has to be static. JVM does not handle the output of the method and hence the return type is void. We can pass series of arguments through command line and String can enclose all the primitive type in Java and we do not know the number of arguments that can be passed so it declared with String array. For MySQL engine types please refer the link Engines


The Java contruct for main() is the equivalent of C's "void main(int argc, char **argv)". Java's main() receives an array of strings, from which one can obtain the length with args.length; no need for argc, the count. It can also be written "String args[]"; both ways specify an array of strings.

The mysql question rightly belongs in another SO question altogether.


As written , string shows that args variable is of type String and [] shows args is an array.

Inside main() is because, Main() is called whenever program is executed, So this args will hold everything you give it at run time i.e. at the call of main()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜