Sutherland Java Questions: AppletsTab.amp

Examrace Placement Series prepares you for the toughest placement exams to top companies.

What is an Applet? Should applets have constructors?

Ans: 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.

How do we read number information from my applet's parameters, given that Applet's getParameter () method returns a string?

Ans: Use the parseInt () method in the Integer Class, the Float (String) constructor in the

Class Float, or the Double (String) constructor in the class Double.

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.

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.

Eg. URL targetURL.

String URLString

AppletContext context = getAppletContext ().

try { targetUR L = new URL (URLString); } catch (Malformed URLException e) {//Code for recover from the exception }

context. ShowDocument (targetURL).

Can applets on different pages communicate with each other?

Ans: No. Not Directly. The applets will exchange the information at one meeting place

either on the local file system or at remote system.

How do Applets differ from Applications?

Ans: Appln: Stand Alone

Applet: Needs no explicit installation on local m/c.

Appln: Execution starts with main () method.

Applet: Execution starts with init () method.

Appln: May or may not be a GUI

Applet: Must run within a GUI (Using AWT)

How do I determine the width and height of my application?

Ans: Use the getSize () method, which the Applet class inherits from the Component

class in the Java. Awt package. The getSize () method returns the size of the applet as

a Dimension object, from which you extract separate width, height fields.

Eg. Dimension dim = getSize ().

int appletwidth = dim. Width ().

What is AppletStub Interface?

Ans: The applet stub interface provides the means by which an applet and the browser communicate. Your code will not typically implement this interface.

It is essential to have both the. Java file and the. Html file of an applet in the same




Ans: b.

The tag contains two attributes namely _________ and _______.

Ans: Name, value.

Passing values to parameters is done in the _________ file of an applet.

Ans: Html.

What tags are mandatory when creating HTML to display an applet

name, height, width

code, name

codebase, height, width

code, height, width (Correct Answer)

Applet's getParameter () method can be used to get parameter values. True.

What are the Applet's Life Cycle methods? Explain them?

Ans: Init () method-Can be called when an applet is first loaded.

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

paint () method-Can be called when the applet is minimized or refreshed.

stop () method-Can be called when the browser moves off the applet's page.

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

What are the Applet's information methods?

Ans: GetAppletInfo () method: Returns a string describing the applet, its author, copy

right information, etc.

getParameterInfo () method: Returns an array of string describing the applet's parameters.

All Applets are subclasses of Applet. True.

All Applets must import java. Applet and java. Awt. True.

What are the steps involved in Applet development?

Ans: Edit a Java source file, Compile your program and Execute the appletviewer, specifying the name of your applet's source file.

Applets are executed by the console based Java run-time interpreter. False

Which classes and interfaces does Applet class consist?

Ans: Applet class consists of a single class, the Applet class and three interfaces: AppletContext.

AppletStub and AudioClip.

What is the sequence for calling the methods by AWT for applets?

Ans: When an applet begins, the AWT calls the following methods, in this sequence.

init ()

start ()

paint ()

When an applet is terminated, the following sequence of method cals takes place:

stop ()

destroy ()

Which method is used to output a string to an applet?

Ans: DrawString () method.

Every color is created from an RGB value. True.