Java Uses command line parameters

Source: Internet
Author: User
Java Uses command line parameters-general Linux technology-Linux programming and kernel information. The following is a detailed description. Sometimes you want to pass information to a program when running the program. This is achieved by passing the command-line arguments to main. The command line parameter is the information that follows the program name in the command line during program execution. Accessing command line parameters in Java programs is quite easy-they are stored as strings in the String array passed to main. For example, the following program shows all the command line parameters called:

// Display all command-line arguments.
Class CommandLine {
Public static void main (String args []) {

For (int I = 0; iSystem. out. println ("args [" + I + "]:" +
Args );

}
}

Run the following command to execute this program:

Chapter 2 further research methods and categories

Java Commandline this is a test 100-1

After execution, you will see the following output:

Args [0]: thisargs [1]: isargs [2]: aargs [3]: testargs [4]: 100 args [5]:-1

Note: All command line parameters are passed as strings. You must manually convert numeric values to their internal form.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.