On the knowledge point of the args of main () in Java

Source: Internet
Author: User

Let's begin by understanding the default definition format for the main () method in Java:

public static void Main (string[] args) {
}
The 1.main method is the entrance of the program execution, except that the parametric of the args can be changed, and the other cannot be changed.

Why is 2.JVM so defined?

Because the JVM is running this Java application, it first calls the main method, which does not instantiate the object of the class, but is called directly through the class name, so it needs to be restricted to public static.

The JVM specifies that a return value cannot be returned, so the return value type is void.

The main () method must have an entry parameter, the type must be string[], and the formal parameter name defaults to AGRs.

3. A program can have only one public static void main (string[] args) {}, but there can be an infinite number of overloaded main (), such as:


4. The following is an introduction to args:

Let's look at the diagram below.


This means that the JVM does not pass any parameters to the JVM when it calls the main () method, but it is also easy to understand that the JVM does not know what useful parameters the main () method requires.

5. But there are two ways we can pass a parameter to the main () method

The first kind: look:


The second kind: right mouse button, click Run as Select Run configurations select arguments to pass the parameter,


The main role of 6.args:
The Main method parameter is to accept the command line input parameters, the formal parameter will be used to accept the role of the information passed.

On the knowledge point of the args of main () in Java

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.