<?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; JAVA UTIL QUESTIONS</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/java-util-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, 03 Feb 2012 10:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Define HashSet Class</title>
		<link>http://www.bestjavainterviewquestions.com/define-hashset-class/</link>
		<comments>http://www.bestjavainterviewquestions.com/define-hashset-class/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 17:34:58 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Define HashSet]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[core java]]></category>
		<category><![CDATA[HashSet]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[utill package]]></category>
		<category><![CDATA[what is HashSet class]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/define-hashset-class/</guid>
		<description><![CDATA[HashSet extends AbstractSet and implements the Set interface. It creates a collection that uses a hash table for storage. As most readers likely know, a hash table stores information by using a mechanism called hashing. In hashing, the informational content of a key is used to determine a unique value, called its hash code. The [...]]]></description>
			<content:encoded><![CDATA[<p><strong>HashSet </strong>extends <strong>AbstractSet </strong>and implements the <strong>Set </strong>interface. It creates a collection that uses a hash table for storage. As most readers likely know, a hash table stores information by using a mechanism called <em>hashing</em>. In <em>hashing</em>, the informational content of a key is used to determine a unique value, called its <em>hash code</em>. The hash code is then used as the index at which the data associated with the key is stored. The transformation of the key into its hash code is performed automatically, you never see the hash code itself. Also, your code can&#8217;t directly index the hash table. The advantage of hashing is that it allows the execution time of basic operations, such as<strong> add(), contains(), remove()</strong>, and size, to remain constant even for large sets,<br />
The following constructors are defined:</p>
<p><strong><em>HashSet()<br />
HashSet(Collection c)<br />
HashSet(int capacity)<br />
HashSet(int capacity, float fillRatio)</em></strong></p>
<p>The first form constructs a default has set. The second form initializes the hash set by using the elements of c. The third form initializes the capacity of the hash set to capacity. The fourth form initializes both the capacity and the fill ration (also called<em> load capacity</em>) of the hash set from its arguments. The fill ratio must be between 0.0 and 1.0, and it determines how full the hash set can be before it is re sized upward. Specifically when the number of elements is greater than the capacity of the hash set multiplied by its fill ratio, the hash set is expanded. For constructors that do not take a fill ratio, 0.75 is used.</p>
<p><strong>HashSet </strong>does not define any additional methods beyond those provided by its <em>superclasses </em>and interfaces.<br />
Importantly, note that a hash set does not guarantee the order of its elements, because the process of hashing doesn&#8217;t usually lend itself to the creation of sorted sets. If you need sorted storage, then another collection, such as <strong>TreeSet</strong>, is a better choice.</p>
<p><em>Here is an example that demonstrates <strong>HashSet</strong>:</em></p>
<p><em>//Demonstrate HashSet.</em></p>
<p><em>import java.util.*;<br />
class HashSet Demo {<br />
public static void main(String args[])<br />
{<br />
//create a hash set</em></p>
<p><em>HashSet hash=new HashSet();</em></p>
<p><em>//add elements to the hash set</em></p>
<p><em>hash.add(&#8220;B&#8221;);<br />
hash.add(&#8220;A&#8221;);<br />
hash.add(&#8220;D&#8221;);<br />
hash.add(&#8220;E&#8221;);<br />
hash.add(&#8220;C&#8221;);<br />
hash.add(&#8220;F&#8221;);<br />
System.out.println(hash);<br />
}<br />
}</em></p>
<p><em>The following is the output from this program:</em></p>
<p><em>[ A,F, E, D, C, B]</em><br />
As explained , the elements are not stored in sorted order, and the precise output may vary.</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions">Core Java Interview Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li><li>August 17, 2010 -- <a href="http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/" title="Define Hashtable,HashMap and HashSet">Define Hashtable,HashMap and HashSet</a> (1)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/when-the-port-number-is-changed/" title="When the port number is changed">When the port number is changed</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/define-hashset-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sockets programming in Java for Client/Server</title>
		<link>http://www.bestjavainterviewquestions.com/sockets-programming-in-java-for-clientserver/</link>
		<comments>http://www.bestjavainterviewquestions.com/sockets-programming-in-java-for-clientserver/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 16:53:37 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Client/Servler Communication]]></category>
		<category><![CDATA[client/server programming]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=519</guid>
		<description><![CDATA[Note: Establishing Communication between a Server and a Client through a socket is called Socket Programming To create the Client Socket Socket Class is available in java.net package. To create ServerSocket, ServerSocket class is avialable in java.net package A Client is a machine that sends a request for some service A Server is machine that [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note:</strong></p>
<p>Establishing Communication between a Server and a Client through a socket is called Socket Programming</p>
<ul>
<li>To create the Client Socket <em>Socket Class is available in java.net package.</em></li>
<li>To create ServerSocket, <em>ServerSocket </em>class is avialable in <em>java.net package</em></li>
<li>A Client is a machine that sends a request for some service</li>
<li>A Server is machine that provides services to the client</li>
</ul>
<p><em><strong><br />
</strong></em></p>
<p><em><strong>Note:  Write a java program to create a client and server Communication between them</strong></em></p>
<p><strong>// A Server that sends a String to the client as a response to the client connection<br />
</strong></p>
<p><em>import java.io.*;<br />
import java.net.*;</em></p>
<p><em>class Server1<br />
{<br />
public static void main(String args[])throws IOException<br />
{</em></p>
<p><em>//create the serversocket</em></p>
<p><em>ServerSocket ss=new ServerSocket(777);</em></p>
<p><em>//make the socket to accept the client connection</em></p>
<p><em>Socket s=ss.accept();<br />
System.out.println(&#8220;connection established&#8221;);</em></p>
<p><em>//flow of data in the socket</em></p>
<p><em>OutputStream obj=s.getOutputStream();</em></p>
<p><em>//to send data to the client</em></p>
<p><em>PrintStream ps=new PrintStream(obj);</em></p>
<p><em>//to receive data from the client</em></p>
<p><em>BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));</em></p>
<p><em>//to read data from keyboard</em></p>
<p><em>BufferedReader kb=new BufferedReader(new InputStreamReader(System.in));<br />
while(true)<br />
{<br />
String str,str1;<br />
while((str=br.readLine())!=null)<br />
{<br />
System.out.println(str);<br />
str1=kb.readLine();<br />
ps.println(str1);<br />
}</em></p>
<p><em>//disconnet server</em></p>
<p><em>ss.close();<br />
s.close();<br />
br.close();<br />
kb.close();<br />
ps.close();<br />
System.exit(0);<br />
}<br />
}<br />
}</em></p>
<p><strong>// A Client that sends a Request to the Server for the response<br />
</strong></p>
<p><em>import java.io.*;<br />
import java.net.*;</em></p>
<p><em>class Client1<br />
{<br />
public static void main(String args[])throws IOException<br />
{</em></p>
<p><em>//create client socket</em></p>
<p><em>Socket s=new Socket(&#8220;localhost&#8221;,777);</em></p>
<p><em>//data send by the client the dos is most preferable</em></p>
<p><em>DataOutputStream dos=new DataOutputStream(s.getOutputStream());<br />
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));<br />
BufferedReader kb=new BufferedReader(new InputStreamReader(System.in));<br />
String str,str1;<br />
while(!(str=kb.readLine()).equals(&#8220;exit&#8221;))<br />
{<br />
dos.writeBytes(str+&#8221;\n&#8221;);<br />
str1=br.readLine();<br />
System.out.println(str1);<br />
}</em></p>
<p><em>//disconnect the client</em></p>
<p><em>dos.close();<br />
br.close();<br />
kb.close();<br />
}<br />
}</em></p>
<p><strong>Procedure of Compiling  and executing the program</strong></p>
<ol>
<li>First Compile the Client Program and wait for the server compilation<strong><em> javac Client1.java </em></strong></li>
<li>Secound Compile the Server Program and wait for the client compilation <em><strong>javac Server1.java</strong></em></li>
<li>and Run the server wait for the request from the client  <strong><em>java Server1.</em></strong></li>
<li>But don&#8217;t run the Server program before the Compilation of the Client compilation</li>
<li>Run the Client and send the Request to the Server which is waiting for the connection to be establish by <strong><em>java Client1.</em></strong></li>
<li>After the client sends the request the server will show the message as the Connection is established and ready for the communication.</li>
</ol>
<p><strong><br />
</strong></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>October 16, 2008 -- <a href="http://www.bestjavainterviewquestions.com/479/" title="What is Thread Safe Servlet">What is Thread Safe Servlet</a> (0)</li><li>August 25, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-servletinputstream/" title="Define ServletInputStream">Define ServletInputStream</a> (0)</li><li>October 4, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-is-jtapi/" title="What is JTAPI">What is JTAPI</a> (0)</li><li>September 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/creating-a-sessionfactory-using-hibernate/" title="Creating a SessionFactory Using Hibernate">Creating a SessionFactory Using Hibernate</a> (0)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-implicit-objects/" title="Define implicit objects">Define implicit objects</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/sockets-programming-in-java-for-clientserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When the port number is changed</title>
		<link>http://www.bestjavainterviewquestions.com/when-the-port-number-is-changed/</link>
		<comments>http://www.bestjavainterviewquestions.com/when-the-port-number-is-changed/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 11:47:51 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[JAVA UTIL QUESTIONS]]></category>
		<category><![CDATA[core java]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java.net]]></category>
		<category><![CDATA[net package]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=508</guid>
		<description><![CDATA[When a new Socket is created new port number should be allocated. When the service on the same socket is changed, a new port number should be alloted. Note :- Some alloted port numbers : port no. Application 13                                    Date and time Services 21                                    FTP,Which transfers files 23                                   Telnet,Which provides remote login 25                                   SMTP,Which delivers [...]]]></description>
			<content:encoded><![CDATA[<p>When a new Socket is created new port number should be allocated.</p>
<p>When the service on the same socket is changed, a new port number should be alloted.</p>
<p><strong>Note :- Some alloted port numbers :</strong></p>
<p><span style="text-decoration: underline;"><strong>port no.</strong></span> <span style="text-decoration: underline;"><strong>Application</strong></span></p>
<p>13                                    Date and time Services</p>
<p>21                                    FTP,Which transfers files</p>
<p>23                                   Telnet,Which provides remote login</p>
<p>25                                   SMTP,Which delivers mail messages</p>
<p>67                                   BOOTP,Which provides configuration at  boot time</p>
<p>80                                  HTTP, Which transfers web pages</p>
<p>109                          POP,Whcih enables users to access mail boxes on remote sys.</p>
<p>for port no Internally 2 bytes is used</p>
<p><strong>NOTE:</strong></p>
<p><strong>1) </strong>To create <em>Server Socket</em>, ServeerSocket class is avialable in <strong><em>java.net.package</em></strong></p>
<p><strong><em>2) </em></strong>To create Client Socket Socket class is available in <strong><em>java.net.package</em></strong></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-is-port-number/" title="What is Port Number">What is Port Number</a> (0)</li><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions">Core Java Interview Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/when-the-port-number-is-changed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which of the Collection Classes will not allow duplicate values</title>
		<link>http://www.bestjavainterviewquestions.com/which-of-the-collection-classes-will-not-allow-duplicate-values/</link>
		<comments>http://www.bestjavainterviewquestions.com/which-of-the-collection-classes-will-not-allow-duplicate-values/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 06:24:05 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[JAVA UTIL QUESTIONS]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=440</guid>
		<description><![CDATA[Rep) Sets (or) set Classes will not allow duplicate values Random PostsJuly 7, 2008 -- EJB INTERVIEW QUESTIONS (1)January 26, 2009 -- Jsp Example: File Uploading (0)October 5, 2008 -- GoTo statement in Java (0)September 17, 2008 -- Creating a SessionFactory Using Hibernate (0)December 10, 2008 -- What is Anonymous Inner Class (0)]]></description>
			<content:encoded><![CDATA[<p><strong>Rep) </strong>Sets (or) set Classes will not allow duplicate values</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>October 4, 2008 -- <a href="http://www.bestjavainterviewquestions.com/how-application-creates-a-connection/" title="How application creates a connection">How application creates a connection</a> (0)</li><li>September 2, 2008 -- <a href="http://www.bestjavainterviewquestions.com/difference-between-stateful-and-stateless-session-bean/" title="Difference Between StateFul and Stateless Session Bean">Difference Between StateFul and Stateless Session Bean</a> (0)</li><li>July 7, 2008 -- <a href="http://www.bestjavainterviewquestions.com/servlet-important-questions/" title="Servlet Important Questions">Servlet Important Questions</a> (0)</li><li>March 20, 2009 -- <a href="http://www.bestjavainterviewquestions.com/life-cycle-of-stateless-session-bean/" title="Life Cycle of stateless session bean">Life Cycle of stateless session bean</a> (0)</li><li>February 15, 2009 -- <a href="http://www.bestjavainterviewquestions.com/write-a-note-on-ejb-frame-work/" title="Write a note on EJB frame work">Write a note on EJB frame work</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/which-of-the-collection-classes-will-not-allow-duplicate-values/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Load Factor</title>
		<link>http://www.bestjavainterviewquestions.com/load-factor/</link>
		<comments>http://www.bestjavainterviewquestions.com/load-factor/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 01:54:18 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[LoadFactor]]></category>
		<category><![CDATA[define loadfactor]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=436</guid>
		<description><![CDATA[Ques) What is LoadFactor? Rep) LoadFactor is useful to determine the point where the capacity of the Hashtable (HashMap) will be doubled For Hashtable initial capacity * loadfactory&#8211;&#62;11 * 0.75=8 This class implements a hashtable, which maps keys to values. Any non-null object can be used as a key or as a value.To successfully store [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Ques) What is LoadFactor?</strong></p>
<p><strong>Rep)</strong> <strong>LoadFactor </strong>is useful to determine the point where the capacity of the Hashtable (HashMap) will be doubled For <em>Hashtable</em> initial capacity * loadfactory&#8211;&gt;11 * 0.75=8</p>
<p>This class implements a<em> hashtable</em>, which maps keys to values. Any non-null object can be used as a key or as a value.To successfully store and retrieve objects from a Hashtable , the objects used as keys must implement the HashCode method and the equals method.</p>
<p>The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the Hashtable exceeds the product of the load factor and the current capacity, the capacity is increased by calling the rehash method.<br />
Therefore after starting 8th pair key values, the capacity of the <em>Hashtable</em> will be <span style="text-decoration: underline;"><strong>&#8220;Doubled&#8221;</strong></span> &#8211;&gt;11*2=22.</p>
<p>Hashtable ht=new Hashtable(100);</p>
<p>|__ It is the inital capacity of the hashtable</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>October 5, 2008 -- <a href="http://www.bestjavainterviewquestions.com/difference-between-get-and-head-request-methods/" title="Difference between GET and HEAD request methods">Difference between GET and HEAD request methods</a> (0)</li><li>July 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/jsf-important-questions/" title="JSF Important Questions">JSF Important Questions</a> (2)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-session-bean-and-entity-bean/" title="Define Session Bean and Entity Bean">Define Session Bean and Entity Bean</a> (0)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/how-many-ejb-objects-are-created-for-a-bean/" title="How many EJB Objects are created for a Bean">How many EJB Objects are created for a Bean</a> (0)</li><li>September 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/hibernate-introduction/" title="Hibernate Introduction">Hibernate Introduction</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/load-factor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Collection FrameWork</title>
		<link>http://www.bestjavainterviewquestions.com/collection-framework/</link>
		<comments>http://www.bestjavainterviewquestions.com/collection-framework/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 01:40:24 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Collection FrameWork]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[define collection framework]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=429</guid>
		<description><![CDATA[Q) What is Collection FrameWork? Res) A Collection FrameWork represents a class library to handle groups of objects &#8211;&#62; Collection framework is implemented in Java.Util.Package. &#8211;&#62; Collection does&#8217;t store copy of all the object, but it stores references of all objects. &#8211;&#62; Collection classes will act upon only referenced datatypes they do not act upon [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) What is Collection FrameWork?</strong></p>
<p><strong>Res)</strong> A Collection FrameWork represents a class library to handle groups of objects</p>
<p><strong>&#8211;&gt; </strong>Collection framework is implemented in <strong>Java.Util.Package</strong>.</p>
<p><strong>&#8211;&gt; </strong>Collection does&#8217;t store copy of all the object, but it stores references of all objects.</p>
<p><strong>&#8211;&gt; </strong>Collection classes will act upon only referenced datatypes they do not act upon primitive datatypes.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>November 6, 2008 -- <a href="http://www.bestjavainterviewquestions.com/load-factor/" title="Load Factor">Load Factor</a> (0)</li><li>August 17, 2010 -- <a href="http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/" title="Define Hashtable,HashMap and HashSet">Define Hashtable,HashMap and HashSet</a> (1)</li><li>February 15, 2009 -- <a href="http://www.bestjavainterviewquestions.com/services-provided-by-ejb-container/" title="Services Provided by EJB Container">Services Provided by EJB Container</a> (0)</li><li>August 25, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-servletoutputstream/" title="Define ServletOutputStream">Define ServletOutputStream</a> (0)</li><li>October 16, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-jsp/" title="Define JSP">Define JSP</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/collection-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ArrayList Class</title>
		<link>http://www.bestjavainterviewquestions.com/arraylist-class/</link>
		<comments>http://www.bestjavainterviewquestions.com/arraylist-class/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 16:38:17 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[ArrayList Class]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[define arraylist]]></category>
		<category><![CDATA[List]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=426</guid>
		<description><![CDATA[The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed. In Java, standard arrays are of a fixed length. After arrays are created, they cannot grow or shrink, which means that you may not know util run time precisely how large of an array you need. [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>ArrayList</strong> class extends <strong>AbstractList</strong> and implements the <strong>List </strong>interface. <strong>ArrayList</strong> supports dynamic arrays that can grow as needed. In Java, standard arrays are of a fixed length. After arrays are created, they cannot grow or shrink, which means that you may not know util run time precisely how large of an array you need. To handle this situation, the collections framework defines ArrayList.</p>
<p>In essence, an ArrayList is a variable-length array of object references. Thjat is, an <strong>ArrayList </strong>can dynamically increase or decrease in size. Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the arraya may be shrunk.</p>
<p>It is dynamically growing array that stores objects. It is not Synchronized and Vector is a Synchronized</p>
<p><strong>Note: </strong>You can&#8217;t store primitive data type. we can store only object into ArrayList.</p>
<p><strong>ArrayList</strong> has the constructors shown here:</p>
<p><strong>&#8211;&gt; </strong>ArrayList();  <em>//This constructor builds an empty array list</em></p>
<p><strong>&#8211;&gt; </strong>ArrayList(Collection c)  <em>// This constructor builds an array list that is initialized with the elements of collection <strong>c</strong>.</em></p>
<p><strong>&#8211;&gt; </strong>ArrayList(int <em>capacity</em>)  <em>//This Contructor builds an array list that has the specified initial capacity.</em></p>
<p><em>1) To Creat  an ArrayList</em></p>
<p>ArrayList arl=new ArrayList();  //creating an object</p>
<p>ArrayList Arl=new ArrayList(20);  //creating an object with the size</p>
<p><em>2) To add objects use add() method</em></p>
<p>arl.add(&#8220;APPLE&#8221;);</p>
<p>arl.add(2,&#8221;APPLE&#8221;);</p>
<p><em>3) To Remove objects use remove().</em></p>
<p>arl.remove(&#8220;APPLE&#8221;);  //remove an string</p>
<p>arl.remove(2);  //removing the string  of specified location</p>
<p><em>4) To Know Number of objects, use size()</em></p>
<p>int n= arl.size()   // It displays the size of the array list.</p>
<p><strong>Example of using an ArrayList.</strong></p>
<p>//Demonstrating ArrayList.</p>
<p>import java.util.*;</p>
<p>class Arraylist Demo  {<br />
public static void main(String args[])  {</p>
<p>ArrayList list=new ArrayList();  //creating an object for ArrayList class<br />
System.out.println(&#8220;Initial size of al:&#8221;+al.size());</p>
<p>//add  elements to the array list<br />
al.add(&#8220;C&#8221;);<br />
al.add(&#8220;B&#8221;);<br />
al.add(&#8220;A&#8221;);<br />
al.add(&#8220;D&#8221;);<br />
al.add(&#8220;E&#8221;);<br />
al.add(&#8220;T&#8221;);<br />
al.add(1,&#8221;A2&#8243;);</p>
<p>System.out.println(&#8220;Size of al after additions: &#8220;+ al.size());</p>
<p>//display the array list<br />
System.out.println(&#8220;Content of al:&#8221;+al);</p>
<p>//Remove elements from the array list<br />
al.remove(&#8220;F&#8221;);<br />
al.remove(2);</p>
<p>System.out.println(&#8220;size of al after deletion:&#8221; +al.size());<br />
System.out.println(&#8220;contents of al:&#8221;+al);<br />
}<br />
}</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-util-package-2/" title="JAVA UTIL PACKAGE">JAVA UTIL PACKAGE</a> (0)</li><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions">Core Java Interview Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/arraylist-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Write a Short notes on Vectors</title>
		<link>http://www.bestjavainterviewquestions.com/write-a-short-notes-on-vectors/</link>
		<comments>http://www.bestjavainterviewquestions.com/write-a-short-notes-on-vectors/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 13:22:30 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Define Vector]]></category>
		<category><![CDATA[define vector class]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=424</guid>
		<description><![CDATA[VECTORS C and C++ programmers will know that generic utility functions with variable arguments can be used to pass different arguments depending upon the calling situations. Java does not support the concept of variable arguments to a function. This feature can be achieved in Java through the use of the Vector class contained in the [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>VECTORS</strong></span></p>
<p>C and C++ programmers will know that generic utility functions with variable arguments can be used to pass different arguments depending upon the calling situations. Java does not support the concept of variable arguments to a function. This feature can be achieved in Java through the use of the Vector class contained in the <strong>java.util </strong>package. This class can be used to create a generic dynamic array known as Vector that can hold <em>objects of any type</em> and any <em>number</em>. The objects do not have to have to be homogenous. Array can be easily implemented as vector. Vectors are created like arrays as follows:</p>
<p><strong>Vector</strong> intVect  = new Vector();   //declaring without size</p>
<p><strong>Vector </strong>list        = new Vector(3);  // declaring with size.</p>
<p>Note that a vector can be declared without specifying any size explicitly. A vector can accommodate an unknown number of items. Even, when a size is specified, this can be overlooked and different number of items may be put into the vector. Remember, in contrast, an array must always have its size specified.</p>
<p>Vector possess a number of advantages over arrays.</p>
<p>1.  It is convenient to use vectors to store objects.</p>
<p>2. A vector can be used to store alist of objects that may vary in size.</p>
<p>3.  We can add and delete objects from the list as and when required.</p>
<p>A major constraint in using vectors is that we cannot directly store simple data types in a vector; we can only store objects. Therefore, we need to convert simple tyhpes to objects. This can be done using the wrapper classes.</p>
<p>The vector class supports a number of methods that can be used to manipulate the vectors created. Important ones are listed</p>
<p><span style="text-decoration: underline;"><strong>Method Call</strong></span><strong> </strong><strong> </strong><strong>and <span style="text-decoration: underline;">task performed</span><br />
</strong></p>
<p><em>list.addElement (item) </em> Adds the item specified to the list at the end.</p>
<p><em>list.elementAt(10) </em>Gives the name of the 10th object.</p>
<p><em>list.size()</em> Gives the number of objects present.</p>
<p><em>list.removeElement(item) </em>Removes the specified item from the list.</p>
<p><em>list.removeElementAt(n) </em>Removes the item stored in the n<em>th</em> position of the list.</p>
<p><em>list.removeAllElements() </em> Removes all the item stored in the n<em>th</em> position of the list.</p>
<p><em>list.copyInto(array) </em> Copies all items from list to array.</p>
<p><em>list.insertElementAt(item,n) </em> Inserts the item at n<em>th</em> position.</p>
<p><strong>Example of working with vectors:</strong></p>
<p>import java.util.*;</p>
<p>class LanguageVector<br />
{<br />
public static void main(String args[])<br />
{<br />
Vector list=new Vector();  //creating an object for vector class<br />
int length=args.length;</p>
<p>for(int i=0;i&lt;length;i++)<br />
{<br />
list.addElement(args[i]);;<br />
list.insertElementAt(&#8220;COBOL&#8221;,2);<br />
int size=list.size();<br />
String listArray[]=new String[size];<br />
list.copyInto(listArray);<br />
System.out.println(&#8220;List of Languages&#8221;);</p>
<p>for(int i=0;i&lt;size;i++)<br />
{<br />
System.out.println(listArray[i]);<br />
}<br />
}<br />
}</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>August 25, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-servletoutputstream/" title="Define ServletOutputStream">Define ServletOutputStream</a> (0)</li><li>September 2, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-session-tracking/" title="Define Session Tracking">Define Session Tracking</a> (0)</li><li>July 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/jsf-important-interview-questions/" title="JSF Important Interview Questions">JSF Important Interview Questions</a> (2)</li><li>July 12, 2010 -- <a href="http://www.bestjavainterviewquestions.com/gui-examples-using-applets/" title="GUI Examples Using Applets">GUI Examples Using Applets</a> (0)</li><li>October 3, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-jsp-directives/" title="Explain Jsp Directives">Explain Jsp Directives</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/write-a-short-notes-on-vectors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA UTIL PACKAGE</title>
		<link>http://www.bestjavainterviewquestions.com/java-util-package-2/</link>
		<comments>http://www.bestjavainterviewquestions.com/java-util-package-2/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 17:34:20 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[JAVA UTIL QUESTIONS]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[HashSet]]></category>
		<category><![CDATA[HashTable]]></category>
		<category><![CDATA[Iterator]]></category>
		<category><![CDATA[javac collections interview questions and answers]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[Tree]]></category>
		<category><![CDATA[Vector]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/java-util-package-2/</guid>
		<description><![CDATA[JAVA COLLECTIONS INTERVIEW QUESTIONS AND ANSWERS 1) Explain Java Collections Framework? A) Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collection of objects. 2) Explain Iterator Interface. A) An Iterator is similar to the Enumeration interface. With the Iterator interface methods, you can traverse a collection [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><strong><span style="color: #ff6969;">JAVA COLLECTIONS INTERVIEW QUESTIONS AND ANSWERS</span></strong></p>
<p><span><span><strong>1) Explain Java Collections Framework? </strong></span></span></p>
<p><span><span>A) Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collection of objects.</span></span></p>
<p><span><span><strong>2) Explain Iterator Interface.</strong></span></span></p>
<p><span><span>A) An Iterator is similar to the Enumeration interface. With the Iterator interface methods, you can traverse a collection from start to end and safely remove elements from the underlying collection. The iterator() method generally used in query operations.<br />
Basic methods:<br />
iterator.remove();<br />
iterator.hasNext();<br />
iterator.next();</span></span></p>
<p><span><span><strong>3) Explain Enumeration Interface?</strong></span></span></p>
<p><span><span>The Enumeration interface allows you to iterate through all the elements of a collection. Iterating through an Enumeration is similar to iterating through an Iterator. However, there is no removal support with Enumeration.<br />
Basic methods:<br />
boolean hasMoreElements();<br />
Object nextElement();</span></span></p>
<p><span><span><strong>4) What is the difference between Enumeration and Iterator interface?</strong></span></span></p>
<p><span><span>The Enumeration interface allows you to iterate through all the elements of a collection. Iterating through an Enumeration is similar to iterating through an Iterator. However, there is no removal support with Enumeration.</span></span></p>
<p><span><span><strong>5) Explain Set Interface.</strong></span></span></p>
<p><span><span>In mathematical concept, a set is just a group of unique items, in the sense that the group contains no duplicates. The Set interface extends the Collection interface. Set does not allow duplicates in the collection. In Set implementations null is valid entry, but allowed only once.</span></span></p>
<p><span><span><strong>6) What are the two types of Set implementations available in the Collections Framework?</strong></span></span></p>
<p><span><span>HashSet and TreeSet are the two Set implementations available in the Collections Framework.</span></span></p>
<p><span><span><strong>7) What is the difference between HashSet and TreeSet?</strong></span></span></p>
<p><span><span>HashSet Class implements java.util.Set interface to eliminate the duplicate entries and uses hashing for storage. Hashing is nothing but mapping between a key value and a data item, this provides efficient searching.</span></span></p>
<p><span><span>The TreeSet Class implements java.util.Set interface provides an ordered set, eliminates duplicate entries and uses tree for storage.</span></span></p>
<p><span><span><strong> <img src='http://www.bestjavainterviewquestions.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> What is a List?</strong></span></span></p>
<p><span><span>List is an ordered and non duplicated collection of objects. The List interface extends the Collection interface.</span></span></p>
<p><span><span><strong>9) What are the two types of List implementations available in the Collections Framework?</strong></span></span></p>
<p><span><span>ArrayList and LinkedList are the two List implementations available in the Collections Framework.</span></span></p>
<p><span><span><strong>10) What is the difference between ArrayList and LinkedList?</strong></span></span></p>
<p><span><span>The ArrayList Class implements java.util.List interface and uses array for storage. An array storage&#8217;s are generally faster but we cannot insert and delete entries in middle of the list. To achieve this kind of addition and deletion requires a new array constructed. You can access any element at randomly.</span></span></p>
<p><span><span>The LinkedList Class implements java.util.List interface and uses linked list for storage. A linked list allow elements to be added, removed from the collection at any location in the container by ordering the elements. With this implementation you can only access the elements in sequentially.</span></span></p>
<p><span><span><strong>11) What collection will you use to implement a queue?</strong><br />
LinkedList</span></span></p>
<p><span><span><strong>12) Explain Map Interface?.</strong></span></span></p>
<p><span><span>A map is a special kind of set with no duplicates. The key values are used to lookup, or index the stored data. The Map interface is not an extension of Collection interface, it has it&#8217;s own hierarchy. Map does not allow duplicates in the collection. In Map implementations null is valid entry, but allowed only once.</span></span></p>
<p><span><span><strong>13) What are the two types of Map implementations available in the Collections Framework?</strong></span></span></p>
<p><span><span>HashMap and TreeMap are two types of Map implementations available in the Collections Framework.</span></span></p>
<p><span><span><strong>14) What is the difference between HashMap and TreeMap?</strong></span></span></p>
<p><span><span>The HashMap Class implements java.util.Map interface and uses hashing for storage. Indirectly Map uses Set functionality so, it does not permit duplicates. The TreeMap Class implements java.util.Map interface and uses tree for storage. It provides the ordered map.</span></span></p>
<p><span><span><strong>15) Explain the functionality of Vector Class?</strong></span></span></p>
<p><span><span>Once array size is set you cannot change size of the array. To deal with this kind of situations we use Vector. Vector grows and shrink it&#8217;s size automatically. Vector allows to store only objects not primitives. To store primitives, convert primitives in to objects using wrapper classes before adding them into Vector. The Vector reallocates and resizes itself automatically.</span></span></p>
<p><span><span><strong>16) What does the following statement convey?</strong></span></span></p>
<p><span><span>Vector vt = new Vector(3, 10);<br />
vt is an instance of Vector class with an initial capacity of 3 and grows in increment of 10 in each relocation</span></span></p>
<p><span><span><strong>17) How do you store a primitive data type within a Vector or other collections class?</strong></span></span></p>
<p><span><span>You need to wrap the primitive data type into one of the wrapper classes found in the java.lang package, like Integer, Float, or Double, as in:<br />
Integer in = new Integer(5);</span></span></p>
<p><span><span><strong>18) What is the difference between Vector and ArrayList?</strong></span></span></p>
<p><span><span>Vector and ArrayList are very similar. Both of them represent a growable array. The main difference is that Vector is synchronized while ArrayList is not.</span></span></p>
<p><span><span><strong>19) What is the difference between Hashtable and HashMap?</strong></span></span></p>
<p><span><span>Both provide key-value access to data. The key differences are :<br />
a. Hashtable is synchronised but HasMap is not synchronised.<br />
b. HashMap permits null values but Hashtable doesn&#8217;t allow null values.<br />
c. iterator in the HashMap is fail-safe while the enumerator for the Hashtable is not fail safe.</span></span></p>
<p><span><span><strong>20) How do I make an array larger?</strong></span></span></p>
<p><span><span>You cannot directly make an array larger. You must make a new (larger) array and copy the original elements into it, usually with System.arraycopy(). If you find yourself frequently doing this, the Vector class does this automatically for you, as long as your arrays are not of primitive data types.</span></span></p>
<p><span><span><strong>21) Which is faster, synchronizing a HashMap or using a Hashtable for thread-safe access?</strong></span></span></p>
<p><span><span>Because a synchronized HashMap requires an extra method call, a Hashtable is faster for synchronized access.</span></span></p>
<p><span><span><strong>22) In which package would you find the interfaces and classes defined in the Java Collection Framework?</strong></span></span></p>
<p><span><span>java.util</span></span></p>
<p><span><span><strong>23) Which method in the System class allows you to copy elements from one array to another?</strong></span></span></p>
<p><span><span>System.arraycopy()</span></span></p>
<p><span><span><strong>24) When using the System.arraycopy() method, What exception is thrown if the destination array is smaller than the source array?</strong></span></span></p>
<p><span><span>ArrayIndexOutofBoundsException</span></span></p>
<p><span><span><strong>25) What is the use of Locale class?</strong></span></span></p>
<p><span><span>The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region</span></span></p>
<p><span><span><strong>26) What is the use of GregorianCalendar class?</strong></span></span></p>
<p><span><span>The GregorianCalendar provides support for traditional Western calendars</span></span></p>
<p><span><span><strong>27) What is the use of SimpleTimeZone class?</strong></span></span></p>
<p><span><span>The SimpleTimeZone class provides support for a Gregorian calendar</span></span></p>
<p><span><span><strong>28) What is the use of ResourceBundle class?</strong></span></span></p>
<p><span><span>The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program&#8217;s appearance to the particular locale in which it is being run.</span></span></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions">Core Java Interview Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li><li>August 17, 2010 -- <a href="http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/" title="Define Hashtable,HashMap and HashSet">Define Hashtable,HashMap and HashSet</a> (1)</li><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/java-util-package-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

