+ 12
Main() method in java
Should a main() method be compulsorily declared in all java classes?
21 Respuestas
+ 9
main() in all classes: NO
main() in application: YES*
You need a static main(String[]) method as an entry point of your application (to start the code execution with). If your application has tons of classes, one entry point in one of the classes is more than enough.
*If you write a Java library, plugin, addon, or anything not directly runnable code (think of .DLL in windows), then you need no entry point at all. If you write no main() method at all, your code WILL compile just fine. If SoloLearn shows error, it is because it requires an entry point to run from, it is not because of Java.
If you are using an IDE (Eclipse, NetBeans, IntelliJ IDEA...) then you can have multiple main() methods and start the application from whichever main() you want. Once you make a runnable .jar file from your Java code, you must specify which main() will be its entry point.
So, by default, you don't need main() at all. To run the application with any number of classes, you are required to have at least one main() somewhere.
+ 6
Yes . I think so because without main method your promgram will remain incomplete and the compiler will show error
+ 6
No 💖💕
+ 4
no its not compulsory to have main ,
without it your prg will not cause error however it will only compile and will not run as interpretation starts with main ()
+ 3
A handy link with answers 💗
https://www.sololearn.com/learn/Java/2137/
+ 3
As a entry point.
+ 3
In java MAIN METHOD is strictly necessary because :-
public static void main (String args[])
public :- The access of this method is public
static :- This method can access from any part of your program so 'static' declared.
void :- Method doesn't return anything.
main(String args[]) :- To this main method string is passed as a reference argument which objects are are stored in the array[].
<HOPE IT WILL HELP YOU!!!>
+ 2
The Reason is Ur JRE doesn't recognize any other method except main() method
So to run ur program it compulsory to have a main method in all java classes
+ 2
Not in all, and most likely only one in entire project.
+ 2
Without main function a program is nothing and it will not work because execution of every program starts with main function.
+ 2
My 5 cents. Entry point may also be declared as final. like this public static final void main(String ... args) {} will compile
+ 2
nope one for a project
+ 1
ANSWERS:
yes beacause i went though java tutorial and it says that you need it
links:
https://code.sololearn.com/cCd6nsj9MJOq/?ref=app
see for yourself
+ 1
yes, because it is the starting point of our java program, main method and class are very important and necessary in java.
+ 1
main function is called as a driver function....so you need a driver to drive your vehicle....so driver is most.....
+ 1
yes because a main function is like a key without a key a car wonk start and without a main function compiler shows error
+ 1
The main method is compulsory because with out main there will not be any execution of the program
+ 1
What about an app.
Don't those have init() instead of main()
+ 1
If you want to run your code after compilation, you need a main function in at least one of your classes.
If you have multiple main functions and compile your code, the IDE will ask you which main function you want to compile as your entry point.
+ 1
Yes.