Java main function Self-http://younglab.blog.51cto.com/416652/94717)

Source: Internet
Author: User
Java main functions are generally defined as follows: public static void main (String [] args)

What does each word mean? One by one: public-indicates that the method main () can be accessed by any program, including the Java technical interpreter. Static-is a keyword that notifies the compiler that main () is used for functions in the class. This keyword is necessary for main () to start running before the program does other things. Note that if the Main () method does not use the static modifier, the compilation will not go wrong, but if you try to execute this program, an error will be reported, prompting that the main () method does not exist. This is because if you execute the program directly using the command line in this way, the class containing main () is not instantiated, so its main () method does not exist, the static modifier indicates that the method is static and can be used without instantiation. Void-indicates that the return value of main () is "untyped". In fact, its return value is determined by the specific star statement in the main function. This is important because the Java programming language requires careful type checks, including checking that the called methods actually return the types declared by these methods. String args []-is a declaration of a String array. What is its return value? When we run the "HelloWorld. class" program, we don't see any array output. Why? After we run the compiled "HelloWorld. class", we directly input "java HelloWorld" in the command line. What if we add something later?
For example, if you enter "java HelloWorld name", you will find that the original name is output, and the array String args [] is used to output parameters following the class name, if you enter "java HelloWorld name age", the output will be :...... name age: String args [0] = "name", String args [1] = "age ".

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.