Java Applet

  Home  Java Programing  Java Applet


“Java Applet Programming Interview Questions and Answers will guide us now that a Java applet is an applet delivered to the users in the form of Java bytecode. Java applets can run in a Web browser using a Java Virtual Machine (JVM), or in Sun's AppletViewer, a stand-alone tool for testing applets. Learn Java Applet Programming or get preparation of Java Applet by the help of this Java Applet Programming Interview Questions with Answers guide”



26 Java Applet Questions And Answers

1⟩ In our URLs and in the text of the buttons we have comma. Its causing an error. Is there a way to change the delimiting character for the menu arguments?

Since 2.00 version our applets support an user-defined delimiter for the menu arguments. To modify the default delimiter add the following parameter (you can use any character as a delimiter):

<param name="delimiter" value="~">

and use it within "menuItems":

<param name="menuItems" value="

{Home~http://www.rendc.org.com/index.php}

{Features, Setup~http://www.rendc.org/}

">

 216 views

3⟩ How to insert your applets into FrontPage?

1. Place the .class file in the directory containing the HTML document into which you want to insert the applet.

2. Copy the <applet>...</applet> tag from your applet implementation or examples to the clipboard.

3. In FrontPage select the "HTML" tab from the lower left hand corner.

4. Paste the <applet>...</applet> tag in an appropriate place between the <body> and </body> tags. You'll find a gray box with the aqua letter "J" in the "Normal" view indicating the the applet tag has been inserted.

5. To see the applet appearance select the "Preview" tab.

 171 views

4⟩ What is an Applet? Should applets have constructors?

Applets are small programs transferred through Internet, automatically installed and run as part of web-browser. Applets implements functionality of a client. Applet is a dynamic and interactive program that runs inside a Web page displayed by a Java-capable browser. We don’t have the concept of Constructors in Applets. Applets can be invoked either through browser or through Appletviewer utility provided by JDK.

 171 views

6⟩ Can we pass parameters to an applet from HTML page to an applet? How?

We can pass parameters to an applet using <param> 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.

 179 views

7⟩ How do Applets differ from Applications?

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.

 184 views

10⟩ What is Difference between AWT and Swing?

Swing provides a richer set of components than AWT. They are 100% Java-based. AWT on the other hand was developed with the mind set that if a component or capability of a component werent available on one platform, it wouldnt be available on any platform. Due to the peer-based nature of AWT, what might work on one implementation might not work on another, as the peer-integration might not be as robust. There are a few other advantages to Swing over AWT:

► Swing provides both additional components and added functionality to AWT-replacement components

► Swing components can change their appearance based on the current "look and feel" library that's being used.

► Swing components follow the Model-View-Controller (MVC) paradigm, and thus can provide a much more flexible UI.

► Swing provides "extras" for components, such as:

► Icons on many components

► Decorative borders for components

► Tool tips for components

► Swing components are lightweight (less resource intensive than AWT)

► Swing provides built-in double buffering

► Swing provides paint debugging support for when you build your own components

Swing also has a few disadvantages:

► It requires Java 2 or a separate JAR file

► If you're not very careful when programming, it can be slower than AWT (all components are drawn)

► Swing components that look like native components might not act exactly like native components

 158 views

11⟩ What are the Applets Life Cycle methods? Explain them?

methods in the life cycle of an Applet:

► init() method - called when an applet is first loaded. This method is called only once in the entire cycle of an applet. This method usually intialize the variables to be used in the applet.

► start( ) method - called each time an applet is started.

► paint() method - called when the applet is minimized or refreshed. This method is used for drawing different strings, figures, and images on the applet window.

► stop( ) method - called when the browser moves off the applet’s page.

► destroy( ) method - called when the browser is finished with the applet.

 152 views

12⟩ What is the order of method invocation in an Applet?

► public void init() : Initialization method called once by 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 applet.

 145 views

13⟩ How will you communicate between two Applets?

The simplest method is to use the static variables of a shared class since there's only one instance of the class and hence only one copy of its static variables. A slightly more reliable method relies on the fact that 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, getImage, showDocument and showStatus().

 161 views

14⟩ How do you communicate in 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 the web server. The server then passes this information to the servlet in the normal way. 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.

 179 views

15⟩ When is update method called?

Whenever a screen needs redrawing (e.g., upon creation, resizing, validating) the update method is called. By default, the update method clears the screen and then calls the paint method, which normally contains all the drawing code.

 173 views

17⟩ What are the steps involved in Applet development?

Following are the steps involved in Applet development:

► Create/Edit a Java source file. This file must contain a class which extends Applet class.

► Compile your program using javac

► Execute the appletviewer, specifying the name of your applet’s source file or html file. In case the applet information is stored in html file then Applet can be invoked using java enabled web browser.

 180 views

18⟩ What are the Applets information methods?

The following are the Applet’s information methods: getAppletInfo() method: Returns a string describing the applet, its author, copyright information, etc. getParameterInfo( ) method: Returns an array of string describing the applet’s parameters.

 174 views