Lab 6 - Applets & Applications

Post Test

 

 

Knowledge/Memory

 

1.  Which of the following is not a standard method used in applet programming?

 

  1. init()
  2. paint()
  3. fork()
  4. start()

 

Answer: C

 

2.   What are the main differences between a Java applet and a Java application?

 

  1. A Java application must have a main method, but the main method is optional for a Java applet.
  2. A Java application must have a main method, but a Java applet cannot have a main method.
  3. A Java application is standalone whereas a Java applet is not.
  4. A Java applet is portable whereas a Java application must run on the host where it was compiled.

a.       I           b. I & II           c. II & III         d. I, III, & IV

 

Answer: C

 

  1. What must be imported to get class Applet?

 

a.   java.applet.Applet

b.      java.util

c.       java.java

d.      java.awt.*

 

Answer: A

 

4.  What are the appropriate uses for an applet?

 

I.        Designing Web pages.

II.     Running server side application.

III.   Running client side application.

IV.  Making a secure connection to a server.

 

a.   II          b. I & II           c. I, II & III      d. I & III

 

Answer: D

 

5.   Given that an Applet contains three methods: init(), paint() and start(). Which method will be invoked first?

 

  1. init()
  2. paint()
  3. start()

 

Answer: A

 

Comprehension:

 

6.   An Applet can throw an exception.

  1. True
  2. False

 

Answer: A

 

7.   Which of the following statements is true?

 

I.    The browser acts the main() method and the applet provides methods for the browser.

II.   Unlike a Java application, a Java applet cannot be compiled because it does not contain a main() method.

III. Applets are intended to be included in HTML pages.

IV. Using the <APPLETVIEWER> tag, you specify (at a minimum) the location of the Applet subclass and the dimensions of the applet’s onscreen display area.

 

a.       I, II, III, & IV   b. I & II           c. I, II, & III     d. I & III

 

Answer: D

 

Application:

 

8.  Given the following HTML code, which portion of the <APPLET> tag must be changed if we change the location of the Applet class file?

 

     <APPLET CODE="HelloApplet.class"

            WIDTH=500

            HEIGHT=500

            CODEBASE=".">

      </APPLET>

 

  1. CODE
  2. CODEBASE
  3. Both CODE and CODEBASE
  4. None of the tags must be changed.

 

Answer: B

 

9.   Suppose you are a programmer for a company and have been asked to build a system for a particular task.  Your client wants to know whether to use an applet or an application.  What questions should you ask?

 

I.        Will the system be used within a browser?

II.   Will the system be an interactive system with a graphical user interface?

III. Will the system require dynamic and flexible information dissemination on the Internet?

IV. Will the system require read/write access to files on the local computer?

 

a.       I & II   b. II & III         c. I, II, & III     d. I, II, III, & IV           e. II, III, & IV

 

Answer: D

 

Analysis:

 

10.  Given the following code:

 

public class HelloApplet extends java.applet.Applet

{

   public void paint(java.awt.Graphics g)

   {

      g.drawString("Hello World Applet!", 20, 20);

   }

}

 

If we change the line

 

            g.drawString("Hello World Applet!", 20, 20);

 

to

 

      g.drawString("Hello World Applet!", 200, 200);

 

What changes will be reflected in the output when you run this modified Applet?

 

  1. The position of the string  "Hello World Applet!" will be changed.
  2. The dimensions of the Applet will be changed.
  3. The length of the string "Hello World Applet!" will be changed.
  4. No changes will be reflected in the output.

 

Answer: A