Clouds
Home

Core Java

Java Fundamentals 1

Java Fundamentals 2

Java Fundamentals 3

Java Swing

Java Applet

Java Memory & Performance

Java Applet Interview Questions


How will you initialize an applet?

By writing your initialization code in the appletís init() method or appletís constructor.

What is the order of method invocation in an applet?

The Appletís life cycle methods are as follows:
  • public void init(): Initialization method called only once by the browser.
  • public void start(): Method called after init() and contains code to start processing. If the user leaves the page and returns without killing the current browser session, the start () method is called without being preceded by init().
  • public void stop(): Stops all processing started by start (). Done if user moves off page.
  • public void destroy(): Called if current browser session is being terminated. Frees all resources used by the applet.

How would you communicate between applets and servlets?

We can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and "tunnel" to a Web server. The server then passes this information to the servlet. Basically, the applet pretends to be a Web browser, and the servlet doesnít know the difference. As far as the servlet is concerned, the applet is just another HTTP client. Applets can communicate with servlets using GET or POST methods. The parameters can be passed between the applet and the servlet as name value pairs. Objects can also be passed between applet and servlet using object serialization. Objects are serialized to and from the inputstream and outputstream of the connection respectively.

How will you communicate between two Applets?

All the applets on a given page share the same AppletContext. We obtain this applet context as follows:

AppletContext ac = getAppletContext();

AppletContext provides applets with methods such as getApplet(name), getApplets(), getAudioClip(url), getImage(url), showDocument(url) and showStatus(status).

What is a signed Applet?

A signed Applet is a trusted Applet. By default, and for security reasons, Java applets are contained within a "sandbox". This means that the applets canít do anything, which might be construed as threatening to the userís machine (e.g. reading, writing or deleting local files, putting up message windows, or querying various system parameters). Early browsers had no provisions for Java applets to reach outside of the sandbox. Recent browsers, however (Internet Explorer 4 on Windows etc), have provisions to give "trusted" applets the ability to work outside the sandbox. For this power to be granted to one of your applets, the appletís code must be digitally signed with your unforgeable digital ID, and then the user must state that he trusts applets signed with your ID. The untrusted applet can request to have privileges outside the sandbox but will have to request the user for privileges every time it executes. But with the trusted applet the user can choose to remember their answer to the request, which means they wonít be asked again.

What is the difference between an applet and an application? Can you use an applet as an application?

Applet

  • Applets donít have a main method. They operate on life cycle methods init(), start(), stop(), destroy() etc.
  • Applets can be embedded in HTML pages and downloaded over the Internet. Has a sandbox security model.
  • Can only be executed within a Java compatible container like browser, appletviewer etc.

Application

  • Has a static main() method.
  • Has no support for embedding or downloading. Has no inherent security restriction.
  • Applications are executed at command line by java tool.


Java Memory & Performance >>>


Home Clouds