Java Learning notes 5_helloworld and public static void main (string[] args)

Source: Internet
Author: User

1. This is the first Hello procedure and description

Default introduction of Package Java.lang

The file name and class name must be the same, with a maximum of one public class in a file

public class Hello {

Static keyword: Static indicates that the method is static (that is, the code in a static function is stored in a static store),

You do not need to instantiate it to use it.

public static void Main (string[] args) {

System.out.println ("Hello");//system class belong to Java.lang, full name is Java.lang.System

Parameter args: a means of interacting with the rain program on the command line state.

for (int i=0; i<args.length; i++)

{

System.out.println (Args[i]);

}

}

}

2. Public static void main function Description (from: http://hi.baidu.com/odbcconnection/blog/item/ a08c3d19104004be4aedbcb8.html)

The main () method is the entry method for the Java application, that is, the first method to execute when the program is running is the main () method, which is quite different from the other methods. For example, the name of the method must be main, and the method must be of public static void type, the method must receive a parameter of an array of strings, and so on.

The declaration of this main () method is: public static void Main (String args[]). It has to be defined, and this is the Java specification. Why this definition is related to the operation of the JVM.

1 explains main: When a class has a main () method, executing the command "Java class name" starts the virtual machine to execute the main method in the class.

2 Explanation of public static: As the JVM runs this Java application, it first calls the main method, which does not instantiate the object of the class, but is called directly by the class name and therefore needs to be restricted to public static.

3 EXPLANATION The return value is void: For the main method in Java, the JVM has a limit and cannot have a return value, so the return value type is void.

3. Parameter args description and test results

The main () method must have an entry, the class detail must be string[], this is the Java specification. As for the name of the string array, this can be set by itself, and according to Custom, the name of this string array is generally consistent with the name of the main parameter in the Sun Java canonical example, named Args.

The array of string arguments in the main () method receives command-line input parameters, separated by spaces between the arguments of the command line. Test results are:




Related Article

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.