Java Language Command line Argument Processing

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • public static void main(String[] args)

Parameters

ParameterDetails
argsThe command line arguments. Assuming that the main method is invoked by the Java launcher, args will be non-null, and will have no null elements.

Remarks

When a regular Java application is launched using the java command (or equivalent), a main method will be called, passing the arguments from the command line in the args array.

Unfortunately, the Java SE class libraries do not provide any direct support for command argument processing. This leaves you two alternatives:

  • Implement the argument processing by hand in Java.
  • Make use of a 3rd-party library.

This Topic will attempt to cover some of the more popular 3rd-party libraries. For an extensive list of the alternatives, see this answer to the StackOverflow Question "How to parse command line arguments in Java?".



Got any Java Language Question?