Register now or log in to join your professional community.
Yes we need a main method ,without main() the execution of program doesn't start and sometime we indirectly uses main() which is not available to our source code but its still there e.g in J2EE technologies like jsp servlets we uses container or server wchich automatically uses main for java source code if not available,
Not in all java classes for sure. And if you are running a web project you dont even need a main to execute your java code.
Not mandatory in all classes.but there should be a class with atleast1 main method.
cz without main method u can't execute class file, you'll get an exception as main method missing
Not necessary you need to define main() method in all java classes. for example java API classes doesn't have main() at all.
You can create a class withoout main() can be used by its instance in another class
In jsp servlets we use container or server which automatically uses main for java source code. However in java application development we need atleast one main method of the parent class (and not to its child class's) to execute the program.
You can have many .class file, but main() indicates the starting point of the program. So you should have one main() class(cannot have more than one)