I do not want to change the public static void
... String[] args
part of the signature, but is it possible to "rename" this function (eg. just for fun)?
So the entry point for execution would be a function with another name.
Rename it to, like, boot
(what would better reflect, if not being historical, the actual use for it in my particular case).
related
I'm interested in doing something different, but these questions are still interesting:
public static void main(String arg[ ] ) in java is it fixed?
Why the name main for function main()
Yes, we can change the order of public static void main() to static public void main() in Java, the compiler doesn't throw any compile-time or runtime error. In Java, we can declare access modifiers in any order, the method name comes last, the return type comes second to last and then after it's our choice.
Java main method is the entry point of any java program. Its syntax is always public static void main(String[] args) . You can only change the name of String array argument, for example you can change args to myStringArgs .
The main method is public in Java because it has to be invoked by the JVM. So, if main() is not public in Java, the JVM won't call it. That's all about why the main method is declared public and static in Java.
The main method must be declared as static so that the JVM can access the main method directly by using the class name. When we execute a java program we use the class name so when we write static it will help the JVM to access the main method.
No. The Java Language Specification says:
A Java virtual machine starts execution by invoking the method
main
of some specified class, passing it a single argument, which is an array of strings.
The JVM Specification says the same thing:
The Java virtual machine then links the initial class, initializes it, and invokes the public class method
void main(String[])
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With