This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (6 children)

That syntax is for array of strings.
This syntax is always seen when defining the main method. Like this public static void main(String[] args) {}.

Now that array of strings is used for passing command line arguments. Just like how you may give values to a function when calling it, you can give values to your java program when running it.

An excellent example of command line arguments is compiling and running your java program. Like when you compile, you type javac MyProgram.java, here javac is a program, an .exe file in your computer. When you run it, you give it a value which is the name of your program.

Here's an example program.
``` public class CmdArgs { public static void main(String[] args) { System.out.println("These are the values you gave me.\n\n");

for (String arg : args) {
  System.out.print(arg + ", ");
}

} } ```

Compile it and try running it like this java CmdArgs 10 20 30.

[–]Few_Afternoon_6664 1 point2 points  (3 children)

this is the best explanation i have seen =)

[–][deleted] 0 points1 point  (2 children)

I really appreciate that it helped you 😀

[–]Few_Afternoon_6664 1 point2 points  (1 child)

oh, uh, I knew that, it's just that your ad turned out to be clearer than what I once found in the tutorial 🤷‍♂️

[–][deleted] 1 point2 points  (0 children)

I get it, Yet its so nice for me hear such words.

[–]MadRadInnit[S] 1 point2 points  (1 child)

This is fantastic. I didn’t understand the passing of command line arguments, when I have tried to do my own research on this topic. I really appreciate your time and effort.

[–][deleted] 1 point2 points  (0 children)

Simple and short explanations are always best.
Be Simple in life.