Show Mobile Navigation

Webring

Powered by WebRing.

Java:Command line arguments

Sachin R Kukale - 20:46
Command line arguments are the arguments passed to the programs to specify the configuration information. You can provide any number of command line arguments to a Java program. When ‘main method’ is invoked by the JVM internally, it has one dimensional string array as parameter and if you are required to pass some arguments then you can use that one dimensional string array to pass the arguments to the program or application.
Syntax to pass command line arguments in Java:
At Command Prompt:
java   ... 
When the above command is executed JVM will create an array of length equal to number of command line arguments. These command line arguments are separated by ‘space’ by default but if you are required to pass the ‘space’ as command line argument then you can specify them in double quotes.
Also ‘String’ is default type to pass the command line arguments and if you want to pass the other data types then you can pass them as String and convert them to required type.
Passing the command line arguments to Java Program in Eclipse or Netbeans:
1.      If you want to pass the command line arguments in Eclipse or Netbeans then right click on the class to which you want to pass the command line arguments and then select the option ‘Run Configurations’.
2.      Choose the option ‘Run Configuration’ and you will get one pop up window. In that window chose the tab ‘Arguments’.
3.      In the space provided for the arguments pass all the command line arguments separated by comma.

4.      Click on ‘Run’ button.

0 comments:

Post a Comment