Java applet Interview Questions & Answers

5 avg. rating (100% score) - 1 votes

Java applet Interview Questions & Answers

Looking for a new job is tough job but we made it easy with our interviews questions page .If you are expertise in Adobe Systems and graphics making then prepare well for the job interviews to get your dream job. Here's our recommendation on the important things to need to prepare for the job interview to achieve your career goals in an easy way. Java applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. Looking for a job can be cumbersome and tiring, especially when you are not aware of it. Follow Wisdomjobs page for Java applet job interview questions and answers page to get through your job interview successfully in first attempt.

Java Applet Interview Questions

Java applet Interview Questions
    1. Question 1. What Is An Applet? Should Applets Have Constructors?

      Answer :

      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.

    2. Question 2. How To Insert Your Applets Into Frontpage?

      Answer :

      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.

       

    3. Question 3. What Is The Order Of Method Invocation In An Applet?

      Answer :

      ► 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.

    4. Question 4. What Are The Applets Life Cycle Methods? Explain Them?

      Answer :

      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.

    5. Question 5. What Is The Sequence For Calling The Methods By Awt For Applets?

      Answer :

      When an applet begins, the AWT calls the following methods, in this sequence:
      ► init()
      ► start()
      ► paint()

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

      Answer :

      ► stop()
      ► destroy()

    7. Question 7. How Do Applets Differ From Applications?

      Answer :

      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.

    8. Question 8. Can We Pass Parameters To An Applet From Html Page To An Applet? How?

      Answer :

      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.

    9. Question 9. How Do We Read Number Information From My Applets Parameters, Given That Applets Getparameter() Method Returns A String?

      Answer :

      Use the parseInt() method in the Integer Class, the Float(String) constructor or parseFloat() method in the Class Float, or the
      Double(String) constructor or parseDoulbl() method in the class Double.

    10. Question 10. How Can I Arrange For Different Applets On A Web Page To Communicate With Each Other?

      Answer :

      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.

    11. Question 11. How Do I Select A Url From My Applet And Send The Browser To That Page?

      Answer :

      Ask the applet for its applet context and invoke showDocument() on that context object.
      URL targetURL;
      String URLString
      AppletContext context = getAppletContext();
      try
      {
      targetURL = new URL(URLString);
      }
      catch (MalformedURLException e)
      {
      // Code for recover from the exception
      }
      context. showDocument (targetURL);

    12. Question 12. Can Applets On Different Pages Communicate With Each Other?

      Answer :

      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.
      The following code snippet explains this:
      Dimension dim = getSize();
      int appletwidth = dim.width();
      int appletheight = dim.height();

    13. Question 13. Which Classes And Interfaces Does Applet Class Consist?

      Answer :

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

       

    14. Question 14. What Is Appletstub Interface?

      Answer :

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

    15. Question 15. What Are The Applets Information Methods?

      Answer :

      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.

    16. Question 16. What Are The Steps Involved In Applet Development?

      Answer :

      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.

    17. Question 17. Which Method Is Used To Output A String To An Applet? Which Function Is This Method Included In?

      Answer :

      drawString( ) method is used to output a string to an applet. This method is included in the paint method of the Applet.

    18. Question 18. When Is Update Method Called?

      Answer :

      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.

    19. Question 19. How Will You Communicate Between Two Applets?

      Answer :

      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().

    20. Question 20. 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

    21. Question 21. What Is The Base Class For All Swing Components?

      Answer :

      JComponent (except top-level containers)

    22. Question 22. 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.

    23. Question 23. 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"

    24. Question 24. 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");
      }

    25. Question 25. 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

    26. Question 26. 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.

    27. Question 27. 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.

    28. Question 28. 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.

       

    29. Question 29. 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.

    30. Question 30. 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.

Java-springs Tutorial

Java Applet Practice Tests

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java-Springs Tutorial