Public static void main (String arg [])

Source: Internet
Author: User

This statement defines the main method. the main method is the entry to program execution. All java programs must have a main () method and must be defined in the preceding format. classes that do not have the main method can be compiled, but cannot be executed. because it does not have the main method as the starting point for execution. static indicates that the main method can be called without the need to create a class instance, because in general, the class cannot be accessed without being instantiated. if there is a keyword static before the method, you can directly access it by class name even if no class instance is created. since JVM will call the main () method before other processes, the main () method should not depend on the instance of any class to be created and must be declared as static. the keyword void tells the compiler that it does not return any value when executing this method. the variables contained in the parentheses () of the main () method are parameters passed to the method. Even if the main method does not require parameters, the method name must still contain parentheses. string arg [] is a parameter passed to the main () method. arg [] is an array of the string type. parameters passed in the command line are stored in this array. A pair of braces of the main () method is a method block. the statement to be executed starting from the main method must be specified in this block.

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.