What is the role of string args[in Java programs?

Source: Internet
Author: User

What is the function of string args[in this program? I've learned c++,string args[] like what's in C + +? If it is C + +, want to output string as long as write cout<< "..." <<endl; on it, void Main () The parentheses are empty, and Java Why write String args[]? Class example{public  static void Main (String args[]) {  System.out.println ("This is a simple Java program.");  }}
Since string args[] or string[] args represents an array of strings to the main method, then System.out.println (args[]); Why is it an error, args[] is not the string that is a simple Java   Program? String args[] What is the relationship with this is a simple Java program? If that's okay, why is there an error removing string args[in the program?

What is the difference between the main function without string args[] and the main function with string args[]? Tell me more about it,

String[] args This string array is the argument that is entered when the main function is saved, for example, the class name of the main function is test so you run Java test a b c in cmd, args[0] = A, AR Gs[1]=b, args[2]=c You can invoke the variables you have entered in your program. Args[] Isn't that the string this is a simple Java program? It's totally not, you don't understand. Well, when you run it, add a parameter, such as Java Test XX. Then add this phrase to your main function: System.out.println ("Arg is" +args[0]) and see what the output is? is not this: it is a simple Java Programarg is xx You can also try this, enter Java Test xx yy zz at run time, and add this paragraph in your main function: System.out.println ("Arg is "+args[0]+" "+args[1]+" "+args[2]" and see what the output is? Is not: This is a simple Java programarg is xx yy zz Now do you understand? If that's okay, why is there an error removing string args[in the program? --------The reason why the error is that the main function without string args[] and the main function with string args[] are essentially not the same function, and Java itself does not have a main function without string args[]. So of course it went wrong.

What is the role of string args[in Java programs?

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.