Why don all classes need a main() method?
Java classes do not necessarily need a main() method because not all classes are used as the entry point to start a Java program, or the execution of the code is activated through a higher level service, like a servlet container. Java class code is usually executed in the context of a larger Java application composed of lots of classes that interact together to provide the overall functionality of the system. It is rare that a single class would comprise a stand-alone application, but of course this can be the case with small utilities, test programs and experimental work. The main() method is used to start a Java program, so is only necessary where the host class serves that purpose in a Java application. Java developers sometimes include a main() method to run simple configuration or diagnostic tests on a class, where you might feed in arbitrary input parameters. Actions: Follow-up, clarify or correct this answer. Submit a new question.
Java classes do not necessarily need a main() method because not all classes are used as the entry point to start a Java program, or the execution of the code is activated through a higher level service, like a servlet container. Java class code is usually executed in the context of a larger Java application composed of lots of classes that interact together to provide the overall functionality of the system. It is rare that a single class would comprise a stand-alone application, but of course this can be the case with small utilities, test programs and experimental work. The main() method is used to start a Java program, so is only necessary where the host class serves that purpose in a Java application. Java developers sometimes include a main() method to run simple configuration or diagnostic tests on a class, where you might feed in arbitrary input parameters. Actions: Follow-up or correct this answer. Submit a new question.