Command Line Arguments in Java | Java Training

This Java Training “Command Line Arguments in Java” gives introduction to command line arguments including, definition, how to pass arguments and memory allocation of command line arguments.


Command Line arguments:

  • Every Java Application is allowed to take user-input from the command prompt while invoking application.
  • Java application can be compiled and run only from the command prompt (OS environment).
  • While invoking the application, we can input any type of data(arguments) that can be processed at later time in the application.
  • main() method is responsible to collect all these arguments and stores into an array of type String. Hence prototype is

main(String arguments_list[ ])


Why arguments array is of type String only?

  • main(int[ ]) –> Accepts only integer data
  • main(float[ ]) –> Accepts only float data
  • main(String[ ]) –> Can accept any type of data as String “10” , “34.56” , “g” , “hari”.


  • Whatever the input type collected from the command prompt will be implicitly converted into String type.
  • To process the command line arguments, it is mandatory to convert String type into corresponding primitive types using parseXxx() methods.
  • If we don’t pass any arguments, the array size will be “zero” .
  • The size increases depends on number of arguments passed.


How to pass command line arguments?

  • While invoking application from the command prompt, we can pass arguments.
  • No limit for command line arguments
  • Arguments separated using “space” while passing.
  • Arguments must be placed followed by “class file” name.


Memory Allocation of Command Line Arguments:

Command Line Arguments in Java

Share this