1java Language Advantages:
(1) Java is a purely object-oriented language
(2) Platform independence
(3) Java provides a lot of built-in library classes
(4) provides support for Web application development
(5) Good safety and robustness
(6) Eliminate confusing concepts such as pointers in C + + that are difficult to understand
2, why need public static viod mian (String [] args) This method
Answer: Java Program entry
Static indicates that this is a static method, where the code in the method is stored in a static code area, and as long as the class is loaded, it can be accessed directly through the class name by using the method without the need to access it by instantiating the object. Mian ().
Viod indicates no return value.
Main () is a special method name that is recognized by the Java Virtual machine.
String[] args provides a means for programmers to interact with programs at the command line
Extension: does main () have other definition formats?
1) since public and static have no sequencing, the following definition format is also true
static public void Mian (string[] args)
2) The main () method can also be defined as final.
public static final Viod main (string[] args)
3) You can also use synchronized to modify the Mian () method.
static public sybnchronized void Mian (string[] args)
In summary: Regardless of the definition, you must ensure that the return value of the main () method is void and has static and public keyword adornments. Because Mian () is a program's entry method, it cannot be decorated with the abstract keyword.
3. Can there be more than one Mian () method in the same. java file?
Although the Mian () method can be defined in each class, only the Mian () method in the public-decorated class with the same file name can be used as the entry method for the program. The following example:
Package test;
Class t{
public static void Mian (string[] args) {
System.out.println ("T mian");
}
}
public class Miantest {
Program Entry function
public static void Main (string[] args) {
System.out.println ("Test mian entrance");
}
}
Operation Result:
Test Mian Entrance
4. Implement the main () method to output "Hello world!" before execution
Scenario: a static block of code is implemented because a static block of code is called when the class is loaded
Package test;
public class HelloWorld {
public static void Main (string[] args) {
System.out.println ("Hello world1111!");
}
static{
System.out.println ("Hello world22222!");
}
}
Program Run Result:
Hello world22222!
Hello world1111!
Basic Java Knowledge