Java: Handle Command Line Argument


Here’s a sample code in Java to handle command line parameter.

You can get the number of arguments by args.length.

And here are examples of execution. If you execute it without any parameter, it shows “No parameter”.

Environment

I checked the above codes work in the following environment.

  • OS: Windows 8
  • JDK: 1.7.0_51