This applies to subclasses of Applet, Servlet, Midlet, etc.
Why do they not need a main()? If I wanted to create a Craplet class that starts at init() or something similar, is it bad design, or how would I go about doing it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is actually good design but not obvious and what you want to do would have no effect so it is a little counter intuitive.
These types of applications live their lives in containers and as such their entry points are determined by the standards those containers must adhere to. The designers of these standards chose not to call the entry point main. You would place your functionality in an overridden method. All applets have the following four methods:
They have these methods because their superclass,
java.applet.Applet, has these methods.The superclass does not have anything but dummy code in these:
If you want to derive a class to extend or change the name of
init()you should Implement your class and have your method callinit(). This would use polymorphism to let you call the method whatever you like. Unless you are writing servlet container you are likely wasting your time.