Use the apache commons cli if you plan on extending that past a single arg.
"The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool."
Commons CLI supports different types of options:
- POSIX like options (ie. tar -zxvf foo.tar.gz)
- GNU like long options (ie. du --human-readable --max-depth=1)
- Java like properties (ie. java -Djava.awt.headless=true -Djava.net.useSystemProxies=true Foo)
- Short options with value attached (ie. gcc -O2 foo.c)
- long options with single hyphen (ie. ant -projecthelp)
GeeksforGeeks
geeksforgeeks.org › java › command-line-arguments-in-java
Command Line Arguments in Java - GeeksforGeeks
Explanation: When the program is executed using java Hello Geeks at GeeksforGeeks, the JVM stores the three command-line arguments in the args array as args[0] = "Geeks", args[1] = "at", and args[2] = "GeeksforGeeks".
Published: September 28, 2026
Oracle
docs.oracle.com › javase › tutorial › essential › environment › cmdLineArgs.html
Command-Line Arguments (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run. For example, suppose a Java application called Sort sorts lines in a file.
Java Command line arguments - Stack Overflow
I am trying to detect whether the 'a' was entered as the first string argument. More on stackoverflow.com
How do I put a command-line argument when running from an IDE
Go to Run -> Edit Configurations... and look at your run configuration. There is a field for "Program arguments". More on reddit.com
What’s the use of doing command line argument in Java?
If you'd like the user to be able to provide different "options" to your program, you can use command-line arguments. For example: Perhaps your program has different "modes" of some kind Perhaps your program reads from a file, and you'd like to be able to pass in different filenames You could also prompt the user for input once the program is running, but sometimes this is not convenient. More on reddit.com
Is there a static method to get command-line arguments?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
09:05
Command line arguments/parameters in Java - YouTube
06:21
Command Line Arguments in Java - YouTube
13:02
How to use command line arguments in Java - YouTube
05:58
Command Line Arguments in Java with examples| Java Tutorial for ...
Java Tutorial #90 - Passing Command-Line Arguments to ...
05:59
Beginner Java - Command Line Arguments in 5 min - YouTube
Baeldung
baeldung.com › home › java › core java › command-line arguments in java
Command-Line Arguments in Java | Baeldung
September 16, 2026 - The code above expects the file path as a command-line argument. If no file path is provided, it throws an exception and prints the usage instructions instead of attempting to read the file. Let’s place a file named hello.txt in our resources folder and pass its absolute path as an argument in our IDE run configuration: "/home/baeldung/tutorials/core-java-modules/core-java-lang/src/main/resources/hello.txt"
Programiz
programiz.com › java-programming › command-line-arguments
Java Command-Line Arguments | Programiz
March 13, 2024 - The String array stores all the arguments passed through the command line. Note: Arguments are always stored as strings and always separated by white-space. The main() method of every Java program only accepts string arguments.
Tutorialspoint
tutorialspoint.com › java › java-command-line-args.htm
Java - Command Line Arguments
Command line arguments allows to configure the application behavior by passing the arguments before start of the application. Batch processes are one of the example where command line arguments are heavily used to execute java commands with ...
CS156
ucsb-cs156.github.io › topics › java › java_command_line_arguments.html
Java: Command Line Arguments | CS156 - GitHub Pages
If you run java Main foo bar fum then args.length is 3, args[0] is "foo", args[1] is "bar", and args[2] is "fum" Command line args come in as Strings. If you want an int, use Integer.parseInt as in this example from Oracle’s tutorial · int firstArg; if (args.length > 0) { try { firstArg ...
Princeton
cs.princeton.edu › courses › archive › spr96 › cs333 › java › tutorial › java › cmdLineArgs › index.html
Command Line Arguments
Your Java application can accept any number of arguments from the command line. Command line arguments allow the user to affect the operation of an application.
Top answer 1 of 9
42
Use the apache commons cli if you plan on extending that past a single arg.
"The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool."
Commons CLI supports different types of options:
- POSIX like options (ie. tar -zxvf foo.tar.gz)
- GNU like long options (ie. du --human-readable --max-depth=1)
- Java like properties (ie. java -Djava.awt.headless=true -Djava.net.useSystemProxies=true Foo)
- Short options with value attached (ie. gcc -O2 foo.c)
- long options with single hyphen (ie. ant -projecthelp)
2 of 9
39
public class YourClass {
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("a")){
//...
}
}
}
Sde-coursepack
sde-coursepack.github.io › modules › java › Command-Line-Arguments
SDE | Command Line Arguments
java myPackage.myClassName these are my lovely arguments ... Reminder that when we want to run class files from command line, we need to include the package name.
Upgrad
upgrad.com › home › tutorials › software & tech › command line arguments in java
Command Line Arguments in Java Explained with Examples
August 31, 2026 - This concept not only enhances flexibility but also helps in customizing application behavior without changing the source code. ... In Java, command line arguments are the values passed to the main() method when a program is launched.
Codemistic
codemistic.github.io › java › command-line-arguments-java.html
Command-Line Arguments in Java| Java Tutorials | CodeMistic
Command Line Argument in Java is the information that is passed to the program when it is executed. The information passed is stored in the string array passed to the main() method and it is stored as a string. It is the information that directly follows the program’s name on the command ...