<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; Applet interview questions</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/applet-interview-questions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 30 Jul 2010 06:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>GUI Examples Using Applets</title>
		<link>http://www.bestjavainterviewquestions.com/gui-examples-using-applets/</link>
		<comments>http://www.bestjavainterviewquestions.com/gui-examples-using-applets/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 11:30:26 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Applet interview questions]]></category>
		<category><![CDATA[applets]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=602</guid>
		<description><![CDATA[/* Now the applet will have a GUI These are elements to interact with the user. In this example they will not perform any actions. */ import java.awt.*; import java.applet.*; public class GuiExample extends Applet { // A Button to click Button okButton; // A textField to get text input TextField nameField; // A group [...]]]></description>
			<content:encoded><![CDATA[<p><em>/* Now the applet will have a GUI<br />
These are elements to interact with the user.<br />
In this example they will not perform any actions.<br />
*/</em></p>
<p><em><br />
</em></p>
<p><strong><em>import java.awt.*;<br />
import java.applet.*;</em></strong></p>
<p><strong><em>public class GuiExample extends Applet<br />
{</em></strong></p>
<p><strong><em><br />
// A Button to click<br />
Button okButton;</em></strong></p>
<p><strong><em>// A textField to get text input<br />
TextField nameField;</em></strong></p>
<p><strong><em>// A group of radio buttons<br />
// necessary to only allow one radio button to be selected at the same time</em></strong></p>
<p><strong><em>CheckboxGroup radioGroup;<br />
// The radio buttons to be selected<br />
Checkbox radio1;<br />
Checkbox radio2;</em></strong></p>
<p><strong><em>// An independant selection box<br />
Checkbox option;</em></strong></p>
<p><strong><em>public void init()<br />
{</em></strong></p>
<p><strong><em>// Tell the applet not to use a layout manager.<br />
setLayout(null);</em></strong></p>
<p><strong><em>// initialze the button and give it a text.<br />
okButton = new Button(&#8220;A button&#8221;);</em></strong></p>
<p><strong><em>// text and length of the field<br />
nameField = new TextField(&#8220;A TextField&#8221;,100);</em></strong></p>
<p><strong><em>// initialize the radio buttons group<br />
radioGroup = new CheckboxGroup();</em></strong></p>
<p><strong><em>// first radio button. Gives the label text, tells to which<br />
// group it belongs and sets the default state (unselected)<br />
radio1 = new Checkbox(&#8220;Radio1&#8243;, radioGroup,false);</em></strong></p>
<p><strong><em>// same but selected<br />
radio2 = new Checkbox(&#8220;Radio2&#8243;, radioGroup,true);</em></strong></p>
<p><strong><em>// Label and state of the checkbox<br />
option = new Checkbox(&#8220;Option&#8221;,false);</em></strong></p>
<p><strong><em>// now we will specify the positions of the GUI components.// this is done by specifying the x and y coordinate and<br />
//the width and height.</em></strong></p>
<p><strong><em>okButton.setBounds(20,20,100,30);<br />
nameField.setBounds(20,70,100,40);<br />
radio1.setBounds(20,120,100,30);<br />
radio2.setBounds(140,120,100,30);<br />
option.setBounds(20,170,100,30);</em></strong></p>
<p><strong><em>// now that all is set we can add these components to the applet<br />
add(okButton);<br />
add(nameField);<br />
add(radio1);<br />
add(radio2);<br />
add(option);<br />
}</em></strong></p>
<p><strong><em>}</em></strong></p>
<p><strong><em><br />
</em></strong></p>
<p><em>// Thats&#8217;s it, you now have given the user visual options.<br />
// However there are no actions related to these comonents.<br />
// that makes it easier to place components.</em></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/applet-interview-question/" title="Applet Interview Question"><img src="Array" alt="Applet Interview Question" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/gui-examples-using-applets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Applet Interview Question</title>
		<link>http://www.bestjavainterviewquestions.com/applet-interview-question/</link>
		<comments>http://www.bestjavainterviewquestions.com/applet-interview-question/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 16:03:36 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Applet interview questions]]></category>
		<category><![CDATA[applets]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=14</guid>
		<description><![CDATA[Q. How can I arrange for different applets on a web page to communicate with each other? A. 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. Q. How do I select a URL from my [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q.  How can I arrange for different applets on a web page to communicate with each other?</strong><br />
A. 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.</p>
<p><strong>Q.  How do I select a URL from my Applet and send the browser to that page?</strong><br />
A. Ask the applet for its applet context and invoke showDocument() on that context object.<br />
URL targetURL;</p>
<p>String URLString<br />
AppletContext context = getAppletContext ( );<br />
try<br />
{<br />
targetURL = new URL ( URLString ) ;<br />
}<br />
catch ( MalformedURLException e )<br />
{<br />
/ /  Code for recover from the exception<br />
}<br />
context. showDocument ( targetURL );</p>
<p><strong>Q.  How do I let an applet read a file?</strong><br />
A. Applets loaded into a Java-enabled browser can&#8217;t read files. Sun&#8217;s appletviewer allows applets to read files that are named on the access control list for reading. The access control list for reading is null by default, in the JDK.</p>
<p>You can allow applets to read directories or files by naming them in the acl.read property in<br />
your ~ / . hotjava / properties file.<br />
Note: The  &#8221; ~ &#8221;  ( tilde ) symbol is used on UNIX systems to refer to your home directory. If you install a web browser on your F : \ drive on your PC, and create a top-level directory named .hotjava, then your properties file is found in F: \ . hotjava \ properties.<br />
For example, to allow any files in the directory home / me to be read by applets loaded into<br />
the appletviewer, add this line to your ~ / .hotjava / properties file.<br />
acl.read= / home / me<br />
You can specify one file to be read:<br />
acl.read= / home / me / somedir / somefile<br />
Use &#8220;:&#8221; to separate entries:<br />
acl.read= / home / foo : / home / me / somedir / somefile<br />
Allowing an applet to read a directory means that it can read all the files in that directory, including any files in any subdirectories that might be hanging off that directory.</p>
<p><strong>Q.  How do I let an applet write a file?</strong><br />
A. Applets loaded into a Java-enabled browser can&#8217;t write files. Sun&#8217;s appletviewer allows applets to write files that are named on the access control list for writing. The access control list for writing is empty by default.                                                                                                                                                           You can allow applets to write to your / tmp directory by setting the acl.write property in your<br />
~ / . hotjava / properties file:<br />
acl.write= / tmp<br />
You can allow applets to write to a particular file by naming it explicitly:<br />
acl.write= / home / me / somedir / somefile<br />
Use : to separate entries:<br />
acl.write= / tmp: / home / me / somedir / somefile<br />
Bear in mind that if you open up your file system for writing by applets, there is no way to limit the amount of disk space an applet might use.</p>
<p><strong>Q.  What system properties can be read by applets, and how?</strong><br />
A. In both Java-enabled browsers and the appletviewer, applets can read these system properties by invoking System.getProperty(String key):<br />
key            meaning<br />
____________        ______________________________<br />
java.version        Java version number<br />
java.vendor        Java vendor-specific string<br />
java.vendor.url                      Java vendor URL<br />
java.class.version                      Java class version number<br />
os.name                         Operating system name<br />
os.arch                         Operating system architecture<br />
os.version                                       Operating system version<br />
file.separator                      File separator (eg, &#8221; / &#8220;)<br />
path.separator                      Path separator (eg, &#8221; : &#8220;)<br />
line.separator                      Line separator</p>
<p>Applets are prevented from reading these system properties:<br />
key            meaning<br />
____________        _____________________________<br />
java.home                        Java installation directory<br />
java.class.path                    Java classpath<br />
user.name                       User account name<br />
user.home                       User home directory<br />
user.dir                       User&#8217;s current working directory<br />
To read a system property from within an applet, simply invoke System.getProperty(key) on</p>
<p>the property you are interested in.<br />
For example,<br />
String s = System.getProperty(&#8221; os.name &#8220;);</p>
<p><strong>Q. Can I use a &#8220;native&#8221; two-tier driver for a browser applet?</strong><br />
A. No. Within an unsigned applet, you cannot load native libraries over the wire, access the local file system, or connect to any host except the host from which you loaded the applet. The applet security manager enforces these restrictions on applets as protection against applets being able to do unsavory things to unsuspecting users.</p>
<p><strong>Q. Why doesn&#8217;t my browser applet connect to the database?</strong><br />
A. If Appletviewer works and Netscape does not, it is an indication that you are violating a Netscape security restriction. In this case, the violation is that an applet cannot open a socket to a machine other than the one from which it loaded the applet. To solve this problem, you will have to serve your applet code from the same machine that hosts the DBMS.</p>
<p><strong>Q.  How do I hide system properties that applets are allowed to read by default?</strong><br />
A. There&#8217;s no way to hide the above ten system properties from applets loaded into a Java-enabled browser. The reason is that the browsers don&#8217;t consult any external files as part their Java configuration, as a security precaution, including the ~ / .hotjava / properties file.<br />
From the appletviewer, you can prevent applets from finding out anything about your system by redefining the property in your ~ / . hotjava / properties file. For example, to hide the name of the operating system that you are using, add this line to your ~ / .hotjava / properties file:<br />
os.name=null</p>
<p><strong>Q.  How can I allow applets to read system properties that they aren&#8217;t allowed to read by default?</strong><br />
A. There&#8217;s no way to allow an applet loaded into a Java-enabled browser to read system properties that they aren&#8217;t allowed to read by default. To allow applets loaded into the appletviewer to read the property named by key, add the property<br />
key.applet=true to your ~ / .hotjava / property file. For example, to allow applets to record your user name, add this line to your ~ / .hotjava / properties file:<br />
user.name.applet=true</p>
<p><strong>Q.  How can an applet open a network connection to a computer on the internet?</strong><br />
A. Applets are not allowed to open network connections to any computer, except for the host that provided the .class files. This is either the host where the html page came from, or the host specified in the codebase parameter in the applet tag, with codebase taking precendence.<br />
For example, if you try to do this from an applet that did not originate from the machine foo.com, it will fail with a security exception:<br />
Socket s = new Socket(&#8220;foo.com&#8221;, 25, true);</p>
<p><strong>Q.  How can an applet open a network connection to its originating host?</strong><br />
A. Be sure to name the originating host exactly as it was specified when the applet was loaded into the browser. That is, if you load an HTML page using the URL<br />
http: / / foo.state.edu / ~ me / appletPage.html<br />
then your applet will be able to connect to its host only by using the name foo.state.edu.<br />
Using the IP address for foo.state.edu won&#8217;t work, and using a &#8220;shorthand&#8221; form of the host name, like foo.state instead of foo.state.edu, won&#8217;t work.</p>
<p><strong>Q.  How can an applet maintain persistent state?</strong><br />
A. There is no explicit support in the JDK applet API for persistent state on the client side. However, an applet can maintain its own persistent state on the server side. That is, it can create files on the server side and read files from the server side.</p>
<p><strong>Q.  Can an applet start another program on the client?</strong><br />
A. No, applets loaded over the net are not allowed to start programs on the client. That is, an applet that you visit can&#8217;t start some rogue process on your PC. In UNIX terminology, applets are not allowed to exec or fork processes. In particular, this means that applets can&#8217;t invoke some program to list the contents of your file system, and it means that applets can&#8217;t invoke System.exit() in an attempt to kill your web browser. Applets are also not allowed to manipulate threads outside the applet&#8217;s own thread group.</p>
<p><strong>Q.  What is the difference between applets loaded over the net and applets loaded via the file system?</strong><br />
A. There are two different ways that applets are loaded by a Java system. The way an applet enters the system affects what it is allowed to do. If an applet is loaded over the net, then it is loaded by the applet class loader, and is subject to the restrictions enforced by the applet security manager. Java-enabled browsers use the applet class loader to load applets specified with file: URLs.<br />
So, the restrictions and protections that accrue from the class loader and its associated security manager are now in effect for applets loaded via file: URLs. This means that if you specify the URL like so:<br />
Location:  file : / home / me / public_html / something.html<br />
and the file something.html contains an applet, the browser loads it using its applet class loader.</p>
<p><strong>Q.  What&#8217;s the applet class loader, and what does it?</strong><br />
A. Applets loaded over the net are loaded by the applet class loader. For example, the appletviewer&#8217;s applet class loader is implemented by the class sun.applet.AppletClassLoader. The class loader enforces the Java name space hierarchy. The class loader guarantees that a unique namespace exists for classes that come from the local file system, and that a unique namespace exists for each network source. When a browser loads an applet over the net, that applet&#8217;s classes are placed in a private namespace associated with the applet&#8217;s origin. Thus, applets loaded from different network sources are partitioned from each other.<br />
Also, classes loaded by the class loader are passed through the verifier. The verifier checks that the class file conforms to the Java language specification &#8211; it doesn&#8217;t assume that the class file was produced by a &#8221; friendly &#8221; or &#8221; trusted &#8221; compiler. On the contrary, it checks the class file for purposeful violations of the language type rules and name space restrictions. The verifier ensures that<br />
•    There are no stack overflows or underflows.<br />
•    All register accesses and stores are valid.<br />
•    The parameters to all bytecode instructions are correct.<br />
•    There is no illegal data conversion.<br />
The verifier accomplishes that by doing a data-flow analysis of the bytecode instruction stream, along with checking the class file format, object signatures, and special analysis of finally clauses that are used for Java exception handling.<br />
A web browser uses only one class loader, which is established at start-up. Thereafter, the system class loader cannot be extended, overloaded, overridden or replaced. Applets cannot create or reference their own class loader.</p>
<p><strong>Q.  What&#8217;s the applet security manager, and what does it?</strong><br />
A. The applet security manager is the Java mechanism for enforcing the applet restrictions described above. The appletviewer&#8217;s applet security manager is implemented by sun.applet.AppletSecurity. A browser may only have one security manager. The security manager is established at startup, and it cannot thereafter be replaced, overloaded, overridden, or extended. Applets cannot create or reference their own security manager.</p>
<p><strong>Q.  If other languages are compiled to Java bytecodes, how does that affect the applet security model?</strong><br />
A. The verifier is independent of Sun&#8217;s reference implementation of the Java compiler and the high-level specification of the Java language. It verifies bytecodes generated by other Java compilers. It also verifies bytecodes generated by compiling other languages into the bytecode format. Bytecodes imported over the net that pass the verifier can be trusted to run on the Java virtual machine. In order to pass the verifier, bytecodes have to conform to the strict typing, the object signatures, the class file format, and the predictability of the runtime stack that are all defined by the Java language implementation.</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/gui-examples-using-applets/" title="GUI Examples Using Applets"><img src="Array" alt="GUI Examples Using Applets" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/applet-interview-question/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Applet Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/applet-interview-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/applet-interview-questions/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 13:28:11 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Applet interview questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=12</guid>
		<description><![CDATA[Q. 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 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q.  What is Applet ?</strong><br />
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 &lt;applet&gt; tag, which tells the browser where to find the Java .class files. For example,</p>
<p>appletviewer .class or .html file</p>
<p><strong>Q. Should applets have constructors?</strong><br />
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.</p>
<p><strong>Q. What are the Applet’s Life Cycle methods? Explain them? –</strong><br />
A.  Following are methods in the life cycle of an Applet:<br />
•    init() method &#8211; 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.<br />
•    start( ) method &#8211; called each time an applet is started.<br />
•    paint() method &#8211; called when the applet is minimized or refreshed. This method is</p>
<p>used for drawing different strings, figures, and images on the applet window.<br />
•    stop( ) method &#8211; called when the browser moves off the applet’s page.<br />
•    destroy( ) method &#8211; called when the browser is finished with the applet.</p>
<p><strong>Q. what are Standalone Java application ?</strong><br />
A.  Java program that is run by invoking the java interpreter.<br />
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.<br />
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.</p>
<p><strong>Q.  How do Applets differ from Applications?</strong><br />
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:<br />
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.</p>
<p><strong>Q.  Can we pass parameters to an applet from HTML page to an applet? How?</strong><br />
A. We can pass parameters to an applet using &lt;param&gt; tag in the following way:<br />
•    &lt;param name=”param1? value=”value1?&gt;<br />
•    &lt;param name=”param2? value=”value2?&gt;<br />
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.</p>
<p><strong>Q.   What is AppletStub Interface?</strong></p>
<p>A.  The applet stub interface provides the means by which an applet and the browser communicate. Your code will not typically implement this interface.</p>
<p><strong>Q.  What tags are mandatory when creating HTML to display an applet?</strong><br />
A.<br />
1.    name, height, width<br />
2.    code, name<br />
3.    codebase, height, width<br />
4.    code, height, width<br />
Correct answer is d.</p>
<p><strong>Q.  Can applets on different pages communicate with each other?</strong><br />
A. No, Not Directly. The applets will exchange the information at one meeting place either on the local file system or at remote system.</p>
<p><strong>Q.  Which classes and interfaces does Applet class consist?</strong><br />
A.  Applet class consists of a single class, the Applet class and three interfaces:<br />
&#8212;&gt;AppletContext, AppletStub, and AudioClip.</p>
<p><strong>Q.  What are applets prevented from doing?</strong><br />
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.</p>
<p><strong>Q.  Can applets read or write files?</strong><br />
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:<br />
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.<br />
Sun&#8217;s appletviewer allows applets to read files that reside in directories on the access control lists.<br />
If the file is not on the client&#8217;s access control list, then applets cannot access the file in any way. Specifically, applets cannot<br />
•    check for the existence of the file<br />
•    read the file<br />
•    write the file<br />
•    rename the file<br />
•    create a directory on the client file system<br />
•    list the files in this file (as if it were a directory)<br />
•    check the file&#8217;s type<br />
•    check the timestamp when the file was last modified<br />
•    check the file&#8217;s size</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/difference-between-include-and-import/" title="Difference between #include and Import"><img src="Array" alt="Difference between #include and Import" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/awt-interview-questions-2/" title="AWT Interview Questions"><img src="Array" alt="AWT Interview Questions" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/creating-a-sessionfactory-using-hibernate/" title="Creating a SessionFactory Using Hibernate"><img src="Array" alt="Creating a SessionFactory Using Hibernate" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/difference-between-print-and-println-methods-in-java/" title="Difference between Print() and Println() Methods in Java"><img src="Array" alt="Difference between Print() and Println() Methods in Java" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/benefits-of-connection-pooling/" title="Benefits of Connection Pooling"><img src="Array" alt="Benefits of Connection Pooling" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/applet-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
