Why main method is important in java?
Can we print something without using Main(public static void main string[]args) method in java? i have tried using static block it's not working in java 8 version.just curious
You need to somehow indicate a point where execution of the programs starts. This is called "an entry point". In some languages you start execution from the first line of code. Perl is an example. In Java you start with a method marked as public static void main(String[] args){/* do something */}
aka psvm
. This gives you flexibility to arrange code blocks (methods) based on program logic, rather than a strict execution sequence.
Each word in psvm
has special meaning, that you shouldn't care at a moment. Java is a verbose language. It means more typing, but it also means that code is easier to read and understand. This is important for collaborations.
The main()
method is the program entry point. It is where you program begins executing. Without an entry point, it wouldn't be an application.
The main() method in the Java language is similar to the main() function in C and C++. When you execute a C or C++ program, the runtime system starts your program by calling its main() function first. The main() function then calls all the other functions required to run your program. Similarly, in the Java language, when you execute a class with the Java interpreter, the runtime system starts by calling the class's main() method. The main() method then calls all the other methods required to run your application.
https://www.cs.princeton.edu/courses/archive/spr96/cs333/java/tutorial/java/anatomy/main.html
In Java
, the public static void main (String[] args)
is the main entry point of any application. Read more about this on this official Java tutorial.
上一篇: Javascript是否通过引用传递?
下一篇: 为什么main方法在java中很重要?