Java command line parameters

Source: Internet
Author: User
Like C, the main function can pass in parameters, which are called command line parameters.

In some cases, this parameter is meaningful, for example, in the android source code.

The command line parameters in Java are in the following format:

Main (string [] ARGs)

Alternatively, you can use the array method of class C:

Main (string ARGs [])

Depending on the advantages of the Java array, the length of the parameter array is provided directly, and you do not need to input another parameter like the C language.

Example:

Public class cmd {public static void main (string [] ARGs) {int length = args. length; For (INT I = 0; I <length; ++ I) {system. out. println ("ARGs [" + I + "]" + "is" + ARGs [I]) ;}}

After compiling with javac, directly call thisProgram:

D: \ workspace \ Java> JAVA cmd Liaoning Shenyang hepingargs [0] Is liaoningargs [1] is shenyangargs [2] is Heping

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.