So I just tried to exclude the arguments String[]from the methodmain
String[]
main
Compiled!
But the JVM shows an exception
Why did it compile when String[]args should be included every time?
What's going on here? Why won't it show a compilation error?
Having typed this, I thought that the compiler did not see it as a method main.. is that so?
If so ... why? I mean, shouldn't there be only one main method that MUST have an argument String[]as an argument?
Having typed this, I thought that maybe the compiler did not see it as the main method .. is that so?
. , main. JVM " ", static public void main(String[]) , , .
static public void main(String[])
, , : JAR , , " ".
JVM .
public static void main( String[] args )
. main "" .
public static void main(String[] args), , JVM. , public static void main(), , JVM, .
public static void main(String[] args)
public static void main()
public static void main(String[] args), , , .java .
, public static void main(String[] args) ( ), , .
" ", java , . - , jar , "" . -, -, "" . - .
, .
Java . , , .
, java ClassName, Java ClassName.class public static void main (String[]) ( , String[]) . , Java :
java ClassName
ClassName.class
public static void main (String[])
"main" java.lang.NoSuchMethodError: main
. , .
, , , . , main(), - .
main()
?
static void main() { }
, JVM.
- , . , .
, (String []) , , - main_String_arr, main() - main.
..
Java , main
, ..!!
# - .
, , :
main, - . , String [] args.
. , "main" int, :
public static void main(int foo){}
, ! , Java-, Java , "main", String.
: . jar, ; , -. (String []) . .
, java main (String []); , . , , .
Java/ :
Java , :public static void main(String[] args) public static (public static static public), public static, . , "args" "argv".main C ++; , .
Java , :
public static (public static static public), public static, . , "args" "argv".
public
static
public static
static public
args
argv
main C ++; , .
, main Java . - , main . , main, .
, varargs :
public static void main(String... args)
, varargs Java .
void
init()
run()
:
.
Several classes can contain the main method inside one compilation module (and therefore they will all be called executable classes)
A class containing the main method may or may not be publicly available.
By mistake, if you must omit the static keyword (or the signature is different in some way), compilation will succeed, but a runtime error will occur.
From my blog:
Java: important notes about the main method
Source: https://habr.com/ru/post/1746617/More articles:C # Initialize a subclass based on the parent - initializationThreading the right way for my business? - multithreadingRemove text in text box using PHP - javascriptProblem with Python 2.6 + PIL + Google App Engine - pythonJADE (Java) - Change agent container - javacan I overload the main method? - javaHow to change your Hibernate car conservation strategy - setterjava templates for multiple WAR files - javaHow can I insert 1000 times in one statement? with SQLITE? - sqliteWhich Java web platform supports cross-domain Javascripting (http proxy)? - javascriptAll Articles