A brief description of the main method in Java programs

Source: Internet
Author: User

briefly describe the main method :

A main method is involved in the programming of the J-ava language Program , which is in the following format:

public static void main (string[] Args) (typically This must be defined, this is the Java Specification)

here the modifier public and the static sequence are Interchangeable. however, according to java practice, The public is generally placed in front, the parameter name in the following args is not fixed, the developer can be arbitrarily named.

1) The Public keyword means that the function can be accessed by other Classes.

2) The static keyword refers to a function that is not instantiated when invoked (that is, the object cannot be created) (static functions can be called directly from the class Name)

3) The Void keyword means that the function has no return value

The main () method is the portal to the application, and when a program executes , it starts with the main () method of the specified class and then starts other resources required by the Program.

The arguments in the string array passed to main are "program argument". They are often typed by the user when they run the Program.

For example, If you do not use the compiler, compile with the command line. You can pass in the ABC when you are ready to compile the class, then the result of the program is abc, which is the main function of the parameter args to provide a means for the program user to interact with the program in the command line State.

This function can also be called as a normal function method, for example, to make it easier to understand: (renaming args as hello, compiling runs Still)

The results of the operation are as Follows:

Note: A class can have no main () method if it is not a program entry.

An application can also be made by any number of main methods, because each class can have a main method, or multiple (overloads). But at any given time, the program uses only one main method.

A brief description of the main method in Java programs

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.