Why we use ‘String args[]’ as a argument in main method of java?

We would have definitely used (String args[]) argument in our main method of java, but most of the people don’t even know the real reason using this argument.

String args[] is a array object of String class. Usually, it is used to store the command line arguments. When we run our java programs and we write ‘java ProgramName’ in cmd , the rest of the line is know as command line. If you write anything after your ProgramName, it is treated as command line argument and is stored in args[] as String

It works as an entry point of your application.

For example, if your have three main events in your application, you can call it through the command line like ‘java Program home’, so in a single java file, you can deal with many things!

Published by Yash Kukreja

I am more than a proGrammer();

Leave a comment

Design a site like this with WordPress.com
Get started