#The main method is a special method, which is the entry point for program execution. A Java program starts executing from the main method.
The Java virtual machine will allocate a main thread in advance before executing the Java program, and then execute our main method in the main thread. Do you understand?
So we often say that the main method is called the main thread! (Recommended learning: java course)
Threads are different execution paths in a program! Forget it, it doesn’t matter if you don’t understand these. In short, just remember that the Java program starts executing from the main method.
For example:
public static void main(String[] args) { System.out.println("nihao"); }
When your program is running, come in from the main method, and the first thing you do is
System.out.println("nihao");
Then there are no other statements, the main method ends, and the program ends!
The declaration of this main() method is: public static void main(String args[]). It must be defined this way, this is the Java specification.
Why it is defined in this way has something to do with the operation of the JVM.
When a class has a main() method, executing the command "java class name" will start the virtual machine to execute the main method in the class.
Since the JVM will first call the main method when running this Java application, it does not instantiate the object of this class when calling, but calls it directly through the class name, so it needs to be limited to public static. (Class name.main())
For the main method in java, jvm has restrictions and cannot have a return value, so the return value type is void.
There is also an input parameter in the main method, the type is String[], this is also the specification of Java, there must be an input parameter in the main() method, the type must be String[], as for the name of the string array , this can be set by yourself. According to custom, the name of this string array is generally consistent with the main parameter name in the sun java standard example, and is named args.
Therefore, the main() method definition must be: "public static void main(String string array parameter name [])".
The above is the detailed content of What is main in Java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools
