0

I want to know that why do we use String args[] because I am a beginner and I am not able to understand why do we use it.

  • As a short answer, sometimes when we want to start our application we need to pass some arguments to it like `java -jar application.jar verbose root`, and then you get the arguments `verbose` and `root` and within your application judge what to do. You can google it there are more information out there. – Elyas Hadizadeh May 03 '20 at 05:47
  • As an aside `String args[]` is C style syntax. The recommended Java syntax is `String[] args` or `String... args`. – Ole V.V. May 03 '20 at 06:14

1 Answers1

1

These are the parameters which you pass to your program when running it.

For example, you can run java MyProgram -param -verbose -enableSomething -key=value

All these -param, -verbose, etc are those arguments.

See docs: https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html

Mikhail Kopylov
  • 2,008
  • 5
  • 27
  • 58