Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Can You Write A Java Class That Could Be Used Both As An Applet As Well As An Application?

Answer»

YES. ADD a MAIN() METHOD to the APPLET.

Yes. Add a main() method to the applet.

2.

What Is A Signed Applet?

Answer»
  • 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 cannot 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.

3.

How Would You Communicate Between Applets And Servlets?

Answer»

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.

 

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.

 

4.

What Are The Methods That Control An Applet’s On-screen Appearance?

Answer»

The methods that control an applet’s on-screen appearance I.e. update and paint.
- The paint() method is called in situations the applet window being overwritten by another window or uncovered or the applet window being resized.
- The paint() is also called when the applet begins execution. The paint() method has one parameter of type Graphics which is needed to KNOW the location where the applet is supposed to paint its output.
- The update() is called when a portion of its window be redrawn. It is defined by the AWT.
- However, the update() first FILLS an applet with the default background colour and then calls paint() due to which an INSTANCE of the default color appears each time update is called.
- Thus update() method should be overridden to avoid this situation.

The methods that control an applet’s on-screen appearance I.e. update and paint.
- The paint() method is called in situations the applet window being overwritten by another window or uncovered or the applet window being resized.
- The paint() is also called when the applet begins execution. The paint() method has one parameter of type Graphics which is needed to know the location where the applet is supposed to paint its output.
- The update() is called when a portion of its window be redrawn. It is defined by the AWT.
- However, the update() first fills an applet with the default background colour and then calls paint() due to which an instance of the default color appears each time update is called.
- Thus update() method should be overridden to avoid this situation.

5.

How Can We Determine The Width And Height Of A Applet?

Answer»
  • Applet tags have attributes WIDTH and HEIGHT with which we can determine their dimensions.
  • When applet is running inside a web browser the size of an applet is SET by the height and width attributes and cannot be changed by the applet.
  • The 'getSize()' method is retrieved the size of an applet.
  • The 'getSize()' method is INHERITS from 'java.awt.Component.getSize()' and returns a 'java.awt.Dimension object.

6.

What Are The Attributes Of Applet Tags?

Answer»
  • height : Defines height of applet
  • width: Defines width of applet
  • align: Defines the text alignment around the applet
  • alt: An ALTERNATE text to be displayed if the browser SUPPORT applets but cannot run this applet
  • archive: A URL to the applet when it is STORED in a Java Archive or ZIP file
  • code: A URL that points to the class of the applet
  • CODEBASE: Indicates the base URL of the applet if the code attribute is relative
  • hspace: Defines the horizontal spacing around the applet
  • vspace: Defines the vertical spacing around the applet
  • name: Defines a name for an applet
  • object: Defines the resource name that contains a serialized representation of the applet
  • title: Display INFORMATION in tool tip

7.

Explain How To Read Information From The Applet Parameters.

Answer»

The getParameter() method can be USED within the init() method to access the parameter data.
It TAKES the parameter name as an argument.
Example:
PUBLIC void init()
{
STRING val = getParameter("foreground-color");
}

The getParameter() method can be used within the init() method to access the parameter data.
It takes the parameter name as an argument.
Example:
public void init()
{
String val = getParameter("foreground-color");
}

8.

What Type Of Sound File Formats Can I Use For The Applets?

Answer»

Java v1.02 only supports the "voice format" of the .au sound files. This is ALSO know as "µ-law, 8/16-bit, MONO, 8000hz sample RATE"

Java v1.02 only supports the "voice format" of the .au sound files. This is also know as "µ-law, 8/16-bit, mono, 8000hz sample rate"

9.

Why Do You Canvas?

Answer»

The Canvas class of java.awt is used to PROVIDE CUSTOM drawing and event handling. It provides a general GUI component for drawing images and text on the SCREEN. It does not SUPPORT any drawing methods of its own, but provides access to a Graphics object through its paint() method. The paint() method is invoked upon the creation and update of a canvas so that the Graphics object ASSOCIATED with a Canvas object can be updated.

The Canvas class of java.awt is used to provide custom drawing and event handling. It provides a general GUI component for drawing images and text on the screen. It does not support any drawing methods of its own, but provides access to a Graphics object through its paint() method. The paint() method is invoked upon the creation and update of a canvas so that the Graphics object associated with a Canvas object can be updated.

10.

What Is The Base Class For All Swing Components?

Answer»

JComponent (EXCEPT top-level CONTAINERS)

JComponent (except top-level containers)

11.

How Do You Communicate In Between Applets And Servlets?

Answer»

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

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

12.

When An Applet Is Terminated, The Following Sequence Of Method Calls Takes Place:

Answer»

STOP()
DESTROY()

► stop()
► destroy()