05 May 2011

Interview questions: Java applets

Topic: Java Applets

Faculty Name:Saritha G Pillai

(Q) What is the difference between an applet and a servlet?

(Ans)- a) Servlets are to servers what applets are to browsers. b) Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.



http://java.sun.com/applets/

http://download.oracle.com/javase/tutorial/deployment/applet/

http://profs.etsmtl.ca/mmcguffin/learn/java/


(Q)What is the difference between applications and applets?


(Ans)

 a)Application must be run on local machine whereas applet needs no explicit installation on local machine. b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser. d)Application starts execution with its main method whereas applet starts execution with its init method. e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.

http://profs.etsmtl.ca/mmcguffin/learn/java/

http://math.bu.edu/DYSYS/applets/


(Q) 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 calls takes place :

§  stop()

§  destroy()

http://download.oracle.com/javase/tutorial/deployment/applet/

http://profs.etsmtl.ca/mmcguffin/learn/java/

(Q)Can we pass parameters to an applet from HTML page to an applet? How?


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

http://profs.etsmtl.ca/mmcguffin/learn/java/

http://math.bu.edu/DYSYS/applets/

http://www.echoecho.com/applets.htm

  (Q) 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 or parseFloat() method in the Class Float, or the

Double(String) constructor or parseDoulbl() method in the class Double.


http://www.echoecho.com/applets.htm

http://javaboutique.internet.com/

http://download.oracle.com/javase/tutorial/deployment/applet/



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


http://download.oracle.com/javase/tutorial/deployment/applet/

http://profs.etsmtl.ca/mmcguffin/learn/java/


(Q) 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?


 URL targetURL;

String URLString

AppletContext context = getAppletContext();

try

{

targetURL = new URL(URLString);

}

catch (MalformedURLException e) {

// Code for recover from the exception

}

context. showDocument (targetURL);


http://cs.uccs.edu/~cs301/java/

http://download.oracle.com/javase/tutorial/deployment/applet/iac.html

http://java.sun.com/applets/

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

http://download.oracle.com/javase/tutorial/deployment/applet/iac.html

http://java.sun.com/applets/


Faculty Name:Arun Pallisseri


Q1. What is Applet ?
A. 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. The html page loaded into the web browser contains an <applet> tag, which tells the browser where to find the Java .class files. For example,

appletviewer .class or .html file

http://www.duckware.com/applets/reference.html

Q2. Should applets have constructors?
A. We don’t have the concept of Constructors in Applets. Applets can be invoked either through browser or through Appletviewer utility provided by JDK.

http://download.oracle.com/javase/1.4.2/docs/api/java/applet/Applet.html

Q3. What are the Applet’s Life Cycle methods? Explain them? –
A. Following are 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.

http://help.sap.com/saphelp_xmii115/helpdata/en/Applet_Reference_Details/Applet_Reference.htm

Q4. what are Standalone Java application ?
A. Java program that is run by invoking the java interpreter.
For example, java coolApplication Server. The computer that hosts the web page that contains an applet. The .class files that make up the applet, and the .html files that reference the applet, reside on the server. When someone on the internet connects to a web page that contains an applet, the server delivers the .class files over the internet to the client that made the request. The server is also known as the originating host.
Client The computer that displays the web page that contains an applet. The terms server and client are sometimes used to refer to computers, and are sometimes used to refer to computer programs.

http://htmlhelp.com/reference/html40/special/applet.html

Q5. How do Applets differ from Applications?
A. Following are the main differences: Application: Stand Alone, doesn’t needweb-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.


http://www.webbasedprogramming.com/Java-Developers-Reference/ch11.htm

Q6. Can we pass parameters to an applet from HTML page to an applet? How?
A. 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.

http://profs.etsmtl.ca/mmcguffin/learn/java/

Q7. What is AppletStub Interface?

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

http://www.echoecho.com/applets.htm

Q8. What tags are mandatory when creating HTML to display an applet?
A.
1. name, height, width
2. code, name
3. codebase, height, width
4. code, height, width
Correct answer is d.

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html


Q9. Can applets on different pages communicate with each other?
A. No, Not Directly. The applets will exchange the information at one meeting place either on the local file system or at remote system.

Q10. Which classes and interfaces does Applet class consist?
A. Applet class consists of a single class, the Applet class and three interfaces:
—>AppletContext, AppletStub, and AudioClip.

http://www.hostitwise.com/java/japplet.html

Q11. What are applets prevented from doing?
A. In general, applets loaded over the net are prevented from reading and writing files on the client file system, and from making network connections except to the originating host. In addition, applets loaded over the net are prevented from starting other programs on the client. Applets loaded over the net are also not allowed to load libraries, or to define native method calls. If an applet could define native method calls, that would give the applet direct access to the underlying computer. There are other specific capabilities denied to applets loaded over the net, but most of the applet security policy is described by those two paragraphs above. Read on for the gory details.


http://www.youtube.com/watch?v=xskyN8fbba8&feature=related

http://www.youtube.com/watch?v=52ao-mAmUvY&feature=related


Q12. Can applets read or write files?
A. In Java-enabled browsers, untrusted applets cannot read or write files at all. By default, downloaded applets are considered untrusted. There are two ways for an applet to be considered trusted:
The applet is installed on the local hard disk, in a directory on the CLASSPATH used by the program that you are using to run the applet. Usually, this is a Java-enabled browser, but it could be the appletviewer, or other Java programs that know how to load applets.
Sun’s appletviewer allows applets to read files that reside in directories on the access control lists.
If the file is not on the client’s access control list, then applets cannot access the file in any way. Specifically, applets cannot
• check for the existence of the file
• read the file
• write the file
• rename the file
• create a directory on the client file system
• list the files in this file (as if it were a directory)
• check the file’s type
• check the timestamp when the file was last modified
• check the file’s size

http://www.walter-fendt.de/ph14e/

No comments:

Post a Comment