-1

I am a new programer and I'm just starting to learn the basics of Java and I'm trying to understand what exactly "args" stands for in "public static void main(String[] args)". I found that's it's connected to command line arguments, which I don't understand. I would like to know what "args" means.

Thank you.

Macintosh Fan
  • 355
  • 1
  • 4
  • 18
  • The Oracle tutorial, [Command-Line Arguments](https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html), explains their use. – Gilbert Le Blanc Jan 02 '21 at 07:57

2 Answers2

3

When you run a Java program, it usually looks like this:

java MyProgram

However, you also have the option of including command-line arguments. For example, if your program adds two numbers, you could set it up to take input like this:

java MyProgram 12 47

In this case, arr would equal ["12", "47"]. Having input work in this way is useful because it makes it easier to automate the running of your program through batch files or the like.

nullptr
  • 2,244
  • 1
  • 15
  • 22
  • i dont realy understand what is "MyProgram" but i am understant that args is a array of string.. but how do i use it? and i dont surrly understand what is Command-Line Arguments. – Pan Eyal May 04 '13 at 10:45
  • 1
    @PanEyal Do you use the command line you run your programs? `MyProgram` is whatever your class is called, as in `public class MyProgram`. Look at my example of command-line arguments to see what they are. – nullptr May 04 '13 at 15:32
0

args is an arbitrary name for command line arguments. Running a java class file from the command line will pass an array of Strings to the main() function. If you want to handle extra arguments, you can check for keywords at certain indices of args and perform extra functions based on them.

Dolphiniac
  • 1,632
  • 1
  • 9
  • 9