<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Java Interview Questions</title>
	<atom:link href="http://javafaq.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://javafaq.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 18 Jan 2012 17:07:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='javafaq.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Java Interview Questions</title>
		<link>http://javafaq.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://javafaq.wordpress.com/osd.xml" title="Java Interview Questions" />
	<atom:link rel='hub' href='http://javafaq.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Collections</title>
		<link>http://javafaq.wordpress.com/2012/01/18/collections/</link>
		<comments>http://javafaq.wordpress.com/2012/01/18/collections/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 17:05:50 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ArrayList]]></category>
		<category><![CDATA[class that implements]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Collections Framework]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java collections framework]]></category>
		<category><![CDATA[java programmer]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Map]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[Set]]></category>
		<category><![CDATA[unrelated apis]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/?p=53</guid>
		<description><![CDATA[What is Java Collections API? Java Collections framework API is a unified architecture for representing and manipulating collections. The API contains Interfaces, Implementations &#38; Algorithm to help java programmer in everyday programming. In nutshell, this API does 6 things at high level Reduces programming efforts. &#8211; Increases program speed and quality. Allows interoperability among unrelated [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=53&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<ol start="1">
<li><strong>What is Java Collections API?</strong></li>
</ol>
<p>Java Collections framework API is a unified architecture for representing and manipulating collections. The API contains Interfaces, Implementations &amp; Algorithm to help java programmer in everyday programming. In nutshell, this API does 6 things at high level</p>
<ol start="1">
<ul>
<li>Reduces programming efforts. &#8211; Increases program speed and quality.</li>
<li>Allows interoperability among unrelated APIs.</li>
<li>Reduces effort to learn and to use new APIs.</li>
<li>Reduces effort to design new APIs.</li>
<li>Encourages &amp; Fosters software reuse.</li>
</ul>
</ol>
<p>To be specific, There are six collection java interfaces. The most basic interface is Collection. Three interfaces extend Collection: Set, List, and SortedSet. The other two collection interfaces, Map and SortedMap, do not extend Collection, as they represent mappings rather than true collections.</p>
<ol start="2">
<li><strong>What is an Iterator?</strong></li>
</ol>
<p>Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.</p>
<ol start="3">
<li><strong>What is the difference between java.util.Iterator and java.util.ListIterator?</strong></li>
</ol>
<p>Iterator : Enables you to traverse through a collection in the forward direction only, for obtaining or removing elements ListIterator : extends Iterator, and allows bidirectional traversal of list and also allows the modification of elements.</p>
<ol start="4">
<li><strong>What is HashMap and Map? </strong></li>
</ol>
<p>Map is Interface which is part of Java collections framework. This is to store Key Value pair, and Hashmap is class that implements that using hashing technique.</p>
<ol start="5">
<li><strong>Difference between HashMap and HashTable? Compare Hashtable vs HashMap?</strong></li>
</ol>
<p>Both Hashtable &amp; HashMap provide key-value access to data. The Hashtable is one of the original collection classes in Java (also called as legacy classes). HashMap is part of the new Collections Framework, added with Java 2, v1.2. There are several differences between HashMap and Hashtable in Java as listed below</p>
<ol start="5">
<ul>
<li>The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesn’t allow nulls).</li>
<li>HashMap does not guarantee that the order of the map will remain constant over time. But one of HashMap&#8217;s subclasses is LinkedHashMap, so in the event that you&#8217;d want predictable iteration order (which is insertion order by default), you can easily swap out the HashMap for a LinkedHashMap. This wouldn&#8217;t be as easy if you were using Hashtable.</li>
<li>HashMap is non synchronized whereas Hashtable is synchronized.</li>
<li>Iterator in the HashMap is fail-fast while the enumerator for the Hashtable isn&#8217;t. So this could be a design consideration.</li>
</ul>
<li><strong>What does synchronized means in Hashtable context?</strong></li>
</ol>
<p>Synchronized means only one thread can modify a hash table at one point of time. Any thread before performing an update on a hashtable will have to acquire a lock on the object while others will wait for lock to be released.</p>
<ol start="7">
<li><strong>What is fail-fast property?</strong></li>
</ol>
<p>At high level &#8211; Fail-fast is a property of a system or software with respect to its response to failures. A fail-fast system is designed to immediately report any failure or condition that is likely to lead to failure. Fail-fast systems are usually designed to stop normal operation rather than attempt to continue a possibly-flawed process.</p>
<p>When a problem occurs, a fail-fast system fails immediately and visibly. Failing fast is a non-intuitive technique: &#8220;failing immediately and visibly&#8221; sounds like it would make your software more fragile, but it actually makes it more robust. Bugs are easier to find and fix, so fewer go into production.</p>
<p>In Java, Fail-fast term can be related to context of iterators. If an iterator has been created on a collection object and some other thread tries to modify the collection object &#8220;structurally&#8221;, a concurrent modification exception will be thrown. It is possible for other threads though to invoke &#8220;set&#8221; method since it doesn&#8217;t modify the collection &#8220;structurally&#8221;. However, if prior to calling &#8220;set&#8221;, the collection has been modified structurally, &#8220;IllegalArgumentException&#8221; will be thrown.</p>
<ol start="8">
<li><strong>Why doesn&#8217;t Collection extend Cloneable and Serializable?</strong></li>
</ol>
<p>From Sun FAQ Page: Many Collection implementations (including all of the ones provided by the JDK) will have a public clone method, but it would be mistake to require it of all Collections. For example, what does it mean to clone a Collection that&#8217;s backed by a terabyte SQL database? Should the method call cause the company to requisition a new disk farm? Similar arguments hold for serializable. If the client doesn&#8217;t know the actual type of a Collection, it&#8217;s much more flexible and less error prone to have the client decide what type of Collection is desired, create an empty Collection of this type, and use the addAll method to copy the elements of the original collection into the new one. Note on Some Important Terms</p>
<ol start="8">
<ul>
<li>Synchronized means only one thread can modify a hash table at one point of time. Basically, it means that any thread before performing an update on a hashtable will have to acquire a lock on the object while others will wait for lock to be released.</li>
<li>Fail-fast is relevant from the context of iterators. If an iterator has been created on a collection object and some other thread tries to modify the collection object &#8220;structurally”, a concurrent modification exception will be thrown. It is possible for other threads though to invoke &#8220;set&#8221; method since it doesn’t modify the collection &#8220;structurally”. However, if prior to calling &#8220;set&#8221;, the collection has been modified structurally, &#8220;IllegalArgumentException&#8221; will be thrown.</li>
</ul>
<li><strong>How can we make Hashmap synchronized? </strong></li>
</ol>
<p>HashMap can be synchronized by <em>Map m = Collections.synchronizedMap(hashMap);</em></p>
<ol start="10">
<li><strong>Where will you use Hashtable and where will you use HashMap?</strong></li>
</ol>
<p>There are multiple aspects to this decision: 1. The basic difference between a Hashtable and an HashMap is that, Hashtable is synchronized while HashMap is not. Thus whenever there is a possibility of multiple threads accessing the same instance, one should use Hashtable. While if not multiple threads are going to access the same instance then use HashMap. Non synchronized data structure will give better performance than the synchronized one. 2. If there is a possibility in future that &#8211; there can be a scenario when you may require to retain the order of objects in the Collection with key-value pair then HashMap can be a good choice. As one of HashMap&#8217;s subclasses is LinkedHashMap, so in the event that you&#8217;d want predictable iteration order (which is insertion order by default), you can easily swap out the HashMap for a LinkedHashMap. This wouldn&#8217;t be as easy if you were using Hashtable. Also if you have multiple thread accessing you HashMap then Collections.synchronizedMap() method can be leveraged. Overall HashMap gives you more flexibility in terms of possible future changes.</p>
<ol start="11">
<li><strong>Difference between Vector and ArrayList? What is the Vector class? </strong></li>
</ol>
<p>Vector &amp; ArrayList both classes are implemented using dynamically resizable arrays, providing fast random access and fast traversal. ArrayList and Vector class both implement the List interface. Both the classes are member of Java collection framework, therefore from an API perspective, these two classes are very similar. However, there are still some major differences between the two. Below are some key differences</p>
<ol start="11">
<ul>
<li>Vector is a legacy class which has been retrofitted to implement the List interface since Java 2 platform v1.2</li>
<li>Vector is synchronized whereas ArrayList is not. Even though Vector class is synchronized, still when you want programs to run in multithreading environment using ArrayList with Collections.synchronizedList() is recommended over Vector.</li>
<li>ArrayList has no default size while vector has a default size of 10.</li>
<li>The Enumerations returned by Vector&#8217;s elements method are not fail-fast. Whereas ArraayList does not have any method returning Enumerations.</li>
</ul>
<li><strong>What is the Difference between Enumeration and Iterator interface?</strong></li>
</ol>
<p>Enumeration and Iterator are the interface available in java.util package. The functionality of Enumeration interface is duplicated by the Iterator interface. New implementations should consider using Iterator in preference to Enumeration. Iterators differ from enumerations in following ways:</p>
<ol start="12">
<ol start="1">
<li>Enumeration contains 2 methods namely hasMoreElements() &amp; nextElement() whereas Iterator contains three methods namely hasNext(), next(),remove().</li>
<li>Iterator adds an optional remove operation, and has shorter method names. Using remove() we can delete the objects but Enumeration interface does not support this feature.</li>
<li>Enumeration interface is used by legacy classes. Vector.elements() &amp; Hashtable.elements() method returns Enumeration. Iterator is returned by all Java Collections Framework classes. java.util.Collection.iterator() method returns an instance of Iterator.</li>
</ol>
<li><strong>Why Java Vector class is considered obsolete or unofficially deprecated? or Why should I always use ArrayList over Vector?</strong></li>
</ol>
<p>You should use ArrayList over Vector because you should default to non-synchronized access. Vector synchronizes each individual method. That&#8217;s almost never what you want to do. Generally you want to synchronize a whole sequence of operations. Synchronizing individual operations is both less safe (if you iterate over a Vector, for instance, you still need to take out a lock to avoid anyone else changing the collection at the same time) but also slower (why take out a lock repeatedly when once will be enough)?</p>
<p>Of course, it also has the overhead of locking even when you don&#8217;t need to. It&#8217;s a very flawed approach to have synchronized access as default. You can always decorate a collection using Collections.synchronizedList &#8211; the fact that Vector combines both the &#8220;resized array&#8221; collection implementation with the &#8220;synchronize every operation&#8221; bit is another example of poor design; the decoration approach gives cleaner separation of concerns.</p>
<p>Vector also has a few legacy methods around enumeration and element retrieval which are different than the List interface, and developers (especially those who learned Java before 1.2) can tend to use them if they are in the code. Although Enumerations are faster, they don&#8217;t check if the collection was modified during iteration, which can cause issues, and given that Vector might be chosen for its syncronization &#8211; with the attendant access from multiple threads, this makes it a particularly pernicious problem. Usage of these methods also couples a lot of code to Vector, such that it won&#8217;t be easy to replace it with a different List implementation.</p>
<p>Despite all above reasons Sun may never officially deprecate Vector class. (Read details <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6201870">Deprecate Hashtable and Vector</a>)</p>
<ol start="14">
<li><strong>What is an enumeration?</strong></li>
</ol>
<p>An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It is a construct which collection classes return when you request a collection of all the objects stored in the collection. It allows sequential access to all the elements stored in the collection.</p>
<ol start="15">
<li><strong>What is the difference between Enumeration and Iterator?</strong></li>
</ol>
<p>The functionality of Enumeration interface is duplicated by the Iterator interface. Iterator has a remove() method while Enumeration doesn&#8217;t. Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects, where as using Iterator we can manipulate the objects also like adding and removing the objects. So Enumeration is used when ever we want to make Collection objects as Read-only.</p>
<ol start="16">
<li><strong>Where will you use Vector and where will you use ArrayList?</strong></li>
</ol>
<p>The basic difference between a Vector and an ArrayList is that, vector is synchronized while ArrayList is not. Thus whenever there is a possibility of multiple threads accessing the same instance, one should use Vector. While if not multiple threads are going to access the same instance then use ArrayList. Non synchronized data structure will give better performance than the synchronized one.</p>
<ol start="17">
<li><strong>What is the importance of hashCode() and equals() methods? How they are used in Java?</strong></li>
</ol>
<p>The java.lang.Object has two methods defined in it. They are &#8211; public boolean equals(Object obj) public int hashCode(). These two methods are used heavily when objects are stored in collections.</p>
<p>There is a contract between these two methods which should be kept in mind while overriding any of these methods.</p>
<p>The Java API documentation describes it in detail. The hashCode() method returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable or java.util.HashMap. The general contract of hashCode is:</p>
<p>Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. The equals(Object obj) method indicates whether some other object is &#8220;equal to&#8221; this one. The equals method implements an equivalence relation on non-null object references:</p>
<p>It is reflexive: for any non-null reference value x, x.equals(x) should return true.</p>
<p>It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.</p>
<p>It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.</p>
<p>It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified. For any non-null reference value x, x.equals(null) should return false. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).</p>
<p>Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.</p>
<p><strong>A practical Example of hashcode() &amp; equals(): </strong>This can be applied to classes that need to be stored in Set collections. Sets use equals() to enforce non-duplicates, and HashSet uses hashCode() as a first-cut test for equality. Technically hashCode() isn&#8217;t necessary then since equals() will always be used in the end, but providing a meaningful hashCode() will improve performance for very large sets or objects that take a long time to compare using equals().</p>
<ol start="18">
<li><strong>What is the difference between Sorting performance of Arrays.sort() vs Collections.sort() ? Which one is faster? Which one to use and when?</strong></li>
</ol>
<p>Many developers are concerned about the performance difference between java.util.Array.sort() java.util.Collections.sort() methods. Both methods have same algorithm the only difference is type of input to them. Collections.sort() has a input as List so it does a translation of List to array and vice versa which is an additional step while sorting. So this should be used when you are trying to sort a list. Arrays.sort is for arrays so the sorting is done directly on the array. So clearly it should be used when you have a array available with you and you want to sort it.</p>
<ol start="19">
<li><strong>What is java.util.concurrent BlockingQueue? How it can be used?</strong></li>
</ol>
<p>Java has implementation of BlockingQueue available since Java 1.5. Blocking Queue interface extends collection interface, which provides you power of collections inside a queue. Blocking Queue is a type of Queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element. A typical usage example would be based on a producer-consumer scenario. Note that a BlockingQueue can safely be used with multiple producers and multiple consumers. An ArrayBlockingQueue is a implementation of blocking queue with an array used to store the queued objects. The head of the queue is that element that has been on the queue the longest time. The tail of the queue is that element that has been on the queue the shortest time. New elements are inserted at the tail of the queue, and the queue retrieval operations obtain elements at the head of the queue. ArrayBlockingQueue requires you to specify the capacity of queue at the object construction time itself. Once created, the capacity cannot be increased. This is a classic &#8220;bounded buffer&#8221; (fixed size buffer), in which a fixed-sized array holds elements inserted by producers and extracted by consumers. Attempts to put an element to a full queue will result in the put operation blocking; attempts to retrieve an element from an empty queue will be blocked.</p>
<ol start="20">
<li><strong>Set &amp; List interface extend Collection, so Why doesn&#8217;t Map interface extend Collection?</strong></li>
</ol>
<p>Though the Map interface is part of collections framework, it does not extend collection interface. This is by design, and the answer to this questions is best described in Sun&#8217;s FAQ Page: This was by design. We feel that mappings are not collections and collections are not mappings. Thus, it makes little sense for Map to extend the Collection interface (or vice versa). If a Map is a Collection, what are the elements? The only reasonable answer is &#8220;Key-value pairs&#8221;, but this provides a very limited (and not particularly useful) Map abstraction. You can&#8217;t ask what value a given key maps to, nor can you delete the entry for a given key without knowing what value it maps to. Collection could be made to extend Map, but this raises the question: what are the keys? There&#8217;s no really satisfactory answer, and forcing one leads to an unnatural interface. Maps can be viewed as Collections (of keys, values, or pairs), and this fact is reflected in the three &#8220;Collection view operations&#8221; on Maps (keySet, entrySet, and values). While it is, in principle, possible to view a List as a Map mapping indices to elements, this has the nasty property that deleting an element from the List changes the Key associated with every element before the deleted element. That&#8217;s why we don&#8217;t have a map view operation on Lists.</p>
<ol start="21">
<li><strong>Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list? </strong></li>
</ol>
<p>a. Vector b. ArrayList c. LinkedList ArrayList and Vector both use an array to store the elements of the list. When an element is inserted into the middle of the list the elements that follow the insertion point must be shifted to make room for the new element. The LinkedList is implemented using a doubly linked list; an insertion requires only the updating of the links at the point of insertion. Therefore, the LinkedList allows for fast insertions and deletions.</p>
<ol start="22">
<li><strong>What is the difference between ArrayList and LinkedList? (ArrayList vs LinkedList.)</strong><strong> </strong></li>
</ol>
<p>java.util.ArrayList and java.util.LinkedList are two Collections classes used for storing lists of object references <strong>Here are some key differences:</strong></p>
<ol start="22">
<ul>
<li>ArrayList uses primitive object array for storing objects whereas LinkedList is made up of a chain of nodes. Each node stores an element and the pointer to the next node. A singly linked list only has pointers to next. A doubly linked list has a pointer to the next and the previous element. This makes walking the list backward easier.</li>
<li>ArrayList implements the RandomAccess interface, and LinkedList does not. The commonly used ArrayList implementation uses primitive Object array for internal storage. Therefore an ArrayList is much faster than a LinkedList for random access, that is, when accessing arbitrary list elements using the get method. Note that the get method is implemented for LinkedLists, but it requires a sequential scan from the front or back of the list. This scan is very slow. For a LinkedList, there&#8217;s no fast way to access the Nth element of the list.</li>
<li>Adding and deleting at the start and middle of the ArrayList is slow, because all the later elements have to be copied forward or backward. (Using System.arrayCopy()) Whereas Linked lists are faster for inserts and deletes anywhere in the list, since all you do is update a few next and previous pointers of a node.</li>
<li>Each element of a linked list (especially a doubly linked list) uses a bit more memory than its equivalent in array list, due to the need for next and previous pointers.</li>
<li>ArrayList may also have a performance issue when the internal array fills up. The arrayList has to create a new array and copy all the elements there. The ArrayList has a growth algorithm of (n*3)/2+1, meaning that each time the buffer is too small it will create a new one of size (n*3)/2+1 where n is the number of elements of the current buffer. Hence if we can guess the number of elements that we are going to have, then it makes sense to create a arraylist with that capacity during object creation (using construtor new ArrayList(capacity)). Whereas LinkedLists should not have such capacity issues.</li>
</ul>
<li><strong>Where will you use ArrayList and Where will you use LinkedList? Or Which one to use when (ArrayList / LinkedList).</strong></li>
</ol>
<p>Below is a snippet from SUN&#8217;s site. The Java SDK contains 2 implementations of the List interface &#8211; ArrayList and LinkedList. If you frequently add elements to the beginning of the List or iterate over the List to delete elements from its interior, you should consider using LinkedList. These operations require constant-time in a LinkedList and linear-time in an ArrayList. But you pay a big price in performance. Positional access requires linear-time in a LinkedList and constant-time in an ArrayList.</p>
<ol start="24">
<li><strong>What is performance of various Java collection implementations/algorithms? What is Big &#8216;O&#8217; notation for each of them ?</strong></li>
</ol>
<p>Each java collection implementation class have different performance for different methods, which makes them suitable for different programming needs.</p>
<div>
<ol start="24">
<ul>
<li><strong>Performance of Map interface implementations</strong></li>
</ul>
</ol>
</div>
<div>
<p><strong>Hashtable</strong></p>
</div>
<p>An instance of Hashtable has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. Note that the hash table is open: in the case of a &#8220;hash collision&#8221;, a single bucket stores multiple entries, which must be searched sequentially. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. The initial capacity and load factor parameters are merely hints to the implementation. The exact details as to when and whether the rehash method is invoked are implementation-dependent.</p>
<div>
<p><strong>HashMap </strong></p>
</div>
<p>This implementation provides constant-time [ Big O Notation is O(1) ] performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets.<br />
Iteration over collection views requires time proportional to the &#8220;capacity&#8221; of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it&#8217;s very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.</p>
<div>
<p><strong>TreeMap</strong></p>
</div>
<p>The TreeMap implementation provides guaranteed log(n) [ Big O Notation is O(log N) ] time cost for the containsKey, get, put and remove operations.</p>
<div>
<p><strong>LinkedHashMap</strong></p>
</div>
<p>A linked hash map has two parameters that affect its performance: initial capacity and load factor. They are defined precisely as for HashMap. Note, however, that the penalty for choosing an excessively high value for initial capacity is less severe for this class than for HashMap, as iteration times for this class are unaffected by capacity.</p>
<div>
<ol start="24">
<ul>
<li><strong>Performance of Set interface implementations</strong></li>
</ul>
</ol>
</div>
<div>
<p><strong>HashSet</strong></p>
</div>
<p>The HashSet class offers constant-time [ Big O Notation is O(1) ] performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets. Iterating over this set requires time proportional to the sum of the HashSet instance&#8217;s size (the number of elements) plus the &#8220;capacity&#8221; of the backing HashMap instance (the number of buckets). Thus, it&#8217;s very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.</p>
<div>
<p><strong>TreeSet</strong></p>
</div>
<p>The TreeSet implementation provides guaranteed log(n) time cost for the basic operations (add, remove and contains).</p>
<div>
<p><strong>LinkedHashSet</strong></p>
</div>
<p>A linked hash set has two parameters that affect its performance: initial capacity and load factor. They are defined precisely as for HashSet. Note, however, that the penalty for choosing an excessively high value for initial capacity is less severe for this class than for HashSet, as iteration times for this class are unaffected by capacity.</p>
<div>
<ol start="24">
<ul>
<li><strong>Performance of List interface implementations</strong></li>
</ul>
</ol>
</div>
<div>
<p><strong>LinkedList</strong></p>
</div>
<p>- Performance of get and remove methods is linear time [ Big O Notation is O(n) ] &#8211; Performance of add and Iterator.remove methods is constant-time [ Big O Notation is O(1) ]</p>
<div>
<p><strong>ArrayList</strong></p>
</div>
<p>- The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. [ Big O Notation is O(1) ]<br />
- The add operation runs in amortized constant time [ Big O Notation is O(1) ] , but in worst case (since the array must be resized and copied) adding n elements requires linear time [ Big O Notation is O(n) ]<br />
- Performance of remove method is linear time [ Big O Notation is O(n) ]<br />
- All of the other operations run in linear time [ Big O Notation is O(n) ]. The constant factor is low compared to that for the LinkedList implementation.</p>
<p>Can you think of a questions which is not part of this post? Please don&#8217;t forget to share it with me in comments section &amp; I will try to include it in the list.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=53&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2012/01/18/collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>Difference between web server and application server?</title>
		<link>http://javafaq.wordpress.com/2010/02/13/difference-between-web-server-and-application-server/</link>
		<comments>http://javafaq.wordpress.com/2010/02/13/difference-between-web-server-and-application-server/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 04:05:22 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Java Interview Questions]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/2010/02/13/difference-between-web-server-and-application-server/</guid>
		<description><![CDATA[A Web server serves pages for viewing in a Web browser, while an application server provides methods that client applications can call. The Web server A Web server handles the HTTP protocol. When the Web server receives an HTTP request, it responds with an HTTP response, such as sending back an HTML page. To process [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=44&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">A Web server serves pages for viewing in a Web browser, while an application server provides methods that client applications can call.</div>
<div id="_mcePaste"></div>
<div><strong>The Web server</strong></div>
<div id="_mcePaste"></div>
<div>A Web server handles the HTTP protocol. When the Web server receives an HTTP request, it responds with an HTTP response, such as sending back an HTML page. To process a request, a Web server may respond with a static HTML page or image, send a redirect, or delegate the dynamic response generation to some other program such as CGI scripts, JSPs (JavaServer Pages), servlets, ASPs (Active Server Pages), server-side JavaScripts, or some other server-side technology. Whatever their purpose, such server-side programs generate a response, most often in HTML, for viewing in a Web browser.</div>
<div id="_mcePaste"></div>
<div><strong>The application server</strong></div>
<div></div>
<div id="_mcePaste">As for the application server, according to our definition, an application server exposes business logic to client applications through various protocols, possibly including HTTP. While a Web server mainly deals with sending HTML for display in a Web browser, an application server provides access to business logic for use by client application programs. The application program can use this logic just as it would call a method on an object (or a function in the procedural world).</div>
<div id="_mcePaste">Webserver is used only for jsp and servlets and for static functionality it has limited functionality and it doesn&#8217;t provide any security persistence and it doesn&#8217;t support EJB and JMS and JAAS like other functionality whereas Application server provide all functionalities</div>
<div id="_mcePaste"></div>
<div>In simple words, Application Server = Web Server + EJB Container</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=44&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2010/02/13/difference-between-web-server-and-application-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>Why can&#8217;t we make jsp as a controller and action servlet in struts?</title>
		<link>http://javafaq.wordpress.com/2010/02/13/why-cant-we-make-jsp-as-a-controller-and-action-servlet-in-struts/</link>
		<comments>http://javafaq.wordpress.com/2010/02/13/why-cant-we-make-jsp-as-a-controller-and-action-servlet-in-struts/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 03:09:53 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/?p=39</guid>
		<description><![CDATA[When JSP compiles, internally the jsp compiler converts it to  servlets and compiles servlets java file and generartes the class file. Every time it will do the same thing, so it may take several time. It may cause performance issue. Most of the applications are created in MVC design pattern to seperate the functions of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=39&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When JSP compiles, internally the jsp compiler converts it to  servlets and compiles servlets java file and generartes the  class file. Every time it will do the same thing, so it may  take several time. It may cause performance issue.</p>
<p>Most of the applications are created in MVC design pattern to seperate the functions of differnetcomponents and handle the complexity of applications. JSP and Servlets are the server sidecomponents which can respond to the client request.</p>
<p>Servlets are the basic components for request handling in Web Server. They contains pure Java code. Everything that needs to be done to generate the proper user response (which is genarally HTML code) needs to be done through coding. As a single servlet cannot respond each and every request by itself as client request varies in type (e.g. enquiry, update request, add etc) the request and response object is passed onto different servlets with little task completed by each servlet. This controlling part is easier to write in java. So Servlet is used as controller.</p>
<p>JSP is again a servlet which has syntax more like to HTML with java support. Whatever user is going to see as result of his request is HTML. Programmer can easily write html tags inside JSP to render html. This is very economical to change also. So all this code is written JSP which is (generally) the final link in Servlet chaining.</p>
<p><strong>In simple words, Controller (servlet) has pure Java code while View (JSP) has HTML code.</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=39&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2010/02/13/why-cant-we-make-jsp-as-a-controller-and-action-servlet-in-struts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>why string is immutable ?</title>
		<link>http://javafaq.wordpress.com/2010/02/13/why-string-is-immutable/</link>
		<comments>http://javafaq.wordpress.com/2010/02/13/why-string-is-immutable/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 03:00:36 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Java Interview Questions]]></category>
		<category><![CDATA[Immutable]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JVM]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/?p=36</guid>
		<description><![CDATA[In java, Strings are handling in Pool format. For example: String str1 = “xyz”; This string(str1) will be stored into memory in particular address. When we defining new String with same array of characters like String str2 = “xyz”; Now JVM will check in String Pool where there is same characters are available or not. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=36&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In java, Strings are handling in Pool format.</p>
<p>For example:</p>
<p>String str1 = “xyz”;</p>
<p>This string(str1) will be stored into memory in particular address. When we defining new String with same array of characters like</p>
<p>String str2 = “xyz”;</p>
<p>Now JVM will check in String Pool where there is same characters are available or not. If two Strings are match the JVM will refer str1 address to str2. Now the str1 and str2 referring the same characters in same memory location. This is a good idea for increasing memory efficiency.</p>
<p>When we change the str1 characters, the changes will be reflected to str2. Because both str1 and str2 variables are referring the same memory location. For avoiding this we are keeping String as immutable. However we can use StringBuffer if you want to do modifications in the string.</p>
<p>Making String immutable, makes it thread safe and thus imporves performance.</p>
<p>Once a string object is created no changes can be made to it. If a string is modified in code a new object will be</p>
<p>created. That is why string is immutable.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=36&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2010/02/13/why-string-is-immutable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>What is the Difference between jar, ear and war?</title>
		<link>http://javafaq.wordpress.com/2010/02/09/what-is-the-difference-between-jar-ear-and-war/</link>
		<comments>http://javafaq.wordpress.com/2010/02/09/what-is-the-difference-between-jar-ear-and-war/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 15:21:28 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Java Interview Questions]]></category>
		<category><![CDATA[EAR]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JAR]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[WAR]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/?p=33</guid>
		<description><![CDATA[.jar files: These files are with the .jar extension. The .jar files contain the libraries, resources and accessories files like property files. .war files: These files are with the .war extension. The war file contains the web application that can be deployed on the any servlet/jsp container. The .war file contains jsp, html, java script and other [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=33&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>.jar files:</strong> These files are with the .jar extension. The .jar files contain the libraries, resources and accessories files like property files.</p>
<p><strong>.war files:</strong> These files are with the .war extension. The war file contains the web application that can be deployed on the any servlet/jsp container. The .war file contains jsp, html, java script and other files for necessary for the development of web applications.</p>
<p><strong>.ear files:</strong> WAR(Web module) + JAR(can be EJB module or application client module). An EAR(Enterprise archive) is a top-level container which contains modules like: EJB modules, web modules, application client modules etc.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=33&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2010/02/09/what-is-the-difference-between-jar-ear-and-war/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>What&#8217;s the difference between &#8220;JDK&#8221; and &#8220;JRE&#8221;?</title>
		<link>http://javafaq.wordpress.com/2010/01/12/whats-the-difference-between-jdk-and-jre/</link>
		<comments>http://javafaq.wordpress.com/2010/01/12/whats-the-difference-between-jdk-and-jre/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 07:56:13 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Difference between JDK]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JDK]]></category>
		<category><![CDATA[JRE]]></category>
		<category><![CDATA[JRE and JVM]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/?p=27</guid>
		<description><![CDATA[The &#8220;JDK&#8221; is the Java Development Kit.the JDK is bundle of software that you can use to develop Java based software. The &#8220;JRE&#8221; is the Java Runtime Environment.the JRE is an implementation of the Java Virtual Machine which actually executes Java programs. Each JDK contains one (or more) JRE&#8217;s along with the various development tools [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=27&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The &#8220;JDK&#8221; is the <em>Java Development Kit</em>.the JDK is bundle of software that you can use to develop Java based software. The &#8220;JRE&#8221; is the <em>Java Runtime Environment</em>.the JRE is an implementation of the Java Virtual Machine which actually executes Java programs.</p>
<p>Each JDK contains one (or more) JRE&#8217;s along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.</p>
<p>JRE is a subset of JDK.</p>
<ul>
<li>Two      steps for a java program ie.,compile and interpret.</li>
</ul>
<ul>
<li>JDK      does compilation but JRE can&#8217;t.</li>
</ul>
<ul>
<li>Both      JRE and JDK does interpretaion.</li>
</ul>
<p><strong>JVM</strong> :</p>
<p>The use of the JVM : &#8211; To convert the byte code into the machine specific code. So the JVM converts the byte code(ie the code which we get when we compile the .java class) into the code that your machine/OS understands. JVM is machine specific. So JVM for windows will be different from JVM for Mac or Unix. JVM is one of the most crucial part in the java engine. It is due to JVM only that we say java code is <strong>&#8220;Compile Once, Run Anywhere&#8221;</strong> programming language.</p>
<p>The byte code generated when we compile the code will be the same doesn&#8217;t matter we compiled the code in Windows OS or some other. However JVM makes sure that the byte code should be interpreted properly in the OS under concerned so interpret the byte code differently for different OS.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=27&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2010/01/12/whats-the-difference-between-jdk-and-jre/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>RSA7 and Local WebSphere Test Environment Performance Tips</title>
		<link>http://javafaq.wordpress.com/2010/01/11/rsa7-and-local-websphere-test-environment-performance-tips/</link>
		<comments>http://javafaq.wordpress.com/2010/01/11/rsa7-and-local-websphere-test-environment-performance-tips/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 08:09:43 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[RAD & Websphere]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[RAD 7]]></category>
		<category><![CDATA[WebSphere]]></category>
		<category><![CDATA[WSAD]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/2010/01/11/rsa7-and-local-websphere-test-environment-performance-tips/</guid>
		<description><![CDATA[If you&#8217;re encountering slowness in either your RSA IDE or in the embedded WebSphere Test Environment, here several strategies that may help:   RSA7 Performance In c:\Program Files\IBM\SDP70\jdk\bin run this: “java -Xshareclasses:destroyAll”.  This will delete a cache file in C:\Documents and Settings\&#60;username&#62;\Local Settings\Application Data\javasharedresources. Run “C:\Program Files\IBM\SDP70&#62;eclipse –clean”  This is supposed to clean up some other [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=26&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>If you&#8217;re encountering slowness in either your RSA IDE or in the embedded WebSphere Test Environment, here several strategies that may help:</div>
<div> </div>
<div><strong>RSA7 Performance</strong></div>
<ul>
<li>In c:\Program Files\IBM\SDP70\jdk\bin run this: “java -Xshareclasses:destroyAll”.  This will delete a cache file in C:\Documents and Settings\&lt;username&gt;\Local Settings\Application Data\javasharedresources.</li>
<li>Run “C:\Program Files\IBM\SDP70&gt;eclipse –clean”  This is supposed to clean up some other cached data.</li>
<li>Edit eclipse.ini (C:\Program Files\IBM\SDP70\eclipse.ini) to change the “-Xshareclasses:singleJVM,keep” line to “-Xshareclasses:none”</li>
<li>Edit eclipse.ini to have larger max heap (e.g. 768m), and set min heap equal to max.</li>
<li>Try increasing the MaxPermSize in eclipse.ini (e.g. 512M).</li>
<li>Update RSA7 to the latest fixpack.</li>
<li>Try disabling automatic build; use Ctrl-B instead.</li>
<li>If using JIBX, try removing the JIBX compiler from the  builder list and running manually when needed.</li>
<li>Try disabling the “AOP Reference Model Builder” builder if you&#8217;re using Spring IDE. </li>
</ul>
<div><strong>WAS 6.1 Test Environment Performance</strong></div>
<ul>
<li>Update the WAS test env to the latest fixpack.</li>
<li>Verify that automatic publishing is turned off.</li>
<li>Restart applications via the “Restart” menu option instead of the “Publish” option on the application server.</li>
<li>Set the min / max heap for WAS JVM to same size and larger, like 768 or 1024</li>
</ul>
<div><strong>Both</strong></div>
<ul>
<li>Be aware that virus scan real time protection on most computers will significantly degrade disk IO.   Also be especially careful that no scheduled scan is currently running.</li>
<li>Also beware that laptops running PointSec full disk encryption can expect at least a 50% degradation in disk IO performance vs. a non-encrypted file system.</li>
<li>If you have at least 3GB of memory, try reducing paging file size to very low to minimize paging.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=26&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2010/01/11/rsa7-and-local-websphere-test-environment-performance-tips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>Servlet</title>
		<link>http://javafaq.wordpress.com/2010/01/04/servlet/</link>
		<comments>http://javafaq.wordpress.com/2010/01/04/servlet/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 11:29:21 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Java Interview Questions]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/?p=23</guid>
		<description><![CDATA[What is the difference between GenericServlet and HttpServlet? Ans: &#8211; GenericServlet is for servlets that might not use HTTP, like for instance FTP servlets. Of course, it turns out that there&#8217;s no such thing as FTP servlets, but they were trying to plan for future growth when they designed the spec. Maybe some day there [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=23&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;"><strong>What is the difference between GenericServlet and HttpServlet?</strong></span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;"><strong>Ans: &#8211; </strong></span><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">GenericServlet is for servlets that might not use HTTP, like for instance FTP servlets. Of course, it turns out that there&#8217;s no such thing as FTP servlets, but they were trying to plan for future growth when they designed the spec. Maybe some day there will be another subclass, but for now, always use HttpServlet. </span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">In short GenericServlet is protocol independent, whereas HttpServlet is protocol  dependent </span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">In GenericServlets you cannot use Cookies or HttpSession.Session tracking is not possible, redirection is not possible.</span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">Http servlets overrides doGet and doPost methods. Generic servlet overides service method.</span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">1.generic servlet is superclass for HttpServlet. </span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">2.httpservlet class can also have service() method.it&#8217;s not necessary that you can only have doGet() and doPost() method defined. </span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">3.Generic servlet is used for small data transfer whereas HttpServlet is used for huge data transfer.</span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">GenericServlet is might not used be for the http services and may be used for the FTP services , and it is protocol independant where as HttpServlet is Protocol dependant.HttpServlet is subclass to GenericServlet. GenericServlet extends java.lang.Object and implements servlet ,ServletConfig , Serializable interface.</span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;"><br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=23&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2010/01/04/servlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>Core Java Interview Questions</title>
		<link>http://javafaq.wordpress.com/2009/01/04/hello-world/</link>
		<comments>http://javafaq.wordpress.com/2009/01/04/hello-world/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 04:53:11 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Interview questions]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[Servlets]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Swing]]></category>
		<category><![CDATA[Threads]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This site is developed for all IT people who work in the field of Java. This site covers all Core Java, J2EE and Sql’s Frequently Asked Questions that are asked in most technical interviews. Core Java Interview Questions: What is a class? A class is a blueprint, or prototype, that defines the variables and the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=1&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span style="font-family:Verdana;">This site is developed for all IT people who work in the field of Java.</span></p>
<p class="MsoNormal"><span style="font-family:Verdana;">This site covers all Core Java, J2EE and Sql’s Frequently Asked Questions that are asked in most technical interviews.</span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;">Core Java Interview Questions:</span></strong></p>
<ol>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a class?</span></strong><span style="font-family:Verdana;"> A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is an object? </span></strong><span style="font-family:Verdana;">An object is a software bundle of variables and related methods. An instance of a class depicting the state and behavior at that particular time in real world. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a method? </span></strong><span style="font-family:Verdana;">Encapsulation of a functionality which can be called to perform specific tasks. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is encapsulation? Explain with an example.</span></strong><span style="font-family:Verdana;"> Encapsulation is the term given to the process of hiding the implementation details of the object. Once an object is encapsulated, its implementation details are not immediately accessible any more. Instead they are packaged and are only indirectly accessible via the interface of the object </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is inheritance? Explain with an example.</span></strong><span style="font-family:Verdana;"> Inheritance in object oriented programming means that a class of objects can inherit properties and methods from another class of objects. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is polymorphism? Explain with an example. </span></strong><span style="font-family:Verdana;">In object-oriented programming, polymorphism refers to a programming language’s ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Is multiple inheritances allowed in Java? </span></strong><span style="font-family:Verdana;">No, multiple inheritance is not allowed in Java. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is interpreter and compiler? </span></strong><span style="font-family:Verdana;">Java interpreter converts the high level language code into a intermediate form in Java called as byte code, and then executes it, where as a compiler converts the high level language code to machine language making it very hardware specific </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is JVM?</span></strong><span style="font-family:Verdana;"> The Java interpreter along with the runtime environment required to run the Java application in called as Java virtual machine(JVM) </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the different types of modifiers? </span></strong><span style="font-family:Verdana;">There are access modifiers and there are other identifiers. Access modifiers are public, protected and private. Other is final and static. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the access modifiers in Java? </span></strong><span style="font-family:Verdana;">There are 3 access modifiers. Public, protected and private, and the default one if no identifier is specified is called friendly, but programmer cannot specify the friendly identifier explicitly. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a wrapper class?</span></strong><span style="font-family:Verdana;"> They are classes that wrap a primitive data type so it can be used as a object </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a static variable and static method? What’s the difference between two?</span></strong><span style="font-family:Verdana;"> The modifier static can be used with a variable and method. When declared as static variable, there is only one variable no matter how instances are created, this variable is initialized when the class is loaded. Static method do not need a class to be instantiated to be called, also a non static method cannot be called from static method. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is garbage collection?</span></strong><span style="font-family:Verdana;"> Garbage Collection is a thread that runs to reclaim the memory by destroying the objects that cannot be referenced anymore. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is abstract class?</span></strong><span style="font-family:Verdana;"> Abstract class is a class that needs to be extended and its methods implemented, aclass has to be declared abstract if it has one or more abstract methods. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is meant by final class, methods and variables? </span></strong><span style="font-family:Verdana;">This modifier can be applied to class method and variable. When declared as final class the class cannot be extended. When declared as final variable, its value cannot be changed if is primitive value, if it is a reference to the object it will always refer to the same object, internal attributes of the object can be changed. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is interface?</span></strong><span style="font-family:Verdana;"> Interface is a contact that can be implemented by a class, it has method that need implementation. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is method overloading?</span></strong><span style="font-family:Verdana;"> Overloading is declaring multiple method with the same name, but with different argument list. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is method overriding?</span></strong><span style="font-family:Verdana;"> Overriding has same method name, identical arguments used in subclass. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is singleton class?</span></strong><span style="font-family:Verdana;"> Singleton class means that any given time only one instance of the class is present, in one JVM. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between an array and a vector?</span></strong><span style="font-family:Verdana;"> Number of elements in an array are fixed at the construction time, whereas the number of elements in vector can grow dynamically. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a constructor?</span></strong><span style="font-family:Verdana;"> In Java, the class designer can guarantee initialization of every object by providing a special method called a constructor. If a class has a constructor, Java automatically calls that constructor when an object is created, before users can even get their hands on it. So initialization is guaranteed. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is casting?</span></strong><span style="font-family:Verdana;"> Conversion of one type of data to another when appropriate. Casting makes explicitly converting of data. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between final, finally and finalize?</span></strong><span style="font-family:Verdana;"> The modifier final is used on class variable and methods to specify certain behavior explained above. And finally is used as one of the loop in the try catch blocks, It is used to hold code that needs to be executed whether or not the exception occurs in the try catch block. Java provides a method called finalize( ) that can be defined in the class. When the garbage collector is ready to release the storage ed for your object, it will first call finalize( ), and only on the next garbage-collection pass will it reclaim the objects memory. So finalize( ), gives you the ability to perform some important cleanup at the time of garbage collection. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are are packages?</span></strong><span style="font-family:Verdana;"> A package is a collection of related classes and interfaces providing access protection and namespace management. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a super class and how can you call a super class?</span></strong><span style="font-family:Verdana;"> When a class is extended that is derived from another class there is a relationship is created, the parent class is referred to as the super class by the derived class that is the child. The derived class can make a call to the super class using the keyword super. If used in the constructor of the derived class it has to be the first statement. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is meant by a Thread?</span></strong><span style="font-family:Verdana;"> Thread is defined as an instantiated parallel process of a given program. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is multi-threading?</span></strong><span style="font-family:Verdana;"> Multi-threading as the name suggest is the scenario where more than one threads are running. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are two ways of creating a thread? Which is the best way and why?</span></strong><span style="font-family:Verdana;"> Two ways of creating threads are, one can extend from the Java.lang.Thread and can implement the rum method or the run method of a different class can be called which implements the interface Runnable, and the then implement the run() method. The latter one is mostly used as first due to Java rule of only one class inheritance, with implementing the Runnable interface that problem is sorted out. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is deadlock?</span></strong><span style="font-family:Verdana;"> Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread. In Java, this resource is usually the object lock obtained by the synchronized keyword. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the three types of priority?</span></strong><span style="font-family:Verdana;"> MAX_PRIORITY which is 10, MIN_PRIORITY which is 1, NORM_PRIORITY which is 5. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the use of synchronizations?</span></strong><span style="font-family:Verdana;"> Every object has a lock, when a synchronized keyword is used on a piece of code the, lock must be obtained by the thread first to execute that code, other threads will not be allowed to execute that piece of code till this lock is released. </span></li>
</ol>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"> </span></strong></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;">33. How could Java classes direct program messages to the system console, but error messages, say to a file?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal" style="margin-bottom:12pt;"><span style="font-family:Verdana;"><br />
A. The class System has a variable <em>out</em> that represents the standard output, and the variable <em>err</em> that represent the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:</span></p>
<p class="MsoNormal"><span class="code"><span style="font-family:Verdana;">Stream st = new Stream(new FileOutputStream(&#8220;output.txt&#8221;)); System.setErr(st); System.setOut(st);</span></span><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
34. What&#8217;s the difference between an interface and an abstract class?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
35. Why would you use a synchronized block vs. synchronized method?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Synchronized blocks place locks for shorter periods than synchronized methods.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
36<strong><span style="font-family:Verdana;">. Explain the usage of the keyword transient?</span></strong></span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).</span></p>
<p><strong>37. How can you force garbage collection?</strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. You can&#8217;t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
38. How do you know if an explicit object casting is needed?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal" style="margin-bottom:12pt;"><span style="font-family:Verdana;"><br />
A. If you assign a super class object to a variable of a subclass&#8217;s data type, you need to do explicit casting. For example:</span></p>
<p class="MsoNormal"><span style="font-family:Verdana;">Object a; Customer b; b = (Customer) a;</span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
When you assign a subclass to a variable having a sup class type, the casting is performed automatically. </span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
39. What&#8217;s the difference between the methods sleep() and wait()</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. The code <span class="code">sleep(1000); </span>puts thread aside for exactly one second. The code <span class="code">wait(1000), </span>causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
40. Can you write a Java class that could be used both as an applet as well as an application?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Yes. Add a main() method to the applet.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
41. What&#8217;s the difference between constructors and other methods?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
42. Can you call one constructor from another if a class has multiple constructors?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Yes. Use this() syntax.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
43. Explain the usage of Java packages.</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
44. If a class is located in a package, what do you need to change in the OS environment to be able to use it?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal" style="margin-bottom:12pt;"><span style="font-family:Verdana;"><br />
A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let&#8217;s say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you&#8217;d need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:</span></p>
<p class="MsoNormal"><span class="code"><span style="font-family:Verdana;">c:\&gt;java com.xyz.hr.Employee</span></span><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><strong><br />
45. What&#8217;s the difference between J2SDK 1.5 and J2SDK 5.0?</strong></span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. There’s no difference, Sun Microsystems just re-branded this version.</span></p>
<p><strong><span style="font-family:Verdana;">46. What would you use to compare two String variables &#8211; the operator == or the method equals()?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. I&#8217;d use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.</span></p>
<p><strong><span style="font-family:Verdana;">47. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception&#8217;s subclasses have to be caught first.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;"><br />
48. Can an inner class declared inside of a method access local variables of this method?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. It&#8217;s possible if these variables are final.</span></p>
<p class="MsoNormal" style="margin-bottom:12pt;"><strong><span style="font-family:Verdana;"><br />
49. What can go wrong if you replace &amp;&amp; with &amp; in the following code:</span></strong></p>
<p class="MsoNormal" style="margin-bottom:12pt;"><span class="code"><strong><span style="font-family:Verdana;">String a=null; if (a!=null &amp;&amp; a.length()&gt;10) {&#8230;}</span></strong></span><strong><span style="font-family:Verdana;"> </span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;">A. A single ampersand here would lead to a NullPointerException.</span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
<strong><span style="font-family:Verdana;">50. What&#8217;s the main difference between a Vector and an ArrayList</span></strong></span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Java Vector class is internally synchronized and ArrayList is not.</span></p>
<p><strong>51. When should the method invokeLater()be used?</strong></p>
<p class="MsoNormal" style="margin-bottom:12pt;"><span style="font-family:Verdana;"><br />
A. This method is used to ensure that Swing components are updated through the event-dispatching thread.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;">52 . How can a subclass call a method or a constructor defined in a super class?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass&#8217;s constructor.</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="font-family:Verdana;">53. What&#8217;s the difference between a queue and a stack?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="font-family:Verdana;">54. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?</span></strong><span style="font-family:Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="font-family:Verdana;">55. What comes to mind when you hear about a young generation in Java?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Garbage collection.</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="font-family:Verdana;">56. What comes to mind when someone mentions a shallow copy in Java?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Object cloning.</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="font-family:Verdana;">57. If you&#8217;re overriding the method equals() of an object, which other method you might also consider?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. hashCode()</span></p>
<p class="MsoNormal"><span id="more-1"></span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;">58. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:<br />
ArrayList or LinkedList?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. ArrayList</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="font-family:Verdana;">59. How would you make a copy of an entire Java object with its state?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Have this class implement Cloneable interface and call its method clone().</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="font-family:Verdana;">60. How can you minimize the need of garbage collection and make the memory use more effective?</span></strong></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. Use object pooling and weak object references.</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><span style="font-family:Verdana;"><strong>61. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?</strong></span></p>
<p class="MsoNormal"><span style="font-family:Verdana;"><br />
A. If these classes are threads I&#8217;d consider notify() or notifyAll(). For regular classes you can use the Observer interface.</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="font-family:Verdana;">62. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?</span></strong></p>
<p class="MsoNormal" style="margin-bottom:12pt;"><span style="font-family:Verdana;"><br />
A. You do not need to specify any access level, and Java will use a default package access level.</span></p>
<p class="MsoNormal" style="margin-bottom:12pt;"><strong><span style="font-family:Verdana;">Some Basic to Advance Core Java Questions</span></strong></p>
<ol>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can there be an abstract class with no abstract methods in it?</span></strong><span style="font-family:Verdana;"> &#8211; Yes </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can an Interface be final?</span></strong><span style="font-family:Verdana;"> &#8211; No </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can an Interface have an inner class?</span></strong><span style="font-family:Verdana;"> &#8211; Yes. </span></li>
</ol>
<pre><span style="font-size:12pt;font-family:Verdana;">  </span>public interface abc

 {

 static int i=0; void dd();

 class a1

 {

 a1()

 {

 int j;

 System.out.println("inside");

 };

 public static void main(String a1[])

 {

 System.out.println("in interfia");

 }

 }

}</pre>
<ol>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can we define private and protected modifiers for variables in interfaces?</span></strong><span style="font-family:Verdana;"> &#8211; No </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is Externalizable?</span></strong><span style="font-family:Verdana;"> &#8211; Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in) </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What modifiers are allowed for methods in an Interface?</span></strong><span style="font-family:Verdana;"> &#8211; Only public and abstract modifiers are allowed for methods in interfaces. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a local, member and a class variable?</span></strong><span style="font-family:Verdana;"> &#8211; Variables declared within a method are “local” variables. Variables declared within the class i.e not within any methods are “member” variables (global variables). Variables declared within the class i.e not within any methods and are defined as “static” are class variables </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the different identifier states of a Thread?</span></strong><span style="font-family:Verdana;"> &#8211; The different identifiers of a Thread are: R &#8211; Running or runnable thread, S &#8211; Suspended thread, CW &#8211; Thread waiting on a condition variable, MW &#8211; Thread waiting on a monitor lock, MS &#8211; Thread suspended waiting on a monitor lock </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are some alternatives to inheritance?</span></strong><span style="font-family:Verdana;"> &#8211; Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass). </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Why isn’t there operator overloading?</span></strong><span style="font-family:Verdana;"> &#8211; Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn’t even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte(). </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What does it mean that a method or field is “static”?</span></strong><span style="font-family:Verdana;"> &#8211; Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That’s how library methods like System.out.println() work. out is a static field in the java.lang.System class. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?</span></strong><span style="font-family:Verdana;"> </span></li>
</ol>
<pre>      String hostname = InetAddress.getByName("192.18.97.39").getHostName();</pre>
<ol>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Difference between JRE/JVM/JDK?</span></strong><span style="font-family:Verdana;"> </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Why do threads block on I/O?</span></strong><span style="font-family:Verdana;"> &#8211; Threads block on i/o (that is enters the waiting state) so that other threads may execute while the I/O operation is performed. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is synchronization and why is it important?</span></strong><span style="font-family:Verdana;"> &#8211; With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object’s value. This often leads to significant errors. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Is null a keyword?</span></strong><span style="font-family:Verdana;"> &#8211; The null value is not a keyword. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Which characters may be used as the second character of an identifier, but not as the first character of an identifier?</span></strong><span style="font-family:Verdana;"> &#8211; The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What modifiers may be used with an inner class that is a member of an outer class?</span></strong><span style="font-family:Verdana;"> &#8211; A (non-local) inner class may be declared as public, protected, private, static, final, or abstract. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?</span></strong><span style="font-family:Verdana;"> &#8211; Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are wrapped classes?</span></strong><span style="font-family:Verdana;"> &#8211; Wrapped classes are classes that allow primitive types to be accessed as objects. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What restrictions are placed on the location of a package statement within a source code file?</span></strong><span style="font-family:Verdana;"> &#8211; A package statement must appear as the first line in a source code file (excluding blank lines and comments). </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between preemptive scheduling and time slicing?</span></strong><span style="font-family:Verdana;"> &#8211; Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a native method?</span></strong><span style="font-family:Verdana;"> &#8211; A native method is a method that is implemented in a language other than Java. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are order of precedence and associativity, and how are they used?</span></strong><span style="font-family:Verdana;"> &#8211; Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the catch or declare rule for method declarations?</span></strong><span style="font-family:Verdana;"> &#8211; If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can an anonymous class be declared as implementing an interface and extending a class?</span></strong><span style="font-family:Verdana;"> &#8211; An anonymous class may implement an interface or extend a superclass, but may not be declared to do both. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the range of the char type?</span></strong><span style="font-family:Verdana;"> &#8211; The range of the char type is 0 to 2^16 &#8211; 1. </span></li>
</ol>
<p class="MsoNormal"><strong><span style="font-family:Verdana;">Basic Java Interview Questions:</span></strong></p>
<p><strong><span style="font-family:Verdana;">1. Why do you prefer Java?</span></strong><span style="font-family:Verdana;"> </span></p>
<p><span style="font-family:Verdana;">Answer: write once ,run anywhere.</span></p>
<p><strong><span style="font-family:Verdana;">2. Name some of the classes which provide the functionality of collation?</span></strong></p>
<p><span style="font-family:Verdana;">Answer: collator, rulebased collator, collationkey, collationelement iterator.</span></p>
<p><strong><span style="font-family:Verdana;">3. Awt stands for? and what is it?</span></strong></p>
<p><span style="font-family:Verdana;">Answer: AWT stands for Abstract window tool kit. It is a is a package that provides an integrated set of classes to manage user interface components. </span></p>
<p><strong><span style="font-family:Verdana;">4. why a java program can not directly communicate with an ODBC driver?</span></strong></p>
<p><span style="font-family:Verdana;">Answer: Since ODBC API is written in C language and makes use of pointers which Java can not support.</span></p>
<p><strong><span style="font-family:Verdana;">5. Are servlets platform independent? If so Why? Also what is the most common application of servlets?</span></strong></p>
<p style="border:medium none #000000;padding:0;"><span style="font-family:Verdana;">Answer: Yes, Because they are written in Java. The most common application of servlet is to access database and dynamically construct HTTP response</span></p>
<ol>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is garbage collection? What is the process that is responsible for doing that in java?</span></strong><span style="font-family:Verdana;"> &#8211; Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What kind of thread is the Garbage collector thread?</span></strong><span style="font-family:Verdana;"> &#8211; It is a daemon thread.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a daemon thread?</span></strong><span style="font-family:Verdana;"> &#8211; These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How will you invoke any external process in Java?</span></strong><span style="font-family:Verdana;"> &#8211; Runtime.getRuntime().exec(….)</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the finalize method do?</span></strong><span style="font-family:Verdana;"> &#8211; Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is mutable object and immutable object?</span></strong><span style="font-family:Verdana;"> &#8211; If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the basic difference between string and stringbuffer object?</span></strong><span style="font-family:Verdana;"> &#8211; String is an immutable object. StringBuffer is a mutable object.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the purpose of Void class?</span></strong><span style="font-family:Verdana;"> &#8211; The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is reflection?</span></strong><span style="font-family:Verdana;"> &#8211; Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the base class for Error and Exception?</span></strong><span style="font-family:Verdana;"> &#8211; Throwable</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the byte range?</span></strong><span style="font-family:Verdana;"> -128 to 127</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the implementation of destroy method in java.. is it native or java code?</span></strong><span style="font-family:Verdana;"> &#8211; This method is not implemented.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a package?</span></strong><span style="font-family:Verdana;"> &#8211; To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the approaches that you will follow for making a program very efficient?</span></strong><span style="font-family:Verdana;"> &#8211; By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a DatabaseMetaData?</span></strong><span style="font-family:Verdana;"> &#8211; Comprehensive information about the database as a whole. </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is Locale?</span></strong><span style="font-family:Verdana;"> &#8211; A Locale object represents a specific geographical, political, or cultural region</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How will you load a specific locale?</span></strong><span style="font-family:Verdana;"> &#8211; Using ResourceBundle.getBundle(…);</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is JIT and its use?</span></strong><span style="font-family:Verdana;"> &#8211; Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Is JVM a compiler or an interpreter?</span></strong><span style="font-family:Verdana;"> &#8211; Interpreter</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">When you think about optimization, what is the best way to findout the time/memory consuming process?</span></strong><span style="font-family:Verdana;"> &#8211; Using profiler</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the purpose of assert keyword used in JDK1.4.x?</span></strong><span style="font-family:Verdana;"> &#8211; In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How will you get the platform dependent values like line separator, path separator, etc., ?</span></strong><span style="font-family:Verdana;"> &#8211; Using Sytem.getProperty(…) (line.separator, path.separator, …)</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is skeleton and stub? what is the purpose of those?</span></strong><span style="font-family:Verdana;"> &#8211; Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the final keyword denotes?</span></strong><span style="font-family:Verdana;"> &#8211; final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the significance of ListIterator?</span></strong><span style="font-family:Verdana;"> &#8211; You can iterate back and forth.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the major difference between LinkedList and ArrayList?</span></strong><span style="font-family:Verdana;"> &#8211; LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is nested class?</span></strong><span style="font-family:Verdana;"> &#8211; If all the methods of a inner class is static then it is a nested class.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is inner class?</span></strong><span style="font-family:Verdana;"> &#8211; If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is composition?</span></strong><span style="font-family:Verdana;"> &#8211; Holding the reference of the other class within some other class is known as composition.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is aggregation?</span></strong><span style="font-family:Verdana;"> &#8211; It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the methods in Object?</span></strong><span style="font-family:Verdana;"> &#8211; clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can you instantiate the Math class?</span></strong><span style="font-family:Verdana;"> &#8211; You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is singleton?</span></strong><span style="font-family:Verdana;"> &#8211; It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … } </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is DriverManager?</span></strong><span style="font-family:Verdana;"> &#8211; The basic service to manage set of JDBC drivers.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is Class.forName() does and how it is useful?</span></strong><span style="font-family:Verdana;"> &#8211; It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Inq</span></strong><span style="font-family:Verdana;"> adds a question: Expain the reason for each keyword of</span></li>
</ol>
<p class="MsoNormal" style="margin-left:.5in;"><span style="font-family:Verdana;">public static void main(String args[])</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;">2.</span></strong></p>
<p class="MsoNormal"><strong> </strong></p>
<ol>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a Marker Interface?</span></strong><span style="font-family:Verdana;"> &#8211; An interface with no methods. Example: Serializable, Remote, Cloneable</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What interface do you implement to do the sorting?</span></strong><span style="font-family:Verdana;"> &#8211; Comparable</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the eligibility for a object to get cloned?</span></strong><span style="font-family:Verdana;"> &#8211; It must implement the Cloneable interface</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the purpose of abstract class? </span></strong><span style="font-family:Verdana;">- It is not an instantiable class. It provides the concrete implementation for some/all the methods. So that they can reuse the concrete functionality by inheriting the abstract class.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between interface and abstract class?</span></strong><span style="font-family:Verdana;"> &#8211; Abstract class defined with methods. Interface will declare only the methods. Abstract classes are very much useful when there is a some functionality across various classes. Interfaces are well suited for the classes which varies in functionality but with the same method signatures.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What do you mean by RMI and how it is useful?</span></strong><span style="font-family:Verdana;"> &#8211; RMI is a remote method invocation. Using RMI, you can work with remote object. The function calls are as though you are invoking a local variable. So it gives you a impression that you are working really with a object that resides within your own JVM though it is somewhere.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the protocol used by RMI?</span></strong><span style="font-family:Verdana;"> &#8211; RMI-IIOP</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a hashCode?</span></strong><span style="font-family:Verdana;"> &#8211; hash code value for this object which is unique for every object.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a thread?</span></strong><span style="font-family:Verdana;"> &#8211; Thread is a block of code which can execute concurrently with other threads in the JVM.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the algorithm used in Thread scheduling?</span></strong><span style="font-family:Verdana;"> &#8211; Fixed priority scheduling.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is hash-collision in Hashtable and how it is handled in Java?</span></strong><span style="font-family:Verdana;"> &#8211; Two different keys with the same hash value. Two different entries will be kept in a single hash bucket to avoid the collision.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the different driver types available in JDBC?</span></strong><span style="font-family:Verdana;"> &#8211; 1. A JDBC-ODBC bridge 2. A native-API partly Java technology-enabled driver 3. A net-protocol fully Java technology-enabled driver 4. A native-protocol fully Java technology-enabled driver For more information: Driver Description</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Is JDBC-ODBC bridge multi-threaded?</span></strong><span style="font-family:Verdana;"> &#8211; No</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Does the </span></strong><strong><span style="font-family:Verdana;">JDBC-ODBC</span></strong><strong><span style="font-family:Verdana;"> </span></strong><strong><span style="font-family:Verdana;">Bridge</span></strong><strong><span style="font-family:Verdana;"> support multiple concurrent open statements per connection?</span></strong><span style="font-family:Verdana;"> &#8211; No</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the use of serializable?</span></strong><span style="font-family:Verdana;"> &#8211; To persist the state of an object into any perminant storage device.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the use of transient?</span></strong><span style="font-family:Verdana;"> &#8211; It is an indicator to the JVM that those variables should not be persisted. It is the users responsibility to initialize the value when read back from the storage.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the different level lockings using the synchronization keyword?</span></strong><span style="font-family:Verdana;"> &#8211; Class level lock Object level lock Method level lock Block level lock</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the use of preparedstatement?</span></strong><span style="font-family:Verdana;"> &#8211; Preparedstatements are precompiled statements. It is mainly used to speed up the process of inserting/updating/deleting especially when there is a bulk processing.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is callable statement? Tell me the way to get the callable statement?</span></strong><span style="font-family:Verdana;"> &#8211; Callablestatements are used to invoke the stored procedures. You can obtain the callablestatement from Connection using the following methods prepareCall(String sql) prepareCall(String sql, int resultSetType, int resultSetConcurrency) </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">In a statement, I am executing a batch. What is the result of the execution?</span></strong><span style="font-family:Verdana;"> &#8211; It returns the int array. The array contains the affected row count in the corresponding index of the SQL.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can a abstract method have the static qualifier?</span></strong><span style="font-family:Verdana;"> &#8211; No</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the different types of qualifier and what is the default qualifier?</span></strong><span style="font-family:Verdana;"> &#8211; public, protected, private, package (default)</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the super class of Hashtable?</span></strong><span style="font-family:Verdana;"> &#8211; Dictionary</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a lightweight component?</span></strong><span style="font-family:Verdana;"> &#8211; Lightweight components are the one which doesn’t go with the native call to obtain the graphical units. They share their parent component graphical units to render them. Example, Swing components</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a heavyweight component?</span></strong><span style="font-family:Verdana;"> &#8211; For every paint call, there will be a native call to get the graphical units. Example, AWT.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is an applet?</span></strong><span style="font-family:Verdana;"> &#8211; Applet is a program which can get downloaded into a client environment and start executing there.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What do you mean by a Classloader?</span></strong><span style="font-family:Verdana;"> &#8211; Classloader is the one which loads the classes into the JVM.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the implicit packages that need not get imported into a class file?</span></strong><span style="font-family:Verdana;"> &#8211; java.lang</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between lightweight and heavyweight component?</span></strong><span style="font-family:Verdana;"> &#8211; Lightweight components reuses its parents graphical units. Heavyweight components goes with the native graphical unit for every component. Lightweight components are faster than the heavyweight components.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the ways in which you can instantiate a thread?</span></strong><span style="font-family:Verdana;"> &#8211; Using Thread class By implementing the Runnable interface and giving that handle to the Thread class.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the states of a thread?</span></strong><span style="font-family:Verdana;"> &#8211; 1. New 2. Runnable 3. Not Runnable 4. Dead </span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a socket?</span></strong><span style="font-family:Verdana;"> &#8211; A socket is an endpoint for communication between two machines.</span></li>
</ol>
<p><span style="font-family:Verdana;">33.</span><span style="font-family:Verdana;"> How will you establish the connection between the servlet and an  applet?</span> -<br />
<span style="font-family:Verdana;">Using the URL, I will create the connection URL. Then by openConnection method of the URL, I will establish the connection, through which I can be able to exchange data.</span></p>
<p>34.<strong><span style="font-family:Verdana;">What are the threads will start, when you start the java program?</span></strong><span style="font-family:Verdana;"> &#8211; Finalizer, Main, Reference Handler, Signal Dispatcher.</span></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;">Simple Java Questions</span></strong></p>
<p class="MsoNormal"><strong> </strong></p>
<ol>
<li class="MsoNormal"><span style="font-family:Verdana;">Meaning &#8211; Abstract classes, abstract methods</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Difference &#8211; Java,C++</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Difference between == and equals method</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Explain Java security model</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Explain working of Java Virtual Machine (JVM)</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Difference: Java Beans, Servlets</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Difference: AWT, Swing</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Disadvantages of Java</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">What is BYTE Code ?</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">What gives java it’s “write once and run anywhere” nature?</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Does Java have “goto”?</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">What is the meaning of “final” keyword?</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Can I create final executable from Java?</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Explain Garbage collection mechanism in Java</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Why Java is not 100% pure object oriented language?</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">What are interfaces? or How to support multiple inhertance in Java?</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">How to use C++ code in Java Program?</span></li>
<li class="MsoNormal"><span style="font-family:Verdana;">Differnece between &#8220;Applet&#8221; and &#8220;Application&#8221;?</span></li>
</ol>
<p><!--more--></p>
<p><strong>Something New in Core Java Questions</strong></p>
<p class="MsoNormal"><strong><span style="font-family:Verdana;">Good Java Questions</span></strong></p>
<p class="MsoNormal"><strong> </strong></p>
<ol>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Is “abc” a primitive value?</span></strong><span style="font-family:Verdana;"> &#8211; The String literal “abc” is not a primitive value. It is a String object.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What restrictions are placed on the values of each case of a switch statement?</span></strong><span style="font-family:Verdana;"> &#8211; During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What modifiers may be used with an interface declaration?</span></strong><span style="font-family:Verdana;"> &#8211; An interface may be declared as public or abstract.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Is a class a subclass of itself?</span></strong><span style="font-family:Verdana;"> &#8211; A class is a subclass of itself.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between a while statement and a do statement?</span></strong><span style="font-family:Verdana;"> &#8211; A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What modifiers can be used with a local inner class?</span></strong><span style="font-family:Verdana;"> &#8211; A local inner class may be final or abstract.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the purpose of the File class?</span></strong><span style="font-family:Verdana;"> &#8211; The File class is used to create objects that provide access to the files and directories of a local file system.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can an exception be rethrown?</span></strong><span style="font-family:Verdana;"> &#8211; Yes, an exception can be rethrown.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">When does the compiler supply a default constructor for a class?</span></strong><span style="font-family:Verdana;"> &#8211; The compiler supplies a default constructor for a class if no other constructors are provided.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">If a method is declared as protected, where may the method be accessed?</span></strong><span style="font-family:Verdana;"> &#8211; A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Which non-Unicode letter characters may be used as the first character of an identifier?</span></strong><span style="font-family:Verdana;"> &#8211; The non-Unicode letter characters $ and _ may appear as the first character of an identifier</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What restrictions are placed on method overloading?</span></strong><span style="font-family:Verdana;"> &#8211; Two methods may not have the same name and argument list but different return types.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is casting?</span></strong><span style="font-family:Verdana;"> &#8211; There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the return type of a program’s main() method?</span></strong><span style="font-family:Verdana;"> &#8211; A program’s main() method has a void return type.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What class of exceptions are generated by the Java run-time system?</span></strong><span style="font-family:Verdana;"> &#8211; The Java runtime system generates RuntimeException and Error exceptions.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What class allows you to read objects directly from a stream?</span></strong><span style="font-family:Verdana;"> &#8211; The ObjectInputStream class supports the reading of objects from input streams.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between a field variable and a local variable?</span></strong><span style="font-family:Verdana;"> &#8211; A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How are this() and super() used with constructors?</span></strong><span style="font-family:Verdana;"> &#8211; this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the relationship between a method’s throws clause and the exceptions that can be thrown during the method’s execution?</span></strong><span style="font-family:Verdana;"> &#8211; A method’s throws clause must declare any checked exceptions that are not caught within the body of the method.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Why are the methods of the Math class static?</span></strong><span style="font-family:Verdana;"> &#8211; So they can be invoked as if they are a mathematical code library.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are the legal operands of the instanceof operator?</span></strong><span style="font-family:Verdana;"> &#8211; The left operand is an object reference or null value and the right operand is a class, interface, or array type.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What an I/O filter?</span></strong><span style="font-family:Verdana;"> &#8211; An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">If an object is garbage collected, can it become reachable again?</span></strong><span style="font-family:Verdana;"> &#8211; Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What are E and PI?</span></strong><span style="font-family:Verdana;"> &#8211; E is the base of the natural logarithm and PI is mathematical value pi.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Are true and false keywords?</span></strong><span style="font-family:Verdana;"> &#8211; The values true and false are not keywords.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between the File and RandomAccessFile classes?</span></strong><span style="font-family:Verdana;"> &#8211; The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What happens when you add a double value to a String?</span></strong><span style="font-family:Verdana;"> &#8211; The result is a String object.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is your platform’s default character encoding?</span></strong><span style="font-family:Verdana;"> &#8211; If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Which package is always imported by default?</span></strong><span style="font-family:Verdana;"> &#8211; The java.lang package is always imported by default.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What interface must an object implement before it can be written to a stream as an object?</span></strong><span style="font-family:Verdana;"> &#8211; An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How can my application get to know when a HttpSession is removed?</span></strong><span style="font-family:Verdana;"> &#8211; Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method. Create an instance of that class and put that instance in HttpSession.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Whats the difference between notify() and notifyAll()?</span></strong><span style="font-family:Verdana;"> &#8211; notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a “writer” lock on a file might permit all “readers” to resume).</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Why can’t I say just abs() or sin() instead of Math.abs() and Math.sin()?</span></strong><span style="font-family:Verdana;"> &#8211; The import statement does not bring methods into your local name space. It lets you abbreviate class names, but not get rid of them altogether. That’s just the way it works, you’ll get used to it. It’s really a lot safer this way.<br />
However, there is actually a little trick you can use in some cases that gets you what you want. If your top-level class doesn’t need to inherit from anything else, make it inherit from java.lang.Math. That *does* bring all the methods into your local name space. But you can’t use this trick in an applet, because you have to inherit from java.awt.Applet. And actually, you can’t use it on java.lang.Math at all, because Math is a “final” class which means it can’t be extended.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Why are there no global variables in Java?</span></strong><span style="font-family:Verdana;"> &#8211; Global variables are considered bad form for a variety of reasons: Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables), State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state, When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, Java decided to ban global variables.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What does it mean that a class or member is final?</span></strong><span style="font-family:Verdana;"> &#8211; A final class can no longer be subclassed. Mostly this is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. Methods may be declared final as well. This means they may not be overridden in a subclass. Fields can be declared final, too. However, this has a completely different meaning. A final field cannot be changed after it’s initialized, and it must include an initializer statement where it’s declared. For example, public final double c = 2.998; It’s also possible to make a static field final to get the effect of C++’s const statement or some uses of C’s #define, e.g. public static final double c = 2.998;</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What does it mean that a method or class is abstract?</span></strong><span style="font-family:Verdana;"> &#8211; An abstract class cannot be instantiated. Only its subclasses can be instantiated. You indicate that a class is abstract with the abstract keyword like this: </span></li>
</ol>
<pre><span style="font-family:Verdana;">    37.<strong>public abstract class Container extends Component {</strong></span></pre>
<p style="margin-left:.5in;"><span style="font-family:Verdana;">Abstract classes may contain abstract methods. A method declared abstract is not actually implemented in the current class. It exists only to be overridden in subclasses. It has no body. For example, </span></p>
<pre><span style="font-family:Verdana;">public abstract float price();</span></pre>
<p style="margin-left:.5in;"><span style="font-family:Verdana;">Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or itself be declared abstract. </span></p>
<p style="margin-left:.5in;"><span style="font-family:Verdana;"><!--more--><br />
</span></p>
<ol>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a transient variable?</span></strong><span style="font-family:Verdana;"> &#8211; transient variable is a variable that may not be serialized.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How are Observer and Observable used?</span></strong><span style="font-family:Verdana;"> &#8211; Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can a lock be acquired on a class?</span></strong><span style="font-family:Verdana;"> &#8211; Yes, a lock can be acquired on a class. This lock is acquired on the class’s Class object.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What state does a thread enter when it terminates its processing?</span></strong><span style="font-family:Verdana;"> &#8211; When a thread terminates its processing, it enters the dead state.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How does Java handle integer overflows and underflows?</span></strong><span style="font-family:Verdana;"> &#8211; It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between the &gt;&gt; and &gt;&gt;&gt; operators?</span></strong><span style="font-family:Verdana;"> &#8211; The &gt;&gt; operator carries the sign bit when shifting right. The &gt;&gt;&gt; zero-fills bits that have been shifted out.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Is sizeof a keyword?</span></strong><span style="font-family:Verdana;"> &#8211; The sizeof operator is not a keyword.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Does garbage collection guarantee that a program will not run out of memory?</span></strong><span style="font-family:Verdana;"> &#8211; Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can an object’s finalize() method be invoked while it is reachable?</span></strong><span style="font-family:Verdana;"> &#8211; An object’s finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object’s finalize() method may be invoked by other objects.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What value does readLine() return when it has reached the end of a file?</span></strong><span style="font-family:Verdana;"> &#8211; The readLine() method returns null when it has reached the end of a file.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can a for statement loop indefinitely?</span></strong><span style="font-family:Verdana;"> &#8211; Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">To what value is a variable of the String type automatically initialized?</span></strong><span style="font-family:Verdana;"> &#8211; The default value of an String type is null.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is a task’s priority and how is it used in scheduling?</span></strong><span style="font-family:Verdana;"> &#8211; A task’s priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the range of the short type?</span></strong><span style="font-family:Verdana;"> &#8211; The range of the short type is -(2^15) to 2^15 &#8211; 1.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the purpose of garbage collection?</span></strong><span style="font-family:Verdana;"> &#8211; The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What do you understand by private, protected and public?</span></strong><span style="font-family:Verdana;"> &#8211; These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is Downcasting ?</span></strong><span style="font-family:Verdana;"> &#8211; Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Can a method be overloaded based on different return type but same argument type ?</span></strong><span style="font-family:Verdana;"> &#8211; No, because the methods can be called without using their return type in which case there is ambiquity for the compiler</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What happens to a static var that is defined within a method of a class ?</span></strong><span style="font-family:Verdana;"> &#8211; Can’t do it. You’ll get a compilation error</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">How many static init can you have ?</span></strong><span style="font-family:Verdana;"> &#8211; As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference amongst JVM Spec, JVM Implementation, JVM Runtime ?</span></strong><span style="font-family:Verdana;"> &#8211; The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the actual implementation of the spec by a vendor and the JVM runtime is the actual running instance of a JVM implementation</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">Describe what happens when an object is created in Java?</span></strong><span style="font-family:Verdana;"> &#8211; Several things happen in a particular order to ensure the object is constructed properly: Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data. The instance variables of the objects are initialized to their default values. The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What does the “final” keyword mean in front of a variable? A method? A class?</span></strong><span style="font-family:Verdana;"> &#8211; FINAL for a variable: value is constant. FINAL for a method: cannot be overridden. FINAL for a class: cannot be derived</span></li>
<li class="MsoNormal"><strong><span style="font-family:Verdana;">What is the difference between instanceof and isInstance?</span></strong><span style="font-family:Verdana;"> &#8211; instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception. isInstance() Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise.</span></li>
</ol>
<p><strong><span style="font-size:10pt;font-family:Verdana;"> Why does it take so much time to access an Applet having Swing Components the first time?</span></strong>-<br />
<span style="font-family:Verdana;">Because behind every swing component are many Java objects and resources. This takes time to create  them in memory. JDK 1.3 from Sun has some improvements which may lead to faster execution of Swing applications.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=1&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2009/01/04/hello-world/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
		<item>
		<title>Some Interview Questions on String.</title>
		<link>http://javafaq.wordpress.com/2007/01/24/some-interview-questions-on-string/</link>
		<comments>http://javafaq.wordpress.com/2007/01/24/some-interview-questions-on-string/#comments</comments>
		<pubDate>Wed, 24 Jan 2007 05:23:19 +0000</pubDate>
		<dc:creator>Sachin Kakkar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://javafaq.wordpress.com/2007/01/24/some-interview-questions-on-string/</guid>
		<description><![CDATA[Que:-1 Difference Between String and String Buffer? Ans:- String is a Collection or array of Characters.when u create a string object u r creating a string that can&#8217;t be changed. this approach is used becoz fixed, immutable strings can be implemented more efficiently then the muttable (Changeable Ones ) strings. StringBuffer &#8211; StringBuffer Represents growable [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=15&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Que:-1 Difference Between String and String Buffer?</p>
<p>Ans:- String is a Collection or array of Characters.when u create a string object u r creating a string that can&#8217;t be changed. this approach is used becoz fixed, immutable strings can be implemented more efficiently then the muttable (Changeable Ones ) strings.</p>
<p>StringBuffer &#8211; StringBuffer Represents growable and writeable character sequences.StringBuffer may have characters and substrings inserted in the middle or append to end.</p>
<p>StringBuffer allocates room for 16 additional Characters when no specific buffer length is requested, becoz reallocation is a costly process in terms of time.</p>
<p>Que:-2  difference between verses (==) and .equals().</p>
<p>Ans.  .equals() is used for comparing values of a string objects and verses ( ==) is used to compare there memory reference.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/javafaq.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/javafaq.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/javafaq.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/javafaq.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/javafaq.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=javafaq.wordpress.com&amp;blog=586052&amp;post=15&amp;subd=javafaq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://javafaq.wordpress.com/2007/01/24/some-interview-questions-on-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f23d189363d45b9dd3f4c41382224ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sachin</media:title>
		</media:content>
	</item>
	</channel>
</rss>
