<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4196701761409440230</id><updated>2026-09-06T20:34:40.688-07:00</updated><category term="java"/><category term="advantages of jsf"/><category term="getting started jsf"/><category term="java server faces"/><category term="jsf"/><category term="oracle"/><category term="vector"/><category term="Cloneable"/><category term="Design Pattern"/><category term="Double-checked locking"/><category term="ENUM"/><category term="Entry"/><category term="JDK 8"/><category term="Lazy loading"/><category term="Serializable"/><category term="Singleton"/><category term="Singleton Design Pattern"/><category term="Why  jsf"/><category term="android"/><category term="android installation"/><category term="arraylist"/><category term="balanced tree"/><category term="clone"/><category term="collections"/><category term="converting web application into jsf appliction"/><category term="double check"/><category term="eclipse"/><category term="eclipse android"/><category term="getting started android"/><category term="hash collision"/><category term="hashmap"/><category term="impdp"/><category term="java 8"/><category term="java collections"/><category term="jsf interview"/><category term="jsf origin"/><category term="jsf tutorial"/><category term="linked list"/><category term="list"/><category term="new in java 8"/><category term="oracle datapump"/><category term="oracle dataset import"/><category term="oracle import"/><category term="performance"/><category term="setting up jsf"/><category term="start up jsf"/><category term="synchronized"/><category term="synchronizedlist"/><category term="uses of jsf"/><category term="volatile"/><category term="what jsf"/><title type='text'>Learn Java</title><subtitle type='html'>Just how I learned</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-9154306728785397372</id><published>2014-04-10T06:04:00.000-07:00</published><updated>2014-04-14T21:57:34.690-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="balanced tree"/><category scheme="http://www.blogger.com/atom/ns#" term="Entry"/><category scheme="http://www.blogger.com/atom/ns#" term="hash collision"/><category scheme="http://www.blogger.com/atom/ns#" term="hashmap"/><category scheme="http://www.blogger.com/atom/ns#" term="java 8"/><category scheme="http://www.blogger.com/atom/ns#" term="JDK 8"/><category scheme="http://www.blogger.com/atom/ns#" term="new in java 8"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle"/><category scheme="http://www.blogger.com/atom/ns#" term="performance"/><title type='text'>What&#39;s New in JAVA 8</title><content type='html'>&lt;br /&gt;
Finally Java 8 released under oracle leadership with many features and enhancements. Though some of the popular JSR&#39;s like JSR 294 (Jigsaw) are deferred again to next release, Java 8 still be the largest ever upgrade to java after it was introduced in 1996.&amp;nbsp; Lets see one of those improvements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;u&gt;&lt;b&gt;&amp;nbsp;Performance improvement of java.util.HashMap under high hash-collision conditions&lt;/b&gt;&lt;/u&gt; : &lt;/span&gt;&lt;/h2&gt;
&lt;br /&gt;
Just to give a little background : &lt;br /&gt;
&lt;br /&gt;
HashMap is used to store key-value pairs in no.of buckets technically &#39;Entry&#39; objects . &lt;br /&gt;
&lt;br /&gt;
Entry is an inner class of HashMap. Please click&amp;nbsp; &lt;a href=&quot;http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/java/util/HashMap.java#HashMap.Entry&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt; to see the source code in java 7.&lt;br /&gt;
&lt;br /&gt;
Each bucket has a unique number called hash code. When you try to put a key-value pair into the map, the hashmap will look at the hash code of the key, and store the pair in the bucket of which the identifier is the hash code of the key. Let&#39;s say if hash code of two keys are same then hash-collision occurs.&lt;br /&gt;
&lt;br /&gt;
Till now (prior to Java 8), hash collision is addressed by creating a linked list data structure. Here is how...&lt;br /&gt;
&lt;br /&gt;
Lets see the source code of &#39;createEntry&#39; method which gets called internally when you try to &#39;put&#39; values into HashMap.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;u&gt;&lt;b&gt;In Java 7:&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/h4&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void&amp;nbsp; createEntry(int hash, K key, V value, int bucketIndex) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Entry&amp;lt;K,V&amp;gt; e = table[bucketIndex];&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table[bucketIndex] = new Entry&amp;lt;&amp;gt;(hash, key, value, e);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; size++;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
An index will be calculated based on hash-code of key as I said earlier and It will be passed to the above method. Don&#39;t confuse with the table field which is nothing but an array of Entry objects. After finding the index, it first check the table array to find whether that position already contains an Entry object and pass the same to create new Entry object, it could be null or existing object.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Here is the Entry inner class:&lt;/h4&gt;
&lt;br /&gt;
&amp;nbsp;static class Entry&amp;lt;K,V&amp;gt; implements Map.Entry&amp;lt;K,V&amp;gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final K key;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; V value;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Entry&amp;lt;K,V&amp;gt; next;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int hash;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Entry(int h, K k, V v, Entry&amp;lt;K,V&amp;gt; n) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = v;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; next = n;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key = k;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hash = h;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
If it finds an Entry object in the specified index, it will move the existing entry object to next and create a new entry object with new key and value. So when ever there is hash collision, new one will be placed in the first node and the rest will be moved to next node. Like this a linked list starts growing when ever there is a hash-collision on each bucket.This is the story till Java 7. &lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Problem with this approach: &lt;/h4&gt;
&lt;br /&gt;
More the linked list size grow in a single bucket, more compares (equals) will happen while getting one of the value in the linked list. In a worst case scenario,it will be O(n). Perfect way to solve this issue is with a good hash function. &lt;br /&gt;
&lt;br /&gt;
But Java 8 gets us some kind of performance improvement even if you have a bad hash function. Here is how?&lt;br /&gt;
&lt;br /&gt;
Many new fields got introduced in Java 8 HashMap, &lt;b&gt;TREEIFY_THRESHOLD&lt;/b&gt; is one of those which needs to pay attention. in Java 8, When a &#39;put&#39; method is called on a HashMap, it internally calls a method called &#39;putVal&#39;. It normally works the same way that the previous version of Hashmap worked like creating a linked list when a hash collision occurs. &lt;br /&gt;
&lt;br /&gt;
It checks for the node count on a particular bucket on which it is trying to insert, if the node count is &amp;gt; &lt;b&gt;TREEIFY_THRESHOLD&lt;/b&gt; (default is 8), new method got added &#39;treeifyBin&#39; which transform all the nodes into TreeNodes, each structured similarly to those in java.util.TreeMap. It recreates that single bucket (not whole hashmap) by using the TreeNodes. &#39;TreeNode&#39; is an another static inner class like &#39;Entry&#39; but works like a balanced tree (&lt;b&gt;red–black tree&lt;/b&gt;). This gives a guaranteed searching in O(log n) time.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Java 8 Source - treeifyBin () :&lt;/h4&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; final void treeifyBin(Node&amp;lt;K,V&amp;gt;[] tab, int hash) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int n, index; Node&amp;lt;K,V&amp;gt; e;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (tab == null || (n = tab.length) &amp;lt; MIN_TREEIFY_CAPACITY)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; resize();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if ((e = tab[index = (n - 1) &amp;amp; hash]) != null) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TreeNode&amp;lt;K,V&amp;gt; hd = null, tl = null;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TreeNode&amp;lt;K,V&amp;gt; p = replacementTreeNode(e, null);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (tl == null)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hd = p;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.prev = tl;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tl.next = p;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tl = p;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } while ((e = e.next) != null);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((tab[index] = hd) != null)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hd.treeify(tab);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Java 8 Source - TreeNode :&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/h4&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; static final class TreeNode&amp;lt;K,V&amp;gt; extends LinkedHashMap.Entry&amp;lt;K,V&amp;gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TreeNode&amp;lt;K,V&amp;gt; parent;&amp;nbsp; // red-black tree links&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TreeNode&amp;lt;K,V&amp;gt; left;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TreeNode&amp;lt;K,V&amp;gt; right;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TreeNode&amp;lt;K,V&amp;gt; prev;&amp;nbsp;&amp;nbsp;&amp;nbsp; // needed to unlink next upon deletion&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; boolean red;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TreeNode(int hash, K key, V val, Node&amp;lt;K,V&amp;gt; next) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super(hash, key, val, next);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final TreeNode&amp;lt;K,V&amp;gt; root() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (TreeNode&amp;lt;K,V&amp;gt; r = this, p;;) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((p = r.parent) == null)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return r;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r = p;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
Now we know that the bin/bucket transforms into a balanced tree after it reaches a threshold (&lt;b&gt;TREEIFY_THRESHOLD&lt;/b&gt;). What happens if you delete some entries from the same bucket and now the node count is less than &lt;b&gt;TREEIFY_THRESHOLD&lt;/b&gt; value. Will it still maintain the same balanced tree? Yes, until it reaches one more threshold called &#39;&lt;b&gt;UNTREEIFY_THRESHOLD&lt;/b&gt;&#39; (default 6). If the the node count reaches &lt;b&gt;UNTREEIFY_THRESHOLD&lt;/b&gt; value, There is one more method called &#39;&lt;b&gt;untreeify()&lt;/b&gt;&#39; which gets the same old functionality of using linked list.&lt;br /&gt;
&lt;br /&gt;
While investigating all these, I found one difference between Java 7 and Java 8 implementations of HashMap (There may be many which didn&#39;t recognize). Till Java 7, When there is a hash collision, new values will be added to beginning of the list by moving the rest to next. In Java 8, new values will be added always to end of linked list as it needs to count the no.of nodes every time to &lt;b&gt;treeifyBin()&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/9154306728785397372/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2014/04/whats-new-in-java-8.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/9154306728785397372'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/9154306728785397372'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2014/04/whats-new-in-java-8.html' title='What&#39;s New in JAVA 8'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-2860911479144727231</id><published>2014-01-16T03:36:00.000-08:00</published><updated>2014-01-21T08:06:39.368-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="clone"/><category scheme="http://www.blogger.com/atom/ns#" term="Cloneable"/><category scheme="http://www.blogger.com/atom/ns#" term="Design Pattern"/><category scheme="http://www.blogger.com/atom/ns#" term="double check"/><category scheme="http://www.blogger.com/atom/ns#" term="Double-checked locking"/><category scheme="http://www.blogger.com/atom/ns#" term="ENUM"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Lazy loading"/><category scheme="http://www.blogger.com/atom/ns#" term="Serializable"/><category scheme="http://www.blogger.com/atom/ns#" term="Singleton"/><category scheme="http://www.blogger.com/atom/ns#" term="Singleton Design Pattern"/><category scheme="http://www.blogger.com/atom/ns#" term="synchronized"/><category scheme="http://www.blogger.com/atom/ns#" term="volatile"/><title type='text'>Singleton Design Pattern</title><content type='html'>&lt;b&gt;We need to create a class which can have only one instance at any time.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 1:&lt;/span&gt;&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;      public class MySingleton {  
           private static MySingleton singleton= new MySingleton();  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); }  
           public static MySingleton getMySingleton(){  
                return singleton;  
           }  
      }  
&lt;/code&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Let&#39;s create the object when we need it, not at the time of loading the class.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 2(with Lazy loading):&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;i&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;      public class MySingleton {             // Line : 1  
           private static MySingleton singleton=null;          // Line : 2  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); } // Line : 3  
           public static MySingleton getMySingleton(){          // Line : 4  
                if(singleton == null)                              // Line : 5  
                {  
                     singleton = new MySingleton();               // Line : 6  
                }  
                return singleton;                                   // Line : 7  
           }  
      }  
&lt;/code&gt;&lt;/i&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;When multiple threads reach &quot;Line : 5&quot; at the same time, multiple objects can be created.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 3: Using synchronized method&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;      public class MySingleton {  
           private static MySingleton singleton=null;  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); }  
           public static synchronized MySingleton getMySingleton(){  
                if(singleton == null)  
                {  
                     singleton = new MySingleton();  
                }  
                return singleton;  
           }  
      }  
&lt;/code&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Even to check the &#39;not null&#39; condition, all threads need to wait, to acquire lock on that class. As the method is synchronized, we are paying the cost of synchronization for every thread invocation of the method, even though it is only required on the first thread invocation.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;synchronize only the instance creation not the whole method.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 4: Using synchronized block&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;  &lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;      public class MySingleton {                                                       // Line : 1  
           private static MySingleton singleton=null;                              // Line : 2  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); }     // Line : 3  
           public static MySingleton getMySingleton(){                              // Line : 4  
                if(singleton == null)                                                  // Line : 5  
                {  
                     synchronized (MySingleton.class) {                              // Line : 6  
                          singleton = new MySingleton();                              // Line : 7  
                     }  
                }  
                return singleton;                                                       // Line : 8  
           }  
      }  
&lt;/code&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;There is a problem in the above solution. Let&#39;s say there are two threads A and B. Thread A and thread B executes &quot;Line: 5&quot; at the same time. As the singleton object is yet to be instantiated, both satisfies the null check and enters into &quot;Line: 6&quot;. As we are using synchronized block here, only one thread i.e. first thread (say Thread A) gets the lock on class and creates the singleton object, Thread B wait outside at &quot;Line:6&quot; until Thread A releases the lock. Once it releases the lock, Thread B also gets the lock and creates one more object. It can be resolved by checking null one more time inside the synchronized block.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 5: Using Double-checked locking&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;  &lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; public class MySingleton {  
           private static MySingleton singleton=null;  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); }  
           public static MySingleton getMySingleton(){  
                if(singleton == null)  
                {  
                     synchronized (MySingleton.class) {  
                          if(singleton == null)  
                          {  
                               singleton = new MySingleton();  
                          }  
                     }  
                }  
                return singleton;  
           }  
      }  
&lt;/code&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;i&gt; &lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;It looks like, it is a perfect solution. No,it is not.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Note : Our Java compiler is free to reorder the instructions.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Let&#39;s say there are two threads A and B.Imagine that thread A is inside the synchronized block, executing the statement singleton = new MySingleton(); while thread B is just entering getMySingleton(). Consider the effect on memory of this initialization. Memory for the new MySingleton object will be allocated; the constructor for MySingleton will be called, initializing the member fields of the new object; and the field singleton of MySingleton will be assigned a reference to the newly created object.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;However, since thread B is not executing inside a synchronized block, it may see these memory operations in a different order than the one thread A executes. It could be the case that B sees these events in the following order (and the compiler is also free to reorder the instructions like this): allocate memory, assign reference to singleton, call constructor. Suppose thread B comes along after the memory has been allocated and the singleton field is set, but before the constructor is called. It sees that singleton is not null, skips the synchronized block, and returns a reference to a partially constructed singleton! Needless to say, the result is neither expected nor desired.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Reference&lt;/u&gt;:: &lt;/b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;a href=&quot;http://www.javaworld.com/article/2074979/java-concurrency/double-checked-locking--clever--but-broken.html&quot;&gt;From JavaWorld&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 6: Using Volatile&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;volatile ensures that the system will not allow a write of a volatile to be reordered with respect to any previous read or write, and a read of a volatile cannot be reordered with respect to any following read or write&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;i&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; public class MySingleton {  
           private static volatile MySingleton singleton=null;  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); }  
           public static MySingleton getMySingleton(){  
                if(singleton == null)  
                {  
                     synchronized (MySingleton.class) {  
                          if(singleton == null)  
                          {  
                               singleton = new MySingleton();  
                          }  
                     }  
                }  
                return singleton;  
           }  
      }  
&lt;/code&gt;&lt;/i&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;b&gt; &lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;Usually you sould not implement eaither Serializable or Cloneable while wrinting a singleton class.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Even if your singleton class implments Cloneable, here is how you can still make sure that there will be only one object for your single tom class.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Just override the clone method to throw an exception like below.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 7: can&#39;t be cloned.&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;i&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;      public class MySingleton implements Cloneable {  
           private static volatile MySingleton singleton=null;  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); }  
           public static MySingleton getMySingleton(){  
                if(singleton == null)  
                {  
                     synchronized (MySingleton.class) {  
                          if(singleton == null)  
                          {  
                               singleton = new MySingleton();  
                          }  
                     }  
                }  
                return singleton;  
           }  
           @Override  
        protected Object clone() throws CloneNotSupportedException {  
          throw new CloneNotSupportedException(&quot;Cloning of this class is not allowed&quot;);   
        }  
      }  
&lt;/code&gt;&lt;/i&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Sometimes in distributed systems, we need to implement Serializable interface in Singleton class so that we can store it’s state in file system and retrieve it at later point of time. Here is a small singleton class that implements Serializable interface also.&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;To make a singleton class serializable, it is not sufficient merely to add implements Serializable to its declaration. To maintain the singleton guarantee, you have to declare all instance fields transient and provide a readResolve method. Otherwise, each time a serialized instance is deserialized, a new instance will be created&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;readResolve works only when all fields are transient.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 8: using readResolve().&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;i&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; import java.io.ObjectStreamException;  
      import java.io.Serializable;  
      public class MySingleton implements Cloneable,Serializable {  
           private static volatile MySingleton singleton=null;  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); }  
           public static MySingleton getMySingleton(){  
                if(singleton == null)  
                {  
                     synchronized (MySingleton.class) {  
                          if(singleton == null)  
                          {  
                               singleton = new MySingleton();  
                          }  
                     }  
                }  
                return singleton;  
           }  
           @Override  
        protected Object clone() throws CloneNotSupportedException {  
          throw new CloneNotSupportedException(&quot;Cloning of this class is not allowed&quot;);   
        }  
           protected Object readResolve() throws ObjectStreamException {  
             return singleton;  
           }  
      }  
&lt;/code&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;After all here is the new simple singleton which can handle lazy inititialization, serialization and they are thread safe. Newly introduced in JAVA 1.5.&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Solution 9: using ENUM.&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;pre  style=&quot;font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqb1kN3OAtfvkPPeR4mCtMYKD_j_cv6r5l_jB_3u25y4G1EYS1KdMqON8_1oLTFbdUJOHduSiSDPQPPOgDeZnRAqj258PaCu6qJi_M8jzJjbK0UzvjB77X6rGriD_rIoDNqFILSEVYDKRR/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;&quot;&gt;&lt;code style=&quot;color:#000000;word-wrap:normal;&quot;&gt; public class MySingleton {  
            private static enum SingletonEnum {   
               INSTANCE;  
               private static final MySingleton singleton = new MySingleton();  
               public MySingleton getSingleton() {  
                 return singleton;  
               }  
             }  
           private MySingleton(){ System.out.println( &quot;Object Created&quot; ); }  
           public static MySingleton getMySingleton(){  
                return SingletonEnum.INSTANCE.getSingleton();  
           }  
      }  
&lt;/code&gt;&lt;/pre&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/2860911479144727231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2014/01/singleton-design-pattern.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/2860911479144727231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/2860911479144727231'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2014/01/singleton-design-pattern.html' title='Singleton Design Pattern'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-7929350227653913898</id><published>2012-02-02T07:49:00.000-08:00</published><updated>2012-02-02T07:49:25.059-08:00</updated><title type='text'>Building memory efficient JAVA applications</title><content type='html'>&lt;a href=&quot;http://domino.research.ibm.com/comm/research_people.nsf/pages/sevitsky.pubs.html/$FILE/oopsla08%20memory-efficient%20java%20slides.pdf&quot;&gt;http://domino.research.ibm.com/comm/research_people.nsf/pages/sevitsky.pubs.html/$FILE/oopsla08%20memory-efficient%20java%20slides.pdf&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/7929350227653913898/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2012/02/building-memory-efficient-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/7929350227653913898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/7929350227653913898'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2012/02/building-memory-efficient-java.html' title='Building memory efficient JAVA applications'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-4748175192776709185</id><published>2012-02-01T10:27:00.001-08:00</published><updated>2012-02-01T10:27:02.415-08:00</updated><title type='text'>REST IN PEACE - JAVA 6</title><content type='html'>&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; text-align: left;&quot;&gt;According to Oracle, Java SE 6 will no longer be publicly available after this July.&amp;nbsp;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/4748175192776709185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2012/02/rest-in-peace-java-6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/4748175192776709185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/4748175192776709185'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2012/02/rest-in-peace-java-6.html' title='REST IN PEACE - JAVA 6'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-8820233933714171430</id><published>2012-01-14T07:16:00.000-08:00</published><updated>2012-01-14T07:17:46.101-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="android installation"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse android"/><category scheme="http://www.blogger.com/atom/ns#" term="getting started android"/><title type='text'>Making your PC ready to develop android apps</title><content type='html'>Learning Android is one of &amp;nbsp;my resolution of this year, don&#39;t know how far I going to make it...&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
let&#39;s start with the first step of making your PC ready with all the bunch of installations.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
1) install JDK 1.6 -- &lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u30-download-1377139.html&quot;&gt;download jdk 1.6&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
2) install Eclipse indigo 3.7.1 -- &lt;a href=&quot;http://eclipse.org/downloads/&quot;&gt;download Eclipse&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
3) In Eclipse go to Help --&amp;gt; Install new software --&amp;gt; Add&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; Enter the below details&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Name &amp;nbsp; &amp;nbsp; : ADT (you can give what ever)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Location :&amp;nbsp;https://dl-ssl.google.com/android/eclipse/&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; Click OK and Finish.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
4) Restart Eclipse when it asked. While starting eclipse, it will prompt you to download the android SDK or &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; you can give the location if you already have in your mechine.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now your system is ready to develop android apps.....&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/8820233933714171430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2012/01/making-your-pc-ready-to-develop-android.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/8820233933714171430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/8820233933714171430'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2012/01/making-your-pc-ready-to-develop-android.html' title='Making your PC ready to develop android apps'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-1555024508575806121</id><published>2011-12-21T22:51:00.000-08:00</published><updated>2012-06-13T23:36:51.144-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="impdp"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle datapump"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle dataset import"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle import"/><title type='text'>Importing a Oracle Dataset with impdp</title><content type='html'>1)Login to Oracle with admin user(ex: system).&lt;br /&gt;
&lt;br /&gt;
2)Execute the below script.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;create directory expdp_dir as &#39;&amp;lt;directory where the dataset resides&amp;gt;&#39;;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
3)exit the Oracle and run the below command.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;impdp DIRECTORY=expdp_dir DUMPFILE=&amp;lt;dump file name&amp;gt; FULL=y LOGFILE=impfull.log&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Note: &lt;/b&gt;If you have multiple dump files to import, you can use comma(,)&amp;nbsp;separated file names in DUMPFILE argument.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/i&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/1555024508575806121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2011/12/importing-oracle-dataset.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/1555024508575806121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/1555024508575806121'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2011/12/importing-oracle-dataset.html' title='Importing a Oracle Dataset with impdp'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-2167879708286306170</id><published>2010-01-29T01:56:00.001-08:00</published><updated>2014-03-16T01:32:47.059-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="collections"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="list"/><category scheme="http://www.blogger.com/atom/ns#" term="synchronizedlist"/><category scheme="http://www.blogger.com/atom/ns#" term="vector"/><title type='text'>Which one is Better Vector or SynchronizedList</title><content type='html'>&lt;div class=&quot;Section1&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Vector and&amp;nbsp;SynchronizedList are synchronized.&lt;br /&gt;
&lt;br /&gt;
In case of vector the synchronization is at method level, &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
public synchronized E get(int index) {&lt;br /&gt;
return (E)elementData[index];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And in case of SynchronizedList, the statements within the methods are synchronized on the list object. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;SynchronizedList is static inner class inside collections class which implements list interface and necessary methods using synchronized blocks like below.&lt;/span&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;Collections.SynchronizedList&quot; style=&quot;background-color: white; color: red; font-family: monospace; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b style=&quot;background-color: white; font-family: monospace; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;Link to &lt;a href=&quot;http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Collections.java#1808&quot; name=&quot;Collections.SynchronizedList&quot; style=&quot;background-color: white; font-family: monospace; margin: 0px; padding: 0px; white-space: pre;&quot; target=&quot;_blank&quot;&gt;Source code&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Example :&lt;br /&gt;
&lt;br /&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
public E get(int index) {&lt;br /&gt;
synchronized(colobj) {return list.get(index);}&lt;br /&gt;
}&lt;br /&gt;
where colobj is the collection object.&lt;br /&gt;
&lt;br /&gt;
When you do Collections.synchronizedList(new ArrayList()); you end up creating 2 instances of List. Whereas, in case of Vector, you are creating only one instance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/2167879708286306170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/2167879708286306170'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2010/01/which-one-is-better-vector-or.html' title='Which one is Better Vector or SynchronizedList'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-1776115253012190683</id><published>2010-01-29T01:44:00.001-08:00</published><updated>2011-12-21T22:53:08.717-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arraylist"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java collections"/><category scheme="http://www.blogger.com/atom/ns#" term="linked list"/><category scheme="http://www.blogger.com/atom/ns#" term="vector"/><title type='text'>Choosing right collection</title><content type='html'>&lt;div class=Section1&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;The performance of code can be affected significantly by choosing the right collection implementation. Regarding the correct and efficient use of the Java Collection classes, a significant performance setback comes from the low utilization of implementation classes other than ArrayList and HashMap. These two implementations are used for almost everything, although different implementations would be more appropriate in some situations. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;The following rules should be applied to select the appropriate collection class:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:Symbol&#39;&gt;&amp;middot;&lt;/span&gt;&lt;span style=&#39;font-size: 7.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Use ArrayList&lt;i&gt; &lt;/i&gt;to collect data in order of occurrence (append operation only). Adding or removing elements at the bottom of the list is very fast on ArrayLists and LinkedList, but the LinkedList puts a high load on the garbage collector. This is the most common use case for lists.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:Symbol&#39;&gt;&amp;middot;&lt;/span&gt;&lt;span style=&#39;font-size: 7.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Use LinkedList to maintain lists whenever elements have to be inserted or removed at positions &lt;i&gt;other&lt;/i&gt; than the the bottom of the list. Inserting or removing elements is very slow for ArrayLists because at average half of the elements in the list have to be shifted.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:Symbol&#39;&gt;&amp;middot;&lt;/span&gt;&lt;span style=&#39;font-size: 7.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Use LinkedList to maintain lists that contain only very few elements and have a lot of instances (for example, 5000 lists with 3 elements each). An ArrayList wastes space for unused slots, a LinkedList needs more bytes per element.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:Symbol&#39;&gt;&amp;middot;&lt;/span&gt;&lt;span style=&#39;font-size: 7.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Never use LinkedList for index-based access. Use only the implementations of List that also implement the (tag-)interface RandomAccess.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:Symbol&#39;&gt;&amp;middot;&lt;/span&gt;&lt;span style=&#39;font-size: 7.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Use Set types like HashSet and TreeSet to maintain lists that contain no duplicates (for example, observers). Searching is very quick for sets: O(log n) instead of &lt;i&gt;O(n).&lt;/i&gt; The Set implementation LinkedHashSet combines the preservation of the insertion order of the List type with the quick lookup of the HashSet type.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;The values in the table below show the memory requirements of ArrayList and LinkedList during an append-only operation. The LinkedList is faster in filling the list but takes much more time to clean up afterwards. This is due to the complex memory-structure of a linked list (many objects, many references) and therefore a lot of work for the garbage collector.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;So the real behavior depends largely on the load that is put on the system. When the CPU load is not high and garbage collections are not frequent, the garbage collection overhead of the LinkedList is no problem. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;When garbage collection takes place as the CPU is busy the time, the garbage collector needs to work off the memory structure (GC Full Cycle Time in the table) will be added completely to the execution time of the application, because the program execution is interrupted until the memory is acquired by the garbage collector.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; text-align:justify&#39;&gt;&lt;span style=&#39;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Appending 10.000.000 elements to a list.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0  style=&#39;border-collapse:collapse&#39;&gt;  &lt;tr&gt;   &lt;td width=91 valign=top style=&#39;width:.95in;border:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;List Class&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=72 valign=top style=&#39;width:.75in;border:solid windowtext 1.0pt;   border-left:none;padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Memory&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=72 valign=top style=&#39;width:.75in;border:solid windowtext 1.0pt;   border-left:none;padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Garbage&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=120 valign=top style=&#39;width:1.25in;border:solid windowtext 1.0pt;   border-left:none;padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;Execution Time&lt;/span&gt;&lt;b&gt;&lt;sup&gt;&lt;span   style=&#39;font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;&#39;&gt;[1]&lt;/span&gt;&lt;/sup&gt;&lt;/b&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=84 valign=top style=&#39;width:63.0pt;border:solid windowtext 1.0pt;   border-left:none;padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;GC Time&lt;sup&gt;2&lt;/sup&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=151 valign=top style=&#39;width:113.4pt;border:solid windowtext 1.0pt;   border-left:none;padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;GC Full Cycle   Time&lt;sup&gt;3&lt;/sup&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td width=91 valign=top style=&#39;width:.95in;border:solid windowtext 1.0pt;   border-top:none;padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;ArrayList&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=72 valign=top style=&#39;width:.75in;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;45MB&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=72 valign=top style=&#39;width:.75in;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;89MB&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=120 valign=top style=&#39;width:1.25in;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;620 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=84 valign=top style=&#39;width:63.0pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;&amp;lt; 1ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=151 valign=top style=&#39;width:113.4pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;140 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td width=91 valign=top style=&#39;width:.95in;border:solid windowtext 1.0pt;   border-top:none;padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;LinkedList&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=72 valign=top style=&#39;width:.75in;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;234MB&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=72 valign=top style=&#39;width:.75in;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;0MB&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=120 valign=top style=&#39;width:1.25in;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;460 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=84 valign=top style=&#39;width:63.0pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;230 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width=151 valign=top style=&#39;width:113.4pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt&#39;&gt;   &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;span   style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;1.550 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/table&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;sup&gt;&lt;span style=&#39;font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;&#39;&gt;[1]&lt;/span&gt;&lt;/sup&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt; no garbage collections in the background&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;sup&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;2&lt;/span&gt;&lt;/sup&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt; time required to collect the objects in the list after the reference to the list has been cleared&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal style=&#39;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto&#39;&gt;&lt;sup&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt;3&lt;/span&gt;&lt;/sup&gt;&lt;span style=&#39;font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;&#39;&gt; time the garbage collector took to traverse the heap for releasable objects (without finding any)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class=MsoNormal&gt;Regards,&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class=MsoNormal&gt;Vamsi.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;  &lt;/div&gt;  </content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/1776115253012190683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2010/01/choosing-right-collection.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/1776115253012190683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/1776115253012190683'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2010/01/choosing-right-collection.html' title='Choosing right collection'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-3359582053715357756</id><published>2009-11-27T23:50:00.000-08:00</published><updated>2011-12-20T04:32:42.268-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf interview"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf tutorial"/><title type='text'>Internals of JSF</title><content type='html'>&lt;span style=&quot;font-size: small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Once jsf project set up properly i.e entries in the web.xml,jsf related jars in lib folder of your web app(&lt;a href=&quot;http://vamsikavuri.blogspot.com/2009/11/setting-up-jsf.html&quot;&gt;setting up jsf project&lt;/a&gt;) we have to create a faces-config.xml to make our set up into a full fledged jsf application.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;u&gt;&lt;b&gt;Creating Faces-config.xml&lt;/b&gt;&lt;/u&gt; ::&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;In the name itself telling us that it contains all the configurations needed for all jsf pages.In fact we don&#39;t need to create the file with the same name.We can create it with any name and we have to mention same as a context parameter in the WEB.xml (&lt;a href=&quot;http://jsftutor.blogspot.com/2009/11/setting-up-jsf.html&quot;&gt;setting up jsf project&lt;/a&gt;).Now its the time to jump into the detailed view.&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;Fallowing are the two main components that we use frequently.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;1)Managed Beans &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;It represents a Java bean that will be instantiated dynamically at the run time by JSF container.We can achive inversion of control in JSF.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Ex:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Class User{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;private String name;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;private String Address;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;//setters and getters for both properties&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;u&gt;Declaration in faces-config.xml&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;managed-bean&amp;gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;       &amp;lt;managed-bean-name&amp;gt;Userbean&amp;lt;/managed-bean-name&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;       &lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;managed-bean-class&amp;gt;User&amp;lt;/managed-bean-class&amp;gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;       &lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;managed-bean-scope&amp;gt;request&amp;lt;/managed-bean-scope&amp;gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;/managed-bean&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Now I can use the bean named &quot;Userbean&quot; in my JSF application at    any time. This is done by using JSF&#39;s Expression Language. For example to bind    a JSF user interface component (UI Component) to one of the properties of my    Userbean, I use the expression #{Userbean.name} as a value argument to    a JSF UI Component. Here is an example of binding the firstName property of    the bean to a JSF inputText (UIInput) UI Component.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The scope specifies the lifetime that bean. &lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; &amp;lt;h:inputText value=&quot;&lt;b&gt;#{Userbean.name}&lt;/b&gt;&quot;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;So now upon any form submissions the value entered into the input text field    will be applied to the property of my Java Bean.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;2)Navigation rule&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;It is a place where all the navigation&#39;s in the jsf application to be declared like to what jsp has to be rendered&amp;nbsp; for&amp;nbsp; a specified output.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Ex:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;navigation-rule&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;     &amp;lt;from-view-id&amp;gt;/pages/login.jsp&amp;lt;/from-view-id&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;     &amp;lt;navigation-case&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;       &amp;lt;from-outcome&amp;gt;success&amp;lt;/from-outcome&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;       &amp;lt;to-view-id&amp;gt;/pages/gretting.jsp&amp;lt;/to-view-id&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;     &amp;lt;/navigation-case&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;     &amp;lt;navigation-case&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;       &amp;lt;from-outcome&amp;gt;failure&amp;lt;/from-outcome&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;       &amp;lt;to-view-id&amp;gt;/pages/login.jsp&amp;lt;/to-view-id&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;     &amp;lt;/navigation-case&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;   &amp;lt;/navigation-rule&amp;gt;  &lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;In the above rule login.jsp is a jsp page which can contain a button&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;or command link or any thing whose action parameter is bind with a method.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;b&gt;&amp;lt;h:commandButton action=&quot;#{Userbean.validateUser}&quot;  value=&quot;login&quot; /&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;If we click on the above button in the jsp page then it will search for the&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;validateUser() method in the UserBean i.e User class and execute that method.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;If the returned value is &quot;success&quot; then greeting.jsp is displayed.If it is &quot;failure&quot;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;then the same page gets displayed.Of course the same page gets rendered if the returned&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;value of the method doesn&#39;t match with any form-outcome.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; font-size: small;&quot;&gt;  &lt;/span&gt;&lt;/pre&gt;
&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;
&lt;/div&gt;
&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/3359582053715357756/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2009/11/internals-of-jsf.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/3359582053715357756'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/3359582053715357756'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2009/11/internals-of-jsf.html' title='Internals of JSF'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-805147553927515425</id><published>2009-11-21T04:10:00.000-08:00</published><updated>2009-11-27T23:58:28.572-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="advantages of jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="converting web application into jsf appliction"/><category scheme="http://www.blogger.com/atom/ns#" term="java server faces"/><category scheme="http://www.blogger.com/atom/ns#" term="setting up jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="start up jsf"/><title type='text'>SETTING UP JSF</title><content type='html'>&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;If you have knowledge on java web applications it is very easy to set up Java server faces application.If you have&amp;nbsp; normal web application follow the below steps to convert it into a jsf app.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;ol style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;An entry in the web application&#39;s &lt;b&gt;web.xml&lt;/b&gt; to process all the requests by JSF controller servlet called Faces Servlet and a certain URL pattern is specified.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;blockquote&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;servlet&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;servlet-name&gt;&amp;lt;!-- Faces Servlet --&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet-name&amp;gt;Faces Servlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet-class&amp;gt;javax.faces.webapp.FacesServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;load-on-startup&amp;gt; 1 &amp;lt;/load-on-startup&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/servlet&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Faces Servlet Mapping --&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet-name&amp;gt;Faces Servlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url-pattern&amp;gt;*.faces&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/servlet-mapping&amp;gt;&lt;br /&gt;
&lt;/servlet-name&gt;&lt;/span&gt;&lt;/servlet&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;servlet-mapping&gt;&lt;/servlet-mapping&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 . A JSF configuration file faces-config.xml, which allows for configuration of all elements of JSF&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; application.It is usually located in the web application&#39;s &lt;b&gt;WEB-INF/directory&lt;/b&gt;.We need to keep an entry int the web.xml.We will discuss the contents later.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;blockquote&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;context-param&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param-name&amp;gt;javax.faces.CONFIG_FILES&amp;lt;/param-name&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param-value&amp;gt;/WEB-INF/faces-config.xml&amp;lt;/param-value&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/context-param&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 . Keep the below jar files in &lt;b&gt;WEB-INF/lib&lt;/b&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Actual JSF libraries : &lt;b&gt;jsf-api.jar&lt;/b&gt; and &lt;b&gt;jsf-impl.jar&lt;/b&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Additional dependencies : &lt;b&gt;commons-beanutils.jar,commons-collections.jar,commons-digester.jar and commons-logging.jar&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;JSTL jar files : &lt;b&gt;jstl.jar and standard.jar&lt;/b&gt;. &lt;br /&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;With above steps our web application is properly configured for JSF.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Next step is to develop a view using JSF.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;ol style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Create a page HelloJSF.jsp in the web application.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Add the below lines in the jsp page to make it JSF compliance.These are core and html tag libraries from sun&#39;s reference implementation.&lt;br /&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;blockquote&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot; %&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3. In the body of the JSP,you must add a &lt;b&gt;&lt;f:view&gt;&lt;/f:view&gt;&lt;/b&gt; tag.This is the base UI component .All the jsf tags must be inside this view tag.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Following are the sample files of web.xml and a jsp page ::&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;u&gt;&lt;b&gt;Web.xml &lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;blockquote&gt;&lt;blockquote&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt; &lt;br /&gt;
&amp;lt;!DOCTYPE web-app PUBLIC &lt;br /&gt;
&amp;nbsp; &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot; &lt;br /&gt;
&amp;nbsp; &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&amp;gt; &lt;br /&gt;
&amp;lt;web-app&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;context-param&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param-name&amp;gt;javax.faces.CONFIG_FILES&amp;lt;/param-name&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param-value&amp;gt;/WEB-INF/faces-config.xml&amp;lt;/param-value&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/context-param&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Faces Servlet --&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet-name&amp;gt;Faces Servlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet-class&amp;gt;javax.faces.webapp.FacesServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;load-on-startup&amp;gt; 1 &amp;lt;/load-on-startup&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/servlet&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Faces Servlet Mapping --&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;servlet-name&amp;gt;Faces Servlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url-pattern&amp;gt;*.faces&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/servlet-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/web-app&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;blockquote&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;web-app&gt;&lt;servlet-mapping&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/servlet-mapping&gt;&lt;/web-app&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;u&gt;&lt;b&gt;JSP Page&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;blockquote&gt;&lt;blockquote&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot; %&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;html &amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;head&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;title&amp;gt;My First JSF Application&amp;lt;/title&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/head&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;body&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;f:view&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;h:outputText value=&quot;This is MY JSF..&quot;/&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;lt;/f:view&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/body&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;lt;/html&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;f:view&gt;&lt;br /&gt;
&lt;/f:view&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;Once the JSP is created then we need to deploy that application in server and enter the below URL in the browser.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;blockquote&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;http://localhost:8080/&lt;webappname&gt;/HelloJSF.faces&lt;/webappname&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;Note ::&amp;nbsp; We need to give the name as HelloJSF.faces eventhogh its exentsion is JSP to wake up the FacesServlet.The servlet container uses the servlet mapping rule to activate the JSF servlet,  which strips off the faces suffix and loads the HelloJSF.jsp  page.&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;This is all about a sample JSF application .we will discuss in depth in the later posts.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;!--Session data--&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/805147553927515425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2009/11/setting-up-jsf.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/805147553927515425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/805147553927515425'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2009/11/setting-up-jsf.html' title='SETTING UP JSF'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-288482872571525992</id><published>2009-11-21T02:59:00.000-08:00</published><updated>2009-11-27T21:44:31.395-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="advantages of jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="getting started jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="uses of jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="what jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="Why  jsf"/><title type='text'>Why &amp; What JSF?</title><content type='html'>&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;There are two technologies popular for developing web applications.They are ASP.net and J2EE.The major advantage of ASP over java is &lt;b&gt;Rapid development style&lt;/b&gt;.Of course JAVA has its own advantages like &lt;b&gt;scalability,portability,open source,platform independent&lt;/b&gt; etc.Despite of all these advantages java is falling behind because of is &lt;b&gt;Hard-Core coding style.&lt;/b&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;With the introduction of JSF, java brings up&lt;b&gt; Rapid user interface development&lt;/b&gt;.We can develop web applications in JSF as fast as ASP can do.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;u&gt;&lt;b&gt;Why JSF &lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;/div&gt;&lt;ol style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;li&gt;MVC for web applications&lt;/li&gt;
&lt;li&gt;Clean separation of roles like (page authors, application developers,component writers,application architects,tool vendors) &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Easy to use &lt;/li&gt;
&lt;li&gt; Extendable Component and Rendering architecture&lt;/li&gt;
&lt;li&gt; Support for client device independence&lt;/li&gt;
&lt;li&gt; Standard From SUN&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Huge vendor and industry support&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;JSP and Servlet&lt;/b&gt;&lt;br /&gt;
– No built-in UI component model&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Struts (I am not saying you should not use Struts)&lt;/b&gt;&lt;br /&gt;
– No built-in UI component model&lt;br /&gt;
– No built-in event model for UI components&lt;br /&gt;
– No built-in state management for UI components&lt;br /&gt;
– No built-in support of multiple renderers&lt;br /&gt;
– Not a standard (despite its popularity)&lt;/li&gt;
&lt;li&gt; Struts and JSF can be used together&lt;/li&gt;
&lt;/ol&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&lt;u&gt;&lt;b&gt;What JSF&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;blockquote&gt;&lt;b style=&quot;color: #6fa8dc;&quot;&gt;&lt;i&gt;It is a server side user interface component framework for Java technology-based web applications.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;If you know about swings then we can call JSF as Swing for server side applications.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;It is a component oriented and event driven framework         for web applications. JSF eases the development of GUI for web         applications. JSF allows the programmers to work with extensible user         interfaces like buttons, text boxes, check boxes etc... Programmer         writes the code for particular event such as button clicked. This makes         programming much easier and now the there is no need to write request         and response processing logic.&lt;br /&gt;
&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;!--Session data--&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/288482872571525992/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2009/11/why-what-jsf.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/288482872571525992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/288482872571525992'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2009/11/why-what-jsf.html' title='Why &amp; What JSF?'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4196701761409440230.post-763601746847866662</id><published>2009-11-21T01:57:00.000-08:00</published><updated>2009-11-21T03:04:34.429-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="getting started jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="java server faces"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf origin"/><title type='text'>ORIGIN OF JSF</title><content type='html'>&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
Before jsf was introduced there were many frameworks which gained popularity (Spring,Struts etc).All of them offered many benefits explicitly by following MVC2 approach.Despite of those benefits they&amp;nbsp; lacked something i.e a robust &lt;b&gt;user-interface-oriented framework&lt;/b&gt;.We need&amp;nbsp; better way to handle the view tier.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;To address this need,several leading software vendors including SUN,IBM,Oracle and BEA met through the Java Community Process in may 2001 and given&amp;nbsp; detailed specification for building J2EE thin client web applications whose primary goal is to provide a simple way to build user interfaces for java web applications.This result in Java Specification Request JSR #127.Here are the design goals of JSF taken from the java community process.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;ol style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;li&gt; Create a standard GUI component framework which can be leveraged by     development tools to make it easier for tool users to both create high     quality GUIs and manage the GUI&#39;s connections to application behavior.   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Define a set of simple lightweight Java base classes for GUI components,     component state, and input events. These classes will address GUI lifecycle     issues, notably managing a component&#39;s persistent state for the lifetime     of its page.   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Provide a set of common GUI components, including the standard HTML form     input elements. These components will be derived from the simple set of base     classes (outlined in #1) that can be used to define new components.   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Provide a JavaBeans model for dispatching events from client-side GUI     controls to server-side application behavior.   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Define APIs for input validation, including support for client-side     validation.   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Specify a model for internationalization and localization of the GUI.   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Automatic generation of appropriate output for the target client,     taking into account all available client configuration data, such as     browser version, etc.   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Automatic Generation of output containing required hooks for supporting     accessibility, as defined by WAI. &lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div id=&quot;refHTML&quot; style=&quot;font-family: Georgia,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;!--Session data--&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaagonist.blogspot.com/feeds/763601746847866662/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javaagonist.blogspot.com/2009/11/origin-of-jsf.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/763601746847866662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4196701761409440230/posts/default/763601746847866662'/><link rel='alternate' type='text/html' href='http://javaagonist.blogspot.com/2009/11/origin-of-jsf.html' title='ORIGIN OF JSF'/><author><name>Vamsi</name><uri>http://www.blogger.com/profile/17951008014807306953</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>