Java Applet Interview Questions and Answers
Ques 11. How do Applets differ from Applications?
Ans. Following are the main differences: Application: Stand Alone, doesn't need web-browser. Applet: Needs no explicit installation on local machine. Can be transferred through Internet on to the local machine and may run as part of web-browser. Application: Execution starts with main() method. Doesn't work if main is not there. Applet: Execution starts with init() method. Application: May or may not be a GUI. Applet: Must run within a GUI (Using AWT). This is essential feature of applets.
Ques 12. Can we pass parameters to an applet from HTML page to an applet? How?Ans. We can pass parameters to an applet using tag in the following way:
► <param name="param1″ value="value1″> ► <param name="param2″ value="value2″>
Access those parameters inside the applet is done by calling getParameter() method inside the applet. Note that getParameter() method returns String value corresponding to the parameter name.
Ques 13. How do we read number information from my applets parameters, given that Applets getParameter() method returns a string?Ans. Use the parseInt() method in the Integer Class, the Float(String) constructor or parseFloat() method in the Class Float, or the
Double(String) constructor or parseDoulbl() method in the class Double.
Ques 14. How can I arrange for different applets on a web page to communicate with each other?Ans. Name your applets inside the Applet tag and invoke AppletContext's getApplet() method in your applet code to obtain references to the other applets on the page.
Ques 15. How do I select a URL from my Applet and send the browser to that page?Ans. Ask the applet for its applet context and invoke showDocument() on that context object.
AppletContext context = getAppletContext();
targetURL = new URL(URLString);
catch (MalformedURLException e)
// Code for recover from the exception
context. showDocument (targetURL);
Most helpful rated by users: