The main() method is the entry point of a standard Java application. The JVM uses the main() method to execute a Java program.
Typically, we would write the complete code for the main() method as follows:
|
1 2 3 4 5 6 7 8 |
package com.huongdanjava.java; public class Application { public static void main(String[] args) { } } |
The keyword public is an access modifier, meaning the main() method can be accessed anywhere. From Java 25 onwards, you are no longer required to declare this public access modifier; Java can understand and execute the main() method.
The keyword static defines that the main() method belongs to the class, not an object of the class, so it can be easily called by the JVM without instantiating an object for the Application class.
The keyword void defines the data type returned with no data. It simply returns control to the JVM.
Java will use the correct method name, main(), to execute the application.
String[] is an array of Strings, allowing us to pass parameters to the application. There are several other ways you can declare this parameter:
String args[]String... args
You can watch the video here:

