There are following two valid signature of main method in java as below.
Popular Spring Tutorials
Why Java force the developer to define public static void main method?
Why public? In Java public is access modifier and it using when we want to method from any where like any native library JNDI, etc. So that is reason main method is public, it can be accessible everywhere and to every object which may desire to use it for launching the application.
Why static? In Java static is a keyword and it tells the compiler that particular entity belongs to a class and should be loaded once the JVM starts. So static things we could invoke without creating instance of that class. Lets suppose we do not have main method as static. Now, to call any method you need an instance of it. Now how to create instance of class which have main method and which one should be used and from where the parameters for overloaded constructors will come.
Why void? In Java void use before the method definition its mean this method is not returning any to the caller of method. But main method is invoked by JVM so there is no use of returning any value to JVM. The only thing application would like to communicate to invoking process normal or abnormal termination. This is already possible using System.exit(int). A non-zero value means abnormal termination otherwise everything was fine.
Why String[] args? it means we create a string type array. It is useful when we pass the value through command line while execute the program.
Why name is main? it is the special user define function. Although it is user define but We can’t change the name.
Conclusion
There are following conclusion we get.
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…