<学习笔记> public static void Main (string[] args) Summary

Source: Internet
Author: User

Before learning the operating system encountered string[] args this problem, but did not as the focus, today, while learning Java, decided to study the problem in depth.

The code is as follows:

public class Stringtest
{
public static void Main (string[] args)
{
for (String Arg:args) {
System.out.print (arg+ "T");
}
System.out.println ();
System.out.println ("Arg1:" +args[0]);
System.out.println ("arg2:" +args[1]);
}
}

The results of the operation are as follows:

The function of string[] args can be inferred from the operation result.

1, is used to accept the parameters of the command line.

2, the parameter type is string type, in the middle with a space to distinguish the different strings.

Of course, this kind of writing is the most familiar way of writing, but also a standard of writing.

There are other different ways of writing, for example, not necessarily to write args, but also to write other character array type variable names. Others are written in string args[, which is also derived from other languages. function is exactly the same. However, it is advisable to write a string [] args, because it is easy to recognize that this is a variable of character array type. If the latter method is used, it is easy to get hooked on string args[],argt.

public static void Main (stirng[] args); The writing of this line of code is set according to the JVM. When a Java virtual machine executes a Java application, the main () method in the program is invoked, and cannot be instantiated. So the main method should be set to a public static method. The JVM also has restrictions on the return value type and no return value. In this way, we can fully understand the meaning of this code, and also better understand the Java program execution mechanism.

Finally, we recommend a new use of String...args, you can use String...args instead of string[] args, please use the code to verify it.

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.