Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java public static main()

Tags:

java

I am learning Java, theres one thing I do not understand..

in the main routine:

public static void main(String[] args) {

I think I pretty much understand this, in the language I know, I think it would be like this:

public static function main(args:String):void {

The first thing I do not understand is what are the 2 brackets [] for in String[]? Also the second thing I am wondering, is if this is the first function that will be called (and called by something outside the program), will there ever actually be a parameter passed?

Thanks.

like image 559
JD Isaacks Avatar asked Dec 02 '22 07:12

JD Isaacks


1 Answers

The arguments to main are the options you pass into Java from the command line, passed in as an array. So for example :

java MyProgram foo bar zoo

takes three arguments, namely, foo, bar, and zoo

foo is args[0], bar is args[1], and zoo is args[2].

like image 100
Amir Afghani Avatar answered Dec 03 '22 20:12

Amir Afghani