tag:blogger.com,1999:blog-77391844310991295142024-03-05T20:14:14.698-08:00ExtremeJavaRamesh Mandalahttp://www.blogger.com/profile/11012237413690387079noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-7739184431099129514.post-43784257588514263242014-05-10T04:35:00.000-07:002014-05-10T05:07:20.888-07:00Java ArrayList vs CopyOnWriteArrayList<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #252525; font-family: sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><b>ArrayList:</b></span></span><br />
<br style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;" />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">ArrayList is a basic implementation of List interface in Collection framework.It extends AbstractList. </span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">ArrayList supports dynamic array that can grow as needed.</span><br />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><br /></span>
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">Some of the important methods in ArrayList are</span><br />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><br /></span>
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">void add(int index,Object element):add the element at the specified index.</span><br />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">void add(Object element): Add the element at the end of the list.</span><br />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">void clear(): clears the list when called on the list.</span><br />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">Object remove(int index): Remove the element at the specified location</span><br />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><br /></span>
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">We need an iterator to iterate over the list. ArrayList iterator is fail-fast by design.That means as soon as the underlying data structure changes after creating iterator it will throw </span><b style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">java.util.ConcurrentModificationException.</b><br />
<b style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><br /></b>
<b style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><br /></b>
Internally when we create an array list, it will maintains a modCount variable which will keep track of the modification count and every time we use add, remove or trimToSize method, it increments. expectedModCount is the iterator variable that is initialized when we create iterator with same value as modCount. This explains why we don’t get exception if we use set method to replace any existing element.<br />
<br />
So basically iterator throws ConcurrentModificationException if list size is changed.<br />
<div>
<br /></div>
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Let's run the program to see </span></span><br />
<span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); color: #222222; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;"> package misc;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class CopyOnArrayListExample {
/**
* @param args
*/
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("James Gosling");
list.add("Brendan Eich");
list.add("Rod Johnson");
list.add("Gavin King");
list.add("Un Known");
Iterator<String> itr = list.iterator();
while (itr.hasNext()) {
String str = itr.next();
System.out.println(str);
if(str.equals("Un Known")) list.remove("Un Known");}
}
} </code></pre>
<span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">Output:</span><br />
<br style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;" />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">Exception in thread "main" java.util.ConcurrentModificationException</span><br />
<span class="Apple-tab-span" style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px; white-space: pre;"> </span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)</span><br />
<span class="Apple-tab-span" style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px; white-space: pre;"> </span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">at java.util.AbstractList$Itr.next(AbstractList.java:343)</span><br />
<span class="Apple-tab-span" style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px; white-space: pre;"> </span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">at misc.CopyOnArrayListExample.main(CopyOnArrayListExample.java:30)</span><br />
<br style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;" />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">As you can see, ArrayList iterator doesn't allow concurrent modification when we iterating.If we need to do concurrent modification then we need </span><span style="background-color: white; border: 0px; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px; margin: 0px; padding: 0px; vertical-align: baseline;">CopyOnWriteArrayList.</span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;"><br /></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;">Lets see CopyOnWriteArrayList in action.</span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;"><br /></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); color: #222222; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package misc;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class CopyOnArrayListExample {
/**
* @param args
*/
public static void main(String[] args) {
List<String> list = new CopyOnWriteArrayList<String>();
list.add("James Gosling");
list.add("Brendan Eich");
list.add("Rod Johnson");
list.add("Gavin King");
list.add("Un Known");
Iterator<String> itr = list.iterator();
while (itr.hasNext()) {
String str = itr.next();
System.out.println(str);
if(str.equals("Un Known")) list.remove("Un Known");}
}
} </code></pre>
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;"><br /></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;">In above code, we just changed the class definition from ArrayList to CopyOnWriteArrayList and see the output below.</span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;"><br /></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">James Gosling</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">Brendan Eich</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">Rod Johnson</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">Gavin King</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">Un Known</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;"><br /></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;">As you can see, the above code doesn't throw any exception as this one is thread safe variant of ArrayList.</span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;"><br /></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;">Few things about CopyOnWriteArrayList from official documentation</span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 15px; line-height: 24.299999237060547px;"><br /></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">A thread-safe variant of ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array.</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">This is ordinarily too costly, but may be more efficient than alternatives when traversal operations vastly outnumber mutations, and is useful when you cannot or don't want to synchronize traversals, yet need to preclude interference among concurrent threads. The "snapshot" style iterator method uses a reference to the state of the array at the point that the iterator was created. This array never changes during the lifetime of the iterator, so interference is impossible and the iterator is guaranteed not to throw ConcurrentModificationException. The iterator will not reflect additions, removals, or changes to the list since the iterator was created. Element-changing operations on iterators themselves (remove, set, and add) are not supported. These methods throw UnsupportedOperationException.</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;"><br /></span></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">All elements are permitted, including null.</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;"><br /></span></span><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"></span><span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;"></span></span>
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a CopyOnWriteArrayList happen-before actions subsequent to the access or removal of that element from the CopyOnWriteArrayList in another thread.</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;"><br /></span></span>
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;">Thanks for visiting my blog!!!!!!!!</span></span><br />
<span style="background-color: white; color: #333333; font-family: 'Open Sans', sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><span style="font-size: 15px; line-height: 24.299999237060547px;"><br /></span></span></div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-7739184431099129514.post-82559796398246196242014-05-10T02:36:00.002-07:002014-05-10T04:32:37.945-07:00Sample Programs for Java Interviews-Series 1<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Bubble Sort:</b><br />
<br />
<span style="color: #252525; font-family: sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;">Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Although the algorithm is simple, most of the other sorting algorithms are more efficient for large lists.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;">Bubble sort has worst-case and average complexity both О(n2), where n is the number of items being sorted. There exist many sorting algorithms with substantially better worst-case or average complexity of O(n log n). Even other О(n2) sorting algorithms, such as insertion sort, tend to have better performance than bubble sort. Therefore, bubble sort is not a practical sorting algorithm when n is large.</span></span><br />
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;"><br /></span></span>
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;">Sample Program:</span></span><br />
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;"><br /></span></span>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package sortings.BubbleSort;
public class BubbleSortExample {
public static void main(String a[]) {
int i;
int array[] = { 12, 9, 4, 99, 120, 1, 3, 10 };
bubble_srt(array, array.length);
System.out.print("Values after sorting: ");
for (i = 0; i < array.length; i++)
System.out.print(array[i] + " ");
}
public static void bubble_srt(int a[], int n) {
int i, j, t = 0;
for (i = 0; i < n; i++) {
for (j = 1; j < (n - i); j++) {
if (a[j - 1] > a[j]) {
t = a[j - 1];
a[j - 1] = a[j];
a[j] = t;
}
}
}
}
} </code></pre>
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;"><br /></span></span>
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;">Output:</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;">Values after sorting: 1 3 4 9 10 12 99 120</span></span><br />
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;"><br /></span></span>
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;"><br /></span></span>
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;"><b>Fibonacci Series:</b></span></span><br />
<span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><span style="color: #252525; font-family: sans-serif;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers. If the Fibonacci sequence is denoted F ( n ), where n is the first term in the sequence, the following equation obtains for n = 0, where the first two terms are defined as 0 and 1 by convention</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="font-size: 14px; line-height: 22.399999618530273px;"><span style="background-color: white; color: #252525; font-family: sans-serif;"></span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">F (0) = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ...</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Sample Program:</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.programming;
public class FibonocciExample {
/**
* @param args
*/
public static void main(String[] args) {
int n = 15;
int f1, f2 = 0, f3 = 1;
System.out.println(f2);
for (int i = 1; i <= n; i++) {
System.out.print(" "+f3);
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
}
} </code></pre>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Output: </span><span style="font-size: 14px; line-height: 22.399999618530273px;"> 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610</span></span><br />
<br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Fibonacci using <b>recursive</b> method:</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.programming;
public class FibonocciRecursive {
/**
* @param args
*/
public static long fib(long num) {
if (num <= 1) {
return num;
}
return fib(num - 1) + fib(num - 2);
}
public static void main(String[] args) {
long n = 15;
for (int i = 1; i <= n; i++) {
System.out.print(fib(i)+"");
}
}
} </code></pre>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Output: </span><span style="font-size: 14px; line-height: 22.399999618530273px;">1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 </span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><b>Reverse a Number:</b></span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><b><br /></b></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">This is a sample program to reverse a given integer number</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.misc;
/**
* @author RameshM
* A sample program for reversing a given integer number
*/
public class ReverseIntegerNumber {
public int reverseNumber(int number) {
int reverse = 0;
while (number != 0) {
reverse = (reverse * 10);
reverse = reverse + (number % 10);
number = number / 10;
}
return reverse;
}
public static void main(String a[]) {
ReverseIntegerNumber reverse = new ReverseIntegerNumber();
// Not handling the cases where the number is less than or equal to zero
// for brevity purposes.
System.out.println("Number after reversing: "
+ reverse.reverseNumber(14789));
}
} </code></pre>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span><span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Output:</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">98741</span></span><br />
<br />
<br />
Thanks for visiting my blog!!!!!!!!!<br />
<br />
<span style="color: #252525; font-family: sans-serif;"><span style="background-color: white; font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-27806704897968704452014-05-08T12:59:00.000-07:002014-05-10T04:36:22.259-07:00Design Patterns implementations in Java API<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 2; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 18pt;"><a href="http://en.wikipedia.org/wiki/Creational_pattern"><span style="color: #4a6b82;">Creational patterns</span></a> <o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Abstract factory</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods returning
the factory itself which in turn can be used to create another
abstract/interface type)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l21 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#newInstance%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.xml.parsers.DocumentBuilderFactory#newInstance()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l21 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newInstance%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.xml.transform.TransformerFactory#newInstance()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l21 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/xpath/XPathFactory.html#newInstance%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.xml.xpath.XPathFactory#newInstance()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Builder_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Builder</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods returning
the instance itself)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l10 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/StringBuilder.html#append%28boolean%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.StringBuilder#append()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(unsynchronized)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l10 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/StringBuffer.html#append%28boolean%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.StringBuffer#append()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(synchronized)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l10 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/nio/ByteBuffer.html#put%28byte%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.nio.ByteBuffer#put()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(also on</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/nio/CharBuffer.html#put%28char%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">CharBuffer</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/nio/ShortBuffer.html#put%28short%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">ShortBuffer</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/nio/IntBuffer.html#put%28int%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">IntBuffer</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/nio/LongBuffer.html#put%28long%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">LongBuffer</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/nio/FloatBuffer.html#put%28float%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">FloatBuffer</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/nio/DoubleBuffer.html#put%28double%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">DoubleBuffer</span></a> )<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l10 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/GroupLayout.Group.html#addComponent%28java.awt.Component%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.swing.GroupLayout.Group#addComponent()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l10 level1 lfo2; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All implementations of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Appendable.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.Appendable</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Factory_method_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Factory method</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods returning
an implementation of an abstract/interface type)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l2 level1 lfo3; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Calendar.html#getInstance%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Calendar#getInstance()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l2 level1 lfo3; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/ResourceBundle.html#getBundle%28java.lang.String%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.ResourceBundle#getBundle()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l2 level1 lfo3; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/text/NumberFormat.html#getInstance%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.text.NumberFormat#getInstance()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l2 level1 lfo3; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html#forName%28java.lang.String%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.nio.charset.Charset#forName()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l2 level1 lfo3; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/net/URLStreamHandlerFactory.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.net.URLStreamHandlerFactory#createURLStreamHandler(String)</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(Returns singleton object per protocol)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Prototype_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Prototype</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods returning
a</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">instance of itself with the
same properties)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l4 level1 lfo4; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#clone%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.Object#clone()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(the class has to implement</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Cloneable.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.Cloneable</span></a> )<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Singleton_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Singleton</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods returning
the</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">same</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">instance (usually of itself)
everytime)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l12 level1 lfo5; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#getRuntime%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.Runtime#getRuntime()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l12 level1 lfo5; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html#getDesktop%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.awt.Desktop#getDesktop()</span></a> <o:p></o:p></span></div>
<div align="center" class="MsoNormal" style="line-height: 16.65pt; margin-bottom: 18.7pt; text-align: center; vertical-align: baseline;">
<span style="font-family: Arial, sans-serif; font-size: 13pt;">
</span><br />
<hr align="center" noshade="" size="1" style="color: #dddddd;" width="100%" />
<span style="font-family: Arial, sans-serif; font-size: 13pt;">
</span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 2; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 18pt;"><a href="http://en.wikipedia.org/wiki/Structural_pattern"><span style="color: #4a6b82;">Structural patterns</span></a> <o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Adapter_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Adapter</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods taking an
instance of</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type and
returning an implementation of own/another abstract/interface type which</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">decorates/overrides</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">the given instance)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l22 level1 lfo6; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#asList%28T...%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Arrays#asList()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l22 level1 lfo6; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/InputStreamReader.html#InputStreamReader%28java.io.InputStream%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.io.InputStreamReader(InputStream)</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(returns a</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">Reader</span><span style="font-family: Arial, sans-serif; font-size: 13pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l22 level1 lfo6; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/OutputStreamWriter.html#OutputStreamWriter%28java.io.OutputStream%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.io.OutputStreamWriter(OutputStream)</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(returns a</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">Writer</span><span style="font-family: Arial, sans-serif; font-size: 13pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l22 level1 lfo6; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html#marshal%28BoundType%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.xml.bind.annotation.adapters.XmlAdapter#marshal()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html#unmarshal%28ValueType%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">#unmarshal()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Bridge_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Bridge</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods taking an
instance of</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type and
returning an implementation of own abstract/interface type which</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">delegates/uses</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">the given instance)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l1 level1 lfo7; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">None comes to mind yet. A fictive example would be</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">new LinkedHashMap(LinkedHashSet<K>, List<V>)</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">which returns an unmodifiable linked map which
doesn't clone the items, but</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> <i>uses</i> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">them. The</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#newSetFromMap%28java.util.Map%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Collections#newSetFromMap()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#singleton%28T%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">singletonXXX()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">methods however comes close.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Composite_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Composite</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods taking an
instance of</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">same</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type into a
tree structure)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l6 level1 lfo8; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/awt/Container.html#add%28java.awt.Component%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.awt.Container#add(Component)</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(practically all over Swing thus)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l6 level1 lfo8; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/component/UIComponent.html#getChildren%28%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.faces.component.UIComponent#getChildren()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(practically all over JSF UI thus)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Decorator_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Decorator</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods taking an
instance of</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">same</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type which
adds additional behaviour)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l13 level1 lfo9; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All subclasses of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.io.InputStream</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/OutputStream.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">OutputStream</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/Reader.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Reader</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/Writer.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Writer</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">have a constructor taking an instance of same
type.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l13 level1 lfo9; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Collections</span></a> ,
the</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#checkedCollection%28java.util.Collection,%20java.lang.Class%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">checkedXXX()</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#synchronizedCollection%28java.util.Collection%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">synchronizedXXX()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#unmodifiableCollection%28java.util.Collection%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">unmodifiableXXX()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">methods.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l13 level1 lfo9; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequestWrapper.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.servlet.http.HttpServletRequestWrapper</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponseWrapper.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">HttpServletResponseWrapper</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Facade_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Facade</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods which
internally uses instances of</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">independent abstract/interface types)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l18 level1 lfo10; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/context/FacesContext.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.faces.context.FacesContext</span></a> ,
it internally uses among others the abstract/interface types</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/lifecycle/Lifecycle.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">LifeCycle</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/application/ViewHandler.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">ViewHandler</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/application/NavigationHandler.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">NavigationHandler</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and many more without that the enduser has to
worry about it (which are however overrideable by injection).<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l18 level1 lfo10; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/context/ExternalContext.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.faces.context.ExternalContext</span></a> ,
which internally uses</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">ServletContext</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSession.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">HttpSession</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">HttpServletRequest</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">HttpServletResponse</span></a> ,
etc.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Flyweight_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Flyweight</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods returning
a cached instance, a bit the "multiton" idea)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l3 level1 lfo11; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#valueOf%28int%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.Integer#valueOf(int)</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(also on</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Boolean.html#valueOf%28boolean%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Boolean</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Byte.html#valueOf%28byte%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Byte</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Character.html#valueOf%28char%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Character</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Short.html#valueOf%28short%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Short</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Long.html#valueOf%28long%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">Long</span></a> )<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Proxy_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Proxy</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by creational methods which
returns an implementation of given abstract/interface type which in turn</span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">delegates/uses</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">a</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">implementation of given abstract/interface
type)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l11 level1 lfo12; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Proxy.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.reflect.Proxy</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l11 level1 lfo12; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/rmi/package-summary.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.rmi.*</span></a> ,
the whole API actually.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; vertical-align: baseline;">
<sub><span style="border: 1pt none windowtext; font-family: Arial, sans-serif; font-size: 8.5pt; padding: 0in;">The
Wikipedia example is IMHO a bit poor, lazy loading has actually completely
nothing to do with the proxy pattern at all.</span></sub><span style="font-family: Arial, sans-serif; font-size: 13pt;"><o:p></o:p></span></div>
<div align="center" class="MsoNormal" style="line-height: 16.65pt; margin-bottom: 18.7pt; text-align: center; vertical-align: baseline;">
<span style="font-family: Arial, sans-serif; font-size: 13pt;">
</span><br />
<hr align="center" noshade="" size="1" style="color: #dddddd;" width="100%" />
<span style="font-family: Arial, sans-serif; font-size: 13pt;">
</span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 2; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 18pt;"><a href="http://en.wikipedia.org/wiki/Behavioral_pattern"><span style="color: #4a6b82;">Behavioral patterns</span></a> <o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Chain of responsibility</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods which
(indirectly) invokes the same method in</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">another</span></i></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">implementation of</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">same</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type in a queue)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l7 level1 lfo13; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/logging/Logger.html#log%28java.util.logging.Level,%20java.lang.String%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.logging.Logger#log()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l7 level1 lfo13; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/Filter.html#doFilter%28javax.servlet.ServletRequest,%20javax.servlet.ServletResponse,%20javax.servlet.FilterChain%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.servlet.Filter#doFilter()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Command_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Command</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods in an
abstract/interface type which invokes a method in an implementation of a</span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type which
has been</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">encapsulated</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">by the command implementation
during its creation)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l15 level1 lfo14; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All implementations of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Runnable.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.Runnable</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l15 level1 lfo14; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All implementations of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/Action.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.swing.Action</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Interpreter_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Interpreter</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods returning
a</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">structurally</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">different instance/type of the
given instance/type; note that parsing/formatting is not part of the pattern,
determining the pattern and how to apply it is)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l14 level1 lfo15; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Pattern</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l14 level1 lfo15; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/text/Normalizer.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.text.Normalizer</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l14 level1 lfo15; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All subclasses of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/text/Format.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.text.Format</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l14 level1 lfo15; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All subclasses of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/el/ELResolver.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.el.ELResolver</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Iterator_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Iterator</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods
sequentially returning instances of a</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">type from a queue)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l19 level1 lfo16; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All implementations of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Iterator.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Iterator</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(thus among others also</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Scanner.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Scanner</span></a> !).<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l19 level1 lfo16; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All implementations of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Enumeration.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Enumeration</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Mediator_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Mediator</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods taking an
instance of different abstract/interface type (usually using the command
pattern) which delegates/uses the given instance)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l17 level1 lfo17; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Timer.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Timer</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(all</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">scheduleXXX()</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">methods)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l17 level1 lfo17; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executor.html#execute%28java.lang.Runnable%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.concurrent.Executor#execute()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l17 level1 lfo17; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.concurrent.ExecutorService</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(the</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">invokeXXX()</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">submit()</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">methods)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l17 level1 lfo17; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ScheduledExecutorService.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.concurrent.ScheduledExecutorService</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(all</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">scheduleXXX()</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">methods)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l17 level1 lfo17; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Method.html#invoke%28java.lang.Object,%20java.lang.Object...%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.lang.reflect.Method#invoke()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Memento_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Memento</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods which
internally changes the state of the</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">whole</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">instance)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo18; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Date.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Date</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(the setter methods do that,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">Date</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">is internally
represented by a</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">long</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">value)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo18; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All implementations of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/Serializable.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.io.Serializable</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l0 level1 lfo18; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All implementations of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/component/StateHolder.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.faces.component.StateHolder</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Observer_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Observer (or Publish/Subscribe)</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods which
invokes a method on an instance of</span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">another</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type,
depending on own state)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l5 level1 lfo19; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Observer.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Observer</span></a> /<a href="http://docs.oracle.com/javase/6/docs/api/java/util/Observable.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Observable</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(rarely used in real world though)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l5 level1 lfo19; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All implementations of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/EventListener.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.EventListener</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(practically all over Swing thus)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l5 level1 lfo19; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSessionBindingListener.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.servlet.http.HttpSessionBindingListener</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l5 level1 lfo19; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSessionAttributeListener.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.servlet.http.HttpSessionAttributeListener</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l5 level1 lfo19; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/event/PhaseListener.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.faces.event.PhaseListener</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/State_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">State</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods which
changes its behaviour depending on the instance's state which can be controlled
externally)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l16 level1 lfo20; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/lifecycle/Lifecycle.html#execute%28javax.faces.context.FacesContext%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.faces.lifecycle.LifeCycle#execute()</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">(controlled by</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/faces/webapp/FacesServlet.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">FacesServlet</span></a> ,
the behaviour is dependent on current phase (state) of JSF lifecycle)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Strategy_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Strategy</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods in an
abstract/interface type which invokes a method in an implementation of a</span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type which
has been</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">passed-in</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">as method argument into the
strategy implementation)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l20 level1 lfo21; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/Comparator.html#compare%28T,%20T%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.Comparator#compare()</span></a> ,
executed by among others</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">Collections#sort()</span><span style="font-family: Arial, sans-serif; font-size: 13pt;">.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l20 level1 lfo21; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServlet.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.servlet.http.HttpServlet</span></a> ,
the</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">service()</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and all</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">doXXX()</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">methods take</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">HttpServletRequest</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">HttpServletResponse</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and the implementor has to process them (and not to get hold of
them as instance variables!).<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l20 level1 lfo21; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/Filter.html#doFilter%28javax.servlet.ServletRequest,%20javax.servlet.ServletResponse,%20javax.servlet.FilterChain%29"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.servlet.Filter#doFilter()</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Template_method_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Template method</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by behavioral methods which
already have a "default" behaviour definied by an abstract type)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l8 level1 lfo22; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All non-abstract methods of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.io.InputStream</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/OutputStream.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.io.OutputStream</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/Reader.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.io.Reader</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/io/Writer.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.io.Writer</span></a> .<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l8 level1 lfo22; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;">All non-abstract methods of</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/AbstractList.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.AbstractList</span></a> ,</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/AbstractSet.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.AbstractSet</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/util/AbstractMap.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">java.util.AbstractMap</span></a> .<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l8 level1 lfo22; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServlet.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.servlet.http.HttpServlet</span></a> ,
all the</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Consolas; font-size: 13pt;">doXXX()</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">methods by default sends a HTTP 405 "Method
Not Allowed" error to the response. You're free to implement none or any
of them.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 3; vertical-align: baseline;">
<b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><a href="http://en.wikipedia.org/wiki/Visitor_pattern"><span style="color: #4a6b82; mso-bidi-font-size: 11.0pt;">Visitor</span></a> </span></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"> </span></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">(recognizeable by two</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">different</span></i></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface types which has methods
definied which takes each the</span></sub></b><b><sub><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;"> </span></sub></b><b><i><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt;">other</span></i></b><b><sub><span style="border: 1pt none windowtext; font-family: 'Trebuchet MS', sans-serif; font-size: 9.5pt; padding: 0in;">abstract/interface type; the
one actually calls the method of the other and the other executes the desired
strategy on it)</span></sub></b><b><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 14pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l9 level1 lfo23; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/lang/model/element/AnnotationValue.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.lang.model.element.AnnotationValue</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/lang/model/element/AnnotationValueVisitor.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">AnnotationValueVisitor</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 28.05pt; margin-right: 0in; margin-top: 0in; mso-list: l9 level1 lfo23; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/lang/model/element/Element.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.lang.model.element.Element</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/lang/model/element/ElementVisitor.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">ElementVisitor</span></a> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 16.65pt; margin-bottom: 4.7pt; margin-left: 28.05pt; margin-right: 4.7pt; margin-top: 0in; mso-list: l9 level1 lfo23; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 10pt;">·<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span dir="LTR"></span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/lang/model/type/TypeMirror.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">javax.lang.model.type.TypeMirror</span></a> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;">and</span><span style="font-family: Arial, sans-serif; font-size: 13pt;"> </span><span style="font-family: Arial, sans-serif; font-size: 13pt;"><a href="http://docs.oracle.com/javase/6/docs/api/javax/lang/model/type/TypeVisitor.html"><span style="color: #4a6b82; font-family: Consolas; mso-bidi-font-family: "Courier New"; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;">TypeVisitor</span></a> <o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p><br /></o:p></div>
<div class="MsoNormal">
I found this in stackoverflow and thought of sharing and keep it for my future reference</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Courtesy: BalusC</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
You can see the complete discussion at the below url</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
http://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns/2707195#2707195</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Thanks for visiting my blog.....</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-39024581630429266642014-05-05T13:14:00.000-07:002014-05-06T01:12:31.759-07:00Overview of SQL Views and Materialized Views<div dir="ltr" style="text-align: left;" trbidi="on">
What is a <b>View</b>?<br />
<br />
A View is virtual table and it is built by selecting data from one or more tables.A view can be accessed by using the SELECT statement as though it is like a normal table.Changes applied to the data in a relevant underlying table(s) are reflected in the data shown in subsequent queries of the view.A view can contain all columns of a table or few columns as desired.<br />
<br />
You can even add SQL functions, WHERE and JOIN statements to a view and present the data as if the data were coming from one single table.<br />
<br />
Note: A view always shows up to date data.Every time you select a view it fetches the data again from the underlying base table(s) which is not the case with Materialized View(we will see shortly what is Materialized View)<br />
<br />
Why we use View?<br />
<br />
1)We can use Views as security mechanisms in databases.We can restrict some columns or data to the users.<br />
<br />
E.g.:Let's say you have a table called Employees, and it has columns like salary and age.You don't want everyone with access to the database to be able to see those columns, so you can create a view called Employee_Info which doesn't select those columns, and deny access to the base table to the users (either by placing them in specific roles/groups and denying access that way, or issuing explicit DENY statements to each user). This way, users don't even have to know that there is a table with more information behind the scenes.<br />
<br />
2)Views can join multiple tables into a single virtual table.<br />
<br />
3)Views take very little space to store.The database contains only the definition of a view, not a copy of all the data that it presents.<br />
<br />
4)Database complexity is hidden<br />
<br />
<br />
Lets see how to create Views<br />
<br />
Database Views can be created using CREATE VIEW statement.<br />
<br />
CREATE VIEW view_name AS<br />
SELECT column1, column2, column3.....<br />
FROM table_name<br />
WHERE [condition];<br />
<br />
<br />
E.g.:<br />
<br />
CREATE VIEW EMPLOYEE_INFO AS<br />
SELECT emp_id, emp_name,emp_age<br />
FROM EMPLOYEES<br />
WHERE emp_id=844;<br />
<br />
We can query the created view like a normal select statement<br />
<br />
SELECT * FROM EMPLOYEE_INFO;<br />
<br />
<br />
Updating a View:<br />
<br />
You can update a view with the following command<br />
<br />
CREATE OR REPLACE VIEW view_name AS<br />
SELECT column_name(s)<br />
FROM table_name<br />
WHERE condition;<br />
<br />
Dropping a View:<br />
<br />
Once a SQL VIEW has been created, you can drop it with the SQL DROP VIEW Statement.<br />
<br />
DROP VIEW view_name;<br />
<br />
Let's see what is <b>Materialized Views:</b><br />
<b><br /></b>
Why we need Materialized Views<br />
<br />
Sometimes there would be a need for a huge query with many join operations between more than 10-20 tables containing millions of records and many WHERE conditions. Especially in a data warehousing environment or for reporting purposes. In such conditions, running the query each time whenever required is not a feasible option. So, there should be a technique to store the data such that we should run the query only if there is a change in data in the underlying tables There comes the usage of a materialized views as they can store the data they have queried.<br />
<br />
Materialized Views are similar to normal Views except in which the query result is cached as a concrete table.This enables much more efficient access, at the cost of some data being potentially out of date. It is most useful in data warehousing scenarios, where frequent queries of the actual base tables can be extremely expensive.<br />
<br />
Materialized views can be set to refresh manually, on a set schedule, or based on the database detecting a change in data from one of the underlying tables.<br />
<br />
How to create MV's<br />
<br />
CREATE MATERIALIZED VIEW <MV_NAME><br />
REFRESH FAST START WITH SYSDATE<br />
NEXT SYSDATE + 1<br />
AS SELECT * FROM <table_name>;<br />
<br />
E.g.:<br />
<br />
CREATE MATERIALIZED VIEW MV_EMPLOYEES_INFO<br />
REFRESH FAST START WITH SYSDATE<br />
NEXT SYSDATE + 1<br />
AS SELECT * FROM EMPLOYEES;<br />
<br />
Selecting from Materialized View<br />
<br />
Since this MV is similar to a physical table you can use SELECT statements normally like shown below<br />
<br />
SELECT emp_id,emp_name from MV_EMPLOYEES_INFO;<br />
<br />
Dropping Materialized View<br />
<br />
DROP MATERIALIZED VIEW MV_EMPLOYEES_INFO PRESERVE TABLE;<br />
<br />
<br />
Thanks for visiting my blog!!!!!!!!!<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-61935747994040149322014-05-02T14:56:00.002-07:002014-05-12T01:48:48.325-07:00Chain of responsibility design pattern<div dir="ltr" style="text-align: left;" trbidi="on">
Before dive into the details, let me explain a real time use case for using Chain of responsibility design pattern.<br />
<br />
Lets say you are working on a online internet banking solution.What are the typical actions take place after you submit the transaction(It may be a fund transfer or bill payment or remittance to another country)? The money will be debited(Need to update the balance in database),send an xml to back office(probably your front end and back office in different technologies and you use xml consisting of your transaction details to communicate with the back office where the real calculations will take place) and a SMS update to customer's registered mobile and similarly an EMAIL to customer's registered email id. These are all different actions and different components need to process these actions.We can chain these actions and process the request one by one.Lets say if a particular end user not registered for SMS or EMAIL then he wont be getting these alerts as this pattern allow us to skip those requests.<br />
<br />
Another use case, lets say in a bank an associate branch manager can approve an amount of 1 lakh loan and any amount more than that requires a branch manager's approval where he can approve 10 lakhs and if its more than that amount its require an approval from the director.So the client doesn't know who actually process the request.<br />
<br />
One of the most famous use case for chain of responsibility design pattern is ATM.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9aFT8Nw6zi1cxf66lX5QWtBRU1SpqeGmvMMtdXnSOAwVhs8S60JtGnDEhe98PGcEtl-KpmNoA4E512MDUU3AOsbROtOLxseewO02uwx_bbhM1tKLPBAx7KiHIJ5kILzafaA6gfl4w3MU/s1600/ATM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9aFT8Nw6zi1cxf66lX5QWtBRU1SpqeGmvMMtdXnSOAwVhs8S60JtGnDEhe98PGcEtl-KpmNoA4E512MDUU3AOsbROtOLxseewO02uwx_bbhM1tKLPBAx7KiHIJ5kILzafaA6gfl4w3MU/s1600/ATM.png" /></a></div>
<br />
<br />
If you are having similar kind of above use cases, chain of responsibility is your best bet.<br />
<br />
Chain of responsibility is a behavioral design pattern. In this pattern a set of handlers are chained to handle a request coming from the client object.The first handler process the request and its forwarded to the next handler in the chain.Please note if the first handler process the request or unable to process the request will forwarded to the to the next handler.This process will continue till it reaches the last handler in the chain.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjorH6HV6bHHegn9f5d6WyRMnANTVEfz0Vo2a6HDh-LG5XnkSkcruGJfj7EHF3GVwedWzGY3wSxV15a4w8Y1A5gS35qWrgWJiiC2_EoOWSQAOZZ6ONDv3W3dZaxIsZ6dRwQR3fstZsxYzic/s1600/chainofresponsibility.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjorH6HV6bHHegn9f5d6WyRMnANTVEfz0Vo2a6HDh-LG5XnkSkcruGJfj7EHF3GVwedWzGY3wSxV15a4w8Y1A5gS35qWrgWJiiC2_EoOWSQAOZZ6ONDv3W3dZaxIsZ6dRwQR3fstZsxYzic/s1600/chainofresponsibility.png" height="138" width="400" /></a></div>
<br />
<br />
As depicted in the above image, the client object only knows about the abstract handler and does't aware which concrete handler really process its request.This way this pattern provide loose coupling between the objects.You can add new handlers with out actually touching your client code when a new requirement comes.<br />
<br />
Let's see Chain of responsibility design pattern in action.<br />
<br />
In this example we create a chain of different handlers such that depending on the handler type being passed to the handler, the handler has to decide whether its going to process the request or pass the request to its successor handle to take action. The handlers we have are Database Handler, SMS Handler, EMAIL Handler and XML Handler. The handler logic in each of these handler doesn’t process any real logic instead it just prints out a message stating who is handing the request for which request. We then populate handler codes of different handlers into a list and then iterate through them passing the handle code to the first handler in the list.<br />
<br />
Our Base Handler<br />
<br />
<pre class="line-pre" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 16.799999237060547px; padding: 0px; width: 744px;"><div class="line" id="file-ramesh-java-LC1" style="box-sizing: border-box;">
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.chainOfResponsibility;
/**
* @author RameshM
*
*/
public class BaseHandler {
private BaseHandler successor;
public void process(String serviceName) {
if (getSuccessor() != null) {
getSuccessor().process(serviceName);
} else {
System.out.println("Unable to find the correct Service Handler: "
+ serviceName);
}
}
BaseHandler getSuccessor() {
return successor;
}
void setSuccessor(BaseHandler successor) {
this.successor = successor;
}
} </code></pre>
</div>
</pre>
We would now create different handlers for handle different request namely-Database handler, SMS handler, EMAIL handler and XML Handler and these extend from the Base Handler class and override the process method. I have kept the implementation of different handlers simple and these methods evaluate if the request has the string type they are looking for. If a particular handler is unable to process the request i.e. the request type is not what it is looking for, then the parent method handles such requests. The handler method in the parent class just invokes the same method on the successor handler.<br />
<br />
DatabaseHandler which handles actions related to Database.<br />
<br />
<pre class="line-pre" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 16.799999237060547px; padding: 0px; width: 744px;"><div class="line" id="file-ramesh-java-LC1" style="box-sizing: border-box;">
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.chainOfResponsibility;
public class DatabaseHandler extends BaseHandler {
public DatabaseHandler(BaseHandler successor) {
this.setSuccessor(successor);
}
@Override
public void process(String serviceName) {
if (serviceName.equals("DATABASE")) {
System.out.println("DATABASE Handler handling the request: "
+ serviceName);
} else {
super.process(serviceName);
}
}
} </code></pre>
</div>
<div class="line" id="file-ramesh-java-LC20" style="box-sizing: border-box;">
</div>
</pre>
Email Handler handles request related to Email actions<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.chainOfResponsibility;
public class EmailHandler extends BaseHandler {
public EmailHandler(BaseHandler successor) {
this.setSuccessor(successor);
}
@Override
public void process(String serviceName) {
if (serviceName.equals("EMAIL")) {
System.out.println("EMAIL Handler handling the request: "
+ serviceName);
} else {
super.process(serviceName);
}
}
} </code></pre>
<pre class="line-pre" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 16.799999237060547px; padding: 0px; width: 744px;"><div class="line" id="file-ramesh-java-LC1" style="box-sizing: border-box;">
<span class="kn" style="box-sizing: border-box; font-weight: bold;">
</span></div>
</pre>
SMS handler handles for SMS related actions<br />
<pre class="line-pre" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 16.799999237060547px; padding: 0px; width: 744px;"><div class="line" id="file-ramesh-java-LC1" style="box-sizing: border-box;">
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.chainOfResponsibility;
/**
* @author RameshM
*
*/
public class SMSHandler extends BaseHandler {
public SMSHandler(BaseHandler successor) {
this.setSuccessor(successor);
}
@Override
public void process(String serviceName) {
if (serviceName.equals("SMS")) {
System.out.println("SMS Handler handling the request: "
+ serviceName);
} else {
super.process(serviceName);
}
}
} </code></pre>
</div>
</pre>
XML Handler handles XML related actions<br />
<pre class="line-pre" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 16.799999237060547px; padding: 0px; width: 744px;"><div class="line" id="file-ramesh-java-LC1" style="box-sizing: border-box;">
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.chainOfResponsibility;
public class XMLHandler extends BaseHandler {
@Override
public void process(String serviceName) {
if (serviceName.equals("XML")) {
System.out.println("XML Handler handling the request: "
+ serviceName);
} else {
super.process(serviceName);
}
}
} </code></pre>
</div>
</pre>
Now that we have all the handlers setup, we need to create a chain of handlers. In this example the chain we create is: Database handler-> SMS handler -> Email handler-> XML handler.Lets see the code for the client class which creates a list of handler codes and then creates the chain which I just described.<br />
<pre class="line-pre" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 16.799999237060547px; padding: 0px; width: 744px;"><div class="line" id="file-ramesh-java-LC1" style="box-sizing: border-box;">
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package chainOfResponsibility;
import java.util.LinkedList;
import java.util.List;
public class ChainOfResponsibilityDemo {
/**
* @param args
*/
public static void main(String[] args) {
List<String> handlers = populateServiceNames();
// No successor for this handler since this is the last in the chain
BaseHandler xmlHandler = new XMLHandler();
// xml handler is the successsor for email handler
BaseHandler emailHandler = new EmailHandler(xmlHandler);
// email handler is the successor for sms handler
BaseHandler smsHandler = new SMSHandler(emailHandler);
// database handler is the first handler in the chain which will invoke
// SMS handler
BaseHandler dbHandler = new DatabaseHandler(smsHandler);
for (String str : handlers) {
dbHandler.process(str);
}
}
private static List<String> populateServiceNames() {
List<String> handlerCodes = new LinkedList<String>();
handlerCodes.add("DATABASE");
handlerCodes.add("SMS");
handlerCodes.add("NOHANDLER");
handlerCodes.add("EMAIL");
handlerCodes.add("XML");
return handlerCodes;
}
} </code></pre>
</div>
</pre>
Lets run the program and see the output.As you can see the main program, the client only knows the base handler and it forward the request to first handler in the chain and the chain continue till it reaches the last handler.As you can see i added a handler code "<span style="background-color: white; color: #dd1144; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 16.799999237060547px; white-space: pre;">NOHANDLER</span>" in list of handler codes just to make sure that if there is not handler specified ,then our base handler handles and prints there is no handler available to process the request. All done... lets see the output below...<br />
<br />
Output:<br />
<br />
<span style="color: blue;">DATABASE Handler handling the request: DATABASE</span><br />
<span style="color: blue;">SMS Handler handling the request: SMS</span><br />
<span style="color: blue;">Unable to find the correct Service Handler: NOHANDLER</span><br />
<span style="color: blue;">EMAIL Handler handling the request: EMAIL</span><br />
<span style="color: blue;">XML Handler handling the request: XML</span><br />
<br />
Disadvantages using Chain of responsibility pattern.<br />
<br />
The chain should be created carefully otherwise there might be a case where the handler might not pass the request to the next handler or there wont be any handlers to process the request.<br />
<br />
Implementation of this pattern in Java and Java EE API<br />
<br />
java.util.logging.Logger#log()<br />
javax.servlet.Filter#doFilter()<br />
<br />
<br />
Thanks for visiting my blog!!!!!!!!!!<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-86114380829997049002014-05-02T08:16:00.002-07:002014-05-02T08:16:27.216-07:00Database Normalization<div dir="ltr" style="text-align: left;" trbidi="on">
<b style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.399999618530273px;">Normalization</b><span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.399999618530273px;"> is the way in which we organize the data </span><span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.399999618530273px;">of database</span><span style="background-color: white;"><span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"> to minimize redundancy(duplicate data). </span></span></span><span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.399999618530273px;">Normalization usually involves decomposing a large table into smaller tables and defining relationships between them(primary key and foreign key).</span><br />
<span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.399999618530273px;"><br /></span>
<span style="background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.399999618530273px;">The main objective of normalization is to eliminate redundancy and undesired </span><span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">characteristics like creation,updation and deletion dependencies and ensuring data is logically stored.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">First Normal Form(1NF): </span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Rules:</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">1)Table should consist of a primary key(uniquely identifies a row in the table)</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">2)Table shouldn't consists of duplicate data.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">3)The values in a column should be of the same type.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">4)The order of the rows should be insignificant.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">5)Each column must be unique</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Second Normal Form(2NF):</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Rules:</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">1)It should meet all the rules defined for 1NF and there shouldn't be no partial dependencies of any of the columns on the primary key.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">To put the above point in another way, relations that have a single attribute for a key are automatically in 2NF.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">E.g.: instead of having a primary key (customer_id, orders_id) for customer_orders table, we can divided the table into separate tables so that each table has a separate primary key (customer_id) for customer table and (orders_id) for orders table.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Third Normal Form(3NF):</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Rules:</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">1)It should meet all the rules defined for 2NF and all the non primary fields should be dependent on primary key.</span></span><br />
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;"><br /></span></span>
<span style="color: #252525; font-family: sans-serif;"><span style="font-size: 14px; line-height: 22.399999618530273px;">Thanks for visiting my blog!!!!!!!!!!</span></span></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-68427811996901398822014-05-02T04:01:00.000-07:002014-05-02T05:49:38.326-07:00Select nth highest salary<div dir="ltr" style="text-align: left;" trbidi="on">
This is very popular interview question asked for beginners to experienced programmers.<br />
<br />
I will explain how we can find the nth highest salary using Oracle row_number() analytic function.<br />
<br />
Let me first explain what is row_number() analytic function.<br />
<br />
row_number() assign a unique number to each row to which it applied based on the order by clause(either descending order or ascending order).<br />
<br />
By nesting a subquery using ROW_NUMBER inside a query that retrieves the ROW_NUMBER values for a specified range, you can find a precise subset of rows from the results of the inner query.<br />
<br />
Query:<br />
<br />
<pre style="background-color: #eeeeec; border: 1px solid rgb(186, 189, 182); font-size: 13px; line-height: 1em; padding: 4px; text-align: justify; white-space: pre-wrap;"><span class="k" style="color: green; font-weight: bold;">SELECT</span> <span class="o" style="color: #666666;">*</span>
<span class="k" style="color: green; font-weight: bold;">FROM</span>
<span class="p">(</span> <span class="k" style="color: green; font-weight: bold;">SELECT</span> <span class="n">employee</span><span class="p">.</span><span class="o" style="color: #666666;">*</span><span class="p">,</span>
<span class="n">row_number</span><span class="p">()</span> <span class="n">over</span> <span class="p">(</span>
<span class="k" style="color: green; font-weight: bold;">ORDER</span> <span class="k" style="color: green; font-weight: bold;">BY</span> employee.<span class="n">salary</span> <span class="k" style="color: green; font-weight: bold;">DESC</span><span class="p">)</span> <span class="n">rownumber</span>
<span class="k" style="color: green; font-weight: bold;">FROM</span> <span class="n">employee</span> <span class="n">employee</span><span class="p">)</span>
<span class="k" style="color: green; font-weight: bold;">WHERE</span> <span class="n">rownumber</span><span class="o" style="color: #666666;">=n</span><span class="p">;</span></pre>
<div>
<span class="p"><br /></span></div>
<div style="text-align: justify;">
<span class="p"><br /></span></div>
<div style="text-align: justify;">
<span class="p">As you see the above query, first we are using the inner query which assign a number for each row starting from 1. Since we are doing order by desc for the salary, the salaries will be order by highest to smallest.</span></div>
<div style="text-align: justify;">
<span class="p"><br /></span></div>
<div style="text-align: justify;">
<div>
Since the rows are arranged in descending order, the row with the highest salary will have a 1 for the row number.Since we know the row numbers we just pass the row number(n) and it will compare and return the result.</div>
<div>
<br /></div>
<div>
That's all about selecting the nth highest salary.</div>
<div>
<br /></div>
<div>
Thanks for visiting my blog!!!!!</div>
</div>
<div style="text-align: justify;">
<span class="p"><br /></span></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-34747735140796881182014-05-01T22:55:00.001-07:002014-05-01T22:55:28.798-07:00Java 8 features<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
1) Lambda Expressions, a new language feature, has been introduced in this release. They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.</div>
<div>
<br /></div>
<div>
2) Method references provide easy-to-read lambda expressions for methods that already have a name.</div>
<div>
<br /></div>
<div>
3)Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces.</div>
<div>
<br /></div>
<div>
4) Repeating Annotations provide the ability to apply the same annotation type more than once to the same declaration or type use.</div>
<div>
<br /></div>
<div>
5) Type Annotations provide the ability to apply an annotation anywhere a type is used, not just on a declaration. Used with a pluggable type system, this feature enables improved type checking of your code.</div>
<div>
<br /></div>
<div>
6) Improved type inference.</div>
<div>
<br /></div>
<div>
7) Method parameter reflection.</div>
<div>
<br /></div>
<div>
8) Classes in the new java.util.stream package provide a Stream API to support functional-style operations on streams of elements. The Stream API is integrated into the Collections API, which enables bulk operations on collections, such as sequential or parallel map-reduce transformations.</div>
<div>
<br /></div>
<div>
9) Performance Improvement for HashMaps with Key Collisions</div>
<div>
<br /></div>
<div>
10) Date-Time Package - a new set of packages that provide a comprehensive date-time model.</div>
<div>
<br /></div>
<div>
Concurrency</div>
<div>
<br /></div>
<div>
11) Classes and interfaces have been added to the java.util.concurrent package.</div>
<div>
<br /></div>
<div>
12 )Methods have been added to the java.util.concurrent.ConcurrentHashMap class to support aggregate operations based on the newly added streams facility and lambda expressions.</div>
<div>
<br /></div>
<div>
13)Classes have been added to the java.util.concurrent.atomic package to support scalable updatable variables.</div>
<div>
<br /></div>
<div>
14) Methods have been added to the java.util.concurrent.ForkJoinPool class to support a common pool.</div>
<div>
<br /></div>
<div>
15) The java.util.concurrent.locks.StampedLock class has been added to provide a capability-based lock with three modes for controlling read/write access.</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-81078831076181247352014-05-01T12:36:00.002-07:002014-05-28T03:32:58.226-07:00Factory Design Pattern<div dir="ltr" style="text-align: left;" trbidi="on">
What is the most preferred way of creating an object in Java? no prizes for guessing :-) The answer is simple, using a new operator right? But what if i need to change the way an object is constructed and this object is created using new operation in lot of classes.I need to change in all classes right?<br />
<br />
Well, if you are not using any dependency injection frameworks like Spring, its better to use factory pattern (also known as factory method pattern)for constructing objects.<br />
<br />
Its a creational design pattern.A factory is a java class which encapsulate the object creation.The composing classes doesn't know how the objects created.A factory class instantiates and returns a particular type of object based on the data passed to the factory.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT9m51YkomcVfdxAEBVJb-EorxtAQQldWOkrr3JpehRWCsT2VS9lzgacDsCGnkN_JEeAkpJwD4Pq14aPmyIstCQ1mBzentGcg19QMnCaVzldDfp-baJE7OsFlDcKIkt3hTzI0G-7uQ-490/s1600/FactoryDesignPatternUML.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT9m51YkomcVfdxAEBVJb-EorxtAQQldWOkrr3JpehRWCsT2VS9lzgacDsCGnkN_JEeAkpJwD4Pq14aPmyIstCQ1mBzentGcg19QMnCaVzldDfp-baJE7OsFlDcKIkt3hTzI0G-7uQ-490/s1600/FactoryDesignPatternUML.png" height="246" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
Lets create a abstract class Account which declares two methods deposit and withdraw.<br />
<br />
Account.java<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.designPatterns;
public abstract class Account {
public abstract long deposit(long depositAmount);
public abstract long withdraw(long withdrawAmount);
} </code></pre>
<br />
We have two concrete implementations of Account, named SavingsAccount,java and CurrentAccount.java<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.designPatterns;
public class SavingsAccount extends Account {
public long deposit(long depositAmount) {
System.out.println("Inside Savings Account's deposit method");
long balance=1000;
if (depositAmount < 0) {
System.out.print("Invalid Amount!");
}
balance = balance + depositAmount;
System.out.println("Current Balance is "+balance);
return balance;
}
@Override
public long withdraw(long withdrawAmount) {
System.out.println("Inside Savings Account's withdraw method");
long balance =30000;
System.out.println("Your Balance is: " + balance);
if (withdrawAmount > balance) {
System.out.println("You do not have a sufficient balance to withdraw this amount!");
}
balance=balance-withdrawAmount;
return balance;
}
} </code></pre>
<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.designPatterns;
public class CurrentAccount extends Account {
public long deposit(long depositAmount) {
System.out.println("Inside Current Account's deposit method");
long balance=1000;
if (depositAmount < 0) {
System.out.print("Invalid Amount!");
}
balance = balance + depositAmount;
System.out.println("Current Balance is "+balance);
return balance;
}
@Override
public long withdraw(long withdrawAmount) {
System.out.println("Inside Current Account's withdraw method");
long balance =30000;
System.out.println("Your Balance is: " + balance);
if (withdrawAmount > balance) {
System.out.println("You do not have a sufficient balance to withdraw this amount!");
}
balance=balance-withdrawAmount;
return balance;
}
} </code></pre>
<br />
<br />
<br />
Now create a AccountFactory which returns either of these accounts based on our requirement.<br />
<br />
AccountFactory.java<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.designPatterns;
public class AccountFactory {
Account account;
public Account getAccount(String accountType) {
if (accountType.equals("savings")) {
account = new SavingsAccount();
} else if (accountType.equals("current")) {
account = new CurrentAccount();
}
return account;
}
} </code></pre>
<div>
<br /></div>
<div>
Now test the factory whether its returning the desired object.<br />
<br />
MainApp.java</div>
<div>
<br /></div>
<div>
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package ramesh.designPatterns;
public class MainApp {
/**
* @param args
*/
public static void main(String[] args) {
AccountFactory factory = new AccountFactory();
Account account = factory.getAccount("savings");
account.deposit(2000);
}
} </code></pre>
</div>
<br />
Here we requested to return the savings account object and we can confirm that we got the savings account object by seeing the output.<br />
<br />
Output:<br />
<br />
Inside Savings Account's deposit method<br />
Current Balance is 3000<br />
<br />
As you see the advantage of factory which decouple the creation of objects from composing class there is a disadvantages also.<br />
<br />
1) Factory class encapsulate the creation of similar objects.So if you need different objects you need to create different factories.<br />
2) The factory should be used for similar type of objects. If the classes doesn't extend common base class or interface they can not be used in a factory design template.<br />
<br />
Examples of Factory pattern in Java API<br />
<br />
<span style="color: #3d85c6;">java.util.Calendar#getInstance() </span><br />
<span style="color: #3d85c6;">java.util.ResourceBundle#getBundle() </span><br />
<span style="color: #3d85c6;">java.text.NumberFormat#getInstance() </span><br />
<span style="color: #3d85c6;">java.nio.charset.Charset#forName() </span><br />
<br />
<div>
That's all about Factory design pattern in Java.</div>
<div>
<br /></div>
<div>
Thanks for visiting my blog...</div>
<div>
</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-78475260173337850352014-05-01T04:59:00.001-07:002015-09-26T01:28:43.112-07:00Spring Transaction Management<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Understanding transactions: </b><br />
<br />
Lets say i would like to transfer 1000 rupees from my savings account to current account.If every thing goes well my 1000 rupees will be debited from savings account and it will be credited into my current account.What if my money debited but not credited into my current account? I am at loss right? So these actions should be wrapped in a transaction. A transaction is basically a unit of work, its "<b>all or nothing</b>".So if some problem happens when crediting the amount, the transaction should be rolled back as if these actions never happened.<br />
<br />
A transaction is characterized by 4 properties<br />
<br />
<b>1)Atomic:</b>Transactions are made of one more actions bundle into a single unit of work.Its all or nothing. Transaction will be successful only if all actions completed successfully otherwise transaction will be rolled back as if nothing has happened.<br />
<b>2)Consistent:</b> Once the transaction completed whether successfully or it was rolled back, the database should be in a consistent state no matter how many transactions happening concurrently. If a transaction triggers secondary actions like CASCADE and TRIGGERS those actions should also successful or the transaction fails.<br />
<b>3)Isolation: </b>In a multi threaded environment, multiple users will do different transactions concurrently.Isolation specifies when and how the changes implemented in an operation visible to other parallel operations. Transactions should be isolated from each other, preventing concurrent reads and<br />
writes to the same data from occurring. (Note that isolation typically involves locking rows and/or tables in a database.)<br />
<b>4)Durability: </b>Once the transaction has completed, the results of the transaction made permanent so that they survive any sort system crash.This involves storing the data in databases.<br />
<br />
Coming to Spring transaction management, Spring offers both programmatic transaction management and declarative transaction management.<br />
<br />
In this post, i will explain about the declarative transaction management.<br />
<br />
Whether we are using programmatic transaction management or declarative transaction management we need a Spring transaction manager to interface with a platform specific transaction implementation so that we are free from dealing directly with platform specific transaction implementations.<br />
<br />
Depends on underlying persistent mechanisms Spring supports different transaction managers.<br />
<br />
below are some of them<br />
<br />
1)HibernateTransactionManager<br />
2)JdoTransactionManager<br />
3)JtaTransactionManager<br />
<br />
Since my application persistence handled by Hibernate i am going to explain Spring Declarative Transaction Management using HibernateTransactionManager.I am explaining using the annotation base declarative transaction management<br />
<br />
We need to define the Spring's tx namespace and to use the @Transactional annotation.<br />
<br />
sample tx namespace declaration in spring application context<br />
<br />
http://www.springframework.org/schema/tx <br />
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"><br />
<br />
defining HibernateTransactionManager in application context xml<br />
<br />
<tx:annotation-driven transaction-manager="hibernateTransactionManager" /><br />
<br />
<bean class="org.springframework.orm.hibernate3.HibernateTransactionManager"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>id="hibernateTransactionManager"><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><property name="sessionFactory" ref="sessionFactory"></property><br />
</bean><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
<br />
The sessionFactory should be wired with HibernateSessionFactory.The HibernateTransactionManager delegates responsibility for transaction management to and org.Transaction object that it retrives from Hibernate session.If the transaction successfully completes it will call the commit() on the Transaction object,otherwise it will rollback() on the Transaction object.<br />
<br />
In Spring declarative transactions are defined with transaction attributes.These attributes define how a transaction policies should be applied to a method.<br />
<br />
These are<br />
1)Propagation<br />
2)Isolation<br />
3)Read-only<br />
4)Timeout<br />
5)Rollback rules<br />
<br />
Lets see what these attributes are up to<br />
<br />
<b>1)Propagation: </b>Propagation rules defines the transaction boundaries.Spring provides several rules to choose from<br />
<br />
<b>a)PROPAGATION_NEVER: </b>When we annotate our business method @Transactional with PROPAGATION_NEVER, it means this method shouldn't run in a transaction context.If an existing transaction is in progress then an exception will be thrown.<br />
<br />
<b>b)PROPAGATION_MANADATORY:</b> Indicates that the method must run with in a transaction.Other wise an exception will be thrown.<br />
<br />
<b>c)PROPAGATION_REQURIED: </b>Indicates that the method must run with in a transaction.If an existing transaction is not there then a new transaction will be started.<br />
<br />
<b>d)PROPAGATION_NESTED: </b>Indicates that the method must run with in an nested transaction if an existing transaction is in progress. The nested transaction can be committed or roll back individually from the enclosing transaction.If no existing transaction is present then it will behave like PROPAGATION_REQUIRED.So a new transaction will be started.<br />
<br />
<b>e)PROPAGATION_REQUIRES_NEW: </b>Indicates that the current transaction must run with in its own transaction.A new transaction will be started if an existing transaction in progress, the existing transaction will be suspended until this transaction completes.<br />
<br />
<b>f)PROPAGATION_SUPPORTS: </b>Indicates that the current method doesn't required a transnational context but will supports if an existing transaction in progress.<br />
<br />
<b>2)ISOLATION LEVELS:</b><br />
<br />
Isolation levels defines how much a transaction will be impacted by the other concurrent transactions.<br />
<br />
In a enterprise application, its possible that many transaction happens concurrently.While this is necessary we may lead to the following problems<br />
<br />
<b>1)Dirty Reads: </b>Lets say we have Transaction A and Transaction B.Imagine if transaction A reads the data and update the data but not committed the changes.Now Transaction B comes in and read the data and later Transaction A rolled back these changes.The data that Transaction B read is invalid now.This is called the Dirty Reads.<br />
<br />
<b>2)Nonrepeatable Reads: </b>Lets say Transaction A reads a row in the table.Now Transaction B came and it reads the same record, mean while Transaction A updates the same record.If Transaction B reads the same record again Transaction B gets a different data.This is called Non Repeatable Read problem.<br />
<br />
<b>3)Phantom Reads: </b>This is similar to Non Repeatable Read problem. These occur when a transaction A reads several rows, and then a concurrent transaction B inserts rows. Upon subsequent queries, the first transaction A finds additional rows that weren’t there before.<br />
<br />
In an ideal situation, the transaction completely isolated from other transaction.But this certainly have a dent on the application as this perfect isolation require locks on the record or complete table on the database.<br />
Since not operations require perfect isolation levels we can flexible with regard to the transaction isolation level.Spring supports the following transaction isolation levels.<br />
<br />
<b>a) ISOLATION_DEFAULT:</b>This will use the underlying isolation level of the database.<br />
<br />
<b>b)ISOLATION_READ_UNCOMMITTED:</b> Allows a transaction to read uncommitted data by another transaction.This may result in dirty reads, nonrepeatable reads and phantom reads.<br />
<br />
<b>c)ISOLATION_READ_COMMITTED:</b> Allows a transaction to read only committed data.But may result in nonrepeatable reads and phantom reads.<br />
<br />
<b>d)ISOLATION_SERIALIZABLE: </b>This is more strict of all these isolation levels.This will restrict dirty reads,non repeatable read and phantom reads.But this will be the slow the performance of the application as it needs to have a lock on the table.<br />
<br />
<br />
<b>3)READ ONLY: </b><br />
<br />
This transaction attribute can be applied to methods that you are intended to read some data.<br />
<br />
E.g.: You are just presenting few employees data to the end user.No updates required on these records(Read Only).<br />
<br />
When you declare this attribute, it may be possible that the underlying datasource may apply some performance optimizations.Furthermore, if you’re using Hibernate as your persistence mechanism, declaring<br />
a transaction as read-only will result in Hibernate’s flush mode being set to FLUSH_NEVER. This tells Hibernate to avoid unnecessary synchronization of objects with the database, thus delaying all updates until the end of the transaction.<br />
<br />
<b>4)TRANSACTION TIMEOUT: </b>If our application need to perform well, each transactions shoudn't take longer time to finish execution. Because transactions may involve locks on the underlying data store, long-running transactions can hold database resources unnecessarily.Instead of waiting the long running transaction finish, we can declare each transaction time out period.<br />
<br />
<b>5)Rollback rules: </b>Spring provides configuration to which exception to rollback a transaction and which doesn't require a rollback.By default transactions rollback for unchecked(Runtime) exceptions but not for checked exceptions.But you can declare a rollback for checked exceptions as well as unchecked exceptions.<br />
<br />
Now we have a minimum understanding of how the @Transactional need to be configured lets configure a sample deposit method.<br />
<br />
@Transactional(propagation=Propagation.REQUIRED,readOnly=false)<br />
public long deposit(long amount){<br />
private long balance;<br />
.//implementation<br />
<br />
return balance;<br />
}<br />
<br />
See this link for @Transactional best practices.<br />
<br />
<b>http://stackoverflow.com/questions/1079114/spring-transactional-annotation-best-practice</b><br />
<br />
That's all about Spring declarative transaction management...<br />
<br />
Thanks for visiting my blog!!!!!!!!<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-21112422181909800712014-04-29T04:02:00.003-07:002017-04-04T00:32:46.484-07:00AOP in Spring<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Aspect Oriented Programming:</b><br />
<br />
Before dive into Spring AOP, let me explain the problems faced in my previous projects(.Ours is an Internet Banking solution.So we need to audit the important fund transfer actions(SaveFT, SubmitFT,AuthorizeFT and RejectFT) in case if something goes wrong, the bank can see the audit and find out who saved or submitted a particular operation.So they can do the necessary actions.<br />
<br />
Coming to auditing functionality, this is scattered in most of the classes and any changes to the audit functionality we need to change all classes it was implemented.So even though my actual business logic wasn't change we need to change those classes and need to compile and deploy again which is pain and error prone.Some of the cross cutting functionalities are logging,security,auditing and transaction management.<br />
<br />
AOP on the other hand provide solution to the above cross cutting concerns or cross cutting functionalists.<br />
We dont need to write these concerns in side our business classes, we can write these aspects separately and run our advices at run time at the desired target methods.AOP also reduces the boiler plate code across our application.<br />
<br />
Terminology in Spring AOP;<br />
<br />
<b>1)Aspect:</b> Aspect is the cross cutting functionality in our application like logging,auditing,transaction or security.<br />
<br />
<b>2)Advice:</b> Advice is the job of an Aspect.Advice will define what and when of an aspect.In addition to describing the job of an aspect will perform, advice addresses the question of when to perform the job<br />
<br />
Spring aspects can work with five kinds of advices<br />
<br />
a)Before: Advice will run before the invocation of our target method.<br />
b)After: Advice will run after the completion of our target method regardless of the outcome.<br />
c)After-returning: The Advice functionality takes place after the target method completed successfully.<br />
d)After-throwing: The Advice funcionality takes place after the target method throws an exception.<br />
e)Around: Advice will run before and after our target method.<br />
<br />
<b>3)Join Points:</b> A join point is point in the execution of the application where an aspect can be plugged in.<br />
This point could be a method being called, an exception being thrown, or even a field being modified.But in Spring join points only represent methods.We can use join points and methods synonymously.<br />
These are the points where your aspect’s code can be inserted into the normal flow of your application to add new behavior.<br />
<br />
<b>4)Pointcut:</b> Pointcuts are used to pinpoint where an aspect’s advice should be applied. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut (for example, the execution of a method with a certain name). The concept of join points as matched by pointcut expressions is central to AOP.<br />
<br />
Lets write a small Logging aspect to understand AOP implementation in Spring.<br />
<br />
For example i have a bank account and i want to run this logging functionality to run before and after the deposit method.<br />
<br />
<b>BankAccount.java</b><br />
<b><br /></b>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh.domain;
public class BankAccount {
private long balance;
// method to deposit
public void deposit(int depositAmount) {
if (depositAmount < 0) {
System.out.print("Invalid Amount!");
}
balance = balance + depositAmount;
System.out.println("Current Balance is "+balance);
}
// method to withdraw
public int withdraw(int withdrawAmount) {
System.out.println("Your Balance is: " + balance);
if (withdrawAmount > balance) {
System.out.println("You do not have a sufficient balance to withdraw this amount!");
}
return withdrawAmount;
}
} </code></pre>
<br />
<b>LoggingAspect.java:</b><br />
<br />
This aspect has two advices which we want to run BankAccount.java's deposit method.Keep in mind the BankAccount doesnt aware about this logging aspect.Spring creates a proxy and weaves these advices in the runtime.<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh.domain;
public class LoggingAspect {
public void beforeDeposit() {
System.out.println("Running before deposit method");
}
public void afterDeposit() {
System.out.println("Running After Deposit method");
}
} </code></pre>
<br />
<br />
Now lets configure our application-context.xml to include these two bean definitions and configure the before and after pointcuts.<br />
<br />
<pre style="color: #333333; line-height: 16.25px;"><pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;"> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<bean id="bankAccount" class="com.ramesh.domain.BankAccount" />
<bean id="logging" class="com.ramesh.domain.LoggingAspect" />
<aop:config>
<aop:aspect ref="logging">
<aop:before pointcut="execution(* com.ramesh.domain.BankAccount.deposit(..))"
method="beforeDeposit" />
<aop:after pointcut="execution(* com.ramesh.domain.BankAccount.deposit(..))"
method="afterDeposit" />
</aop:aspect>
</aop:config>
</beans> </code></pre>
</pre>
<br />
<br />
We are configuring the aop in xml file.We can do this with annotations also.<br />
<br />
Here we declared these two beans.There is no dependency between these two beans.we are defining logging bean as an aspect. and we want to execute before method at our target method com.ramesh.domain.BankAccount.deposit. please note * at starting the pointcut denotes we never care about the return type and deposit(..) indicates the method can take any number of parameters.<br />
<br />
Since we completed our configuration lets test it..<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.ramesh.domain.BankAccount;
public class MainApp {
public static void main(String[] args) {
ApplicationContext appContext = new ClassPathXmlApplicationContext(
"spring-context.xml");
BankAccount account = (BankAccount) appContext.getBean("bankAccount");
account.deposit(100);
}
} </code></pre>
<br />
<br />
If you see the main program, we only calling the deposit method.Lets see the output after running this<br />
<br />
Apr 29, 2014 8:50:33 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons<br />
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1c0e45a: defining beans [bankAccount,logging,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0,org.springframework.aop.aspectj.AspectJPointcutAdvisor#1]; root of factory hierarchy<br />
<br />
<br />
<b>Running before deposit method</b><br />
<b>Current Balance is 100</b><br />
<b>Running After Deposit method</b><br />
<br />
Magic...our advices(beforeDeposit() and afterDeposit() methods) run before and after our target method(deposit())..<br />
<br />
we have seen before and after advice.Now lets see around advice.<br />
<br />
Around advice will run before and after the target method.This advice will be useful when we want to save the state between the before and after advice calls, if we don't have around advice we need to save the state to a variable when before and after advices used.<br />
<br />
Around advice will take ProceedingJoinPoint as an parameter and it has proceed method will is used to pass the control to our target method.<br />
<br />
Lets say we want to run around advice to a target method withdraw in BankAccount<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh.domain;
public class BankAccount {
private long balance=1000;
// method to deposit
public void deposit(int depositAmount) {
if (depositAmount < 0) {
System.out.print("Invalid Amount!");
}
balance = balance + depositAmount;
System.out.println("Current Balance is "+balance);
}
// method to withdraw
public long withdraw(int withdrawAmount) {
System.out.println("Your Balance is: " + balance);
if (withdrawAmount > balance) {
System.out.println("You do not have a sufficient balance to withdraw this amount!");
}
balance=balance-withdrawAmount;
return balance;
}
} </code></pre>
<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;"> package com.ramesh.domain;
import org.aspectj.lang.ProceedingJoinPoint;
public class LoggingAspect {
public void beforeDeposit() {
System.out.println("Running before deposit method");
}
public void afterDeposit() {
System.out.println("Running After Deposit method");
}
public void aroundWithdraw(ProceedingJoinPoint joinPoint) {
System.out
.println("Inside around method: It will run before advised method");
try {
joinPoint.proceed();
} catch (Throwable e) {
e.printStackTrace();
}
System.out
.println("Inside around method: It will run after advised method");
}
} </code></pre>
<br />
<br />
Lets see the around configuration in spring-context.xml<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;"><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<bean id="bankAccount" class="com.ramesh.domain.BankAccount" />
<bean id="logging" class="com.ramesh.domain.LoggingAspect" />
<aop:config>
<aop:aspect ref="logging">
<aop:around pointcut="execution(* com.ramesh.domain.BankAccount.withdraw(..))"
method="aroundWithdraw" />
</aop:aspect>
</aop:config>
</beans> </code></pre>
<br />
<br />
Lets run the MainApp.java to the output<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.ramesh.domain.BankAccount;
public class MainApp {
public static void main(String[] args) {
ApplicationContext appContext = new ClassPathXmlApplicationContext(
"spring-context.xml");
BankAccount account = (BankAccount) appContext.getBean("bankAccount");
account.withdraw(100);
}
} </code></pre>
<br />
<br />
Output:<br />
<br />
Apr 30, 2014 12:27:32 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons<br />
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@982589: defining beans [bankAccount,logging,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0]; root of factory hierarchy<br />
<br />
<b><br /></b>
<b>Inside around method: It will run before advised method</b><br />
<b>Your Balance is: 1000</b><br />
<b>Inside around method: It will run after advised method</b><br />
<div>
<br /></div>
<div>
<br /></div>
Thanks for reading!!!!!!<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-71714860442375557902014-04-28T11:44:00.001-07:002014-04-28T14:28:13.604-07:00Object Oriented Programming - Encapsulation<div dir="ltr" style="text-align: left;" trbidi="on">
Encapsulation in Object Oriented Programming is a concept in which it enforces protecting attributes and behavior by wrapping inside a single unit(a class in Java) and restricting accessing to the inner workings of the objects based on that class.The true power of encapsulation is that the changes done to our protected code will result in bare minimal changes or no change to other parts of the application.<br />
<br />
In principle the object shouldn't reveal any thing about it's inner workings and provides only things that are necessary for other parts of the application to work.<br />
<br />
We can do this in Java by completely encapsulate a member variable or member function by declaring them as private or you can encapsulate partially by declaring them protected.<br />
<br />
Let me give an example<br />
<br />
Lets say we have a BankAccount class and we don't want other parts of the program reach in my balance and change it without going through the usual withdraw() or deposit() methods.This will cause a havoc in my program.<br />
<br />
You may ask, we are allowing to change the balance through the deposit and withdraw methods.Yes.But how can my balance updated without doing any withdraw or deposit operations.In these two methods we may be doing other things like auditing or logging, without this functionality we might not know what's happened if some thing goes wrong(like who done the transfer and how much amount or who authorized the transaction etc).<br />
<br />
To secure the data we should declare those attributes as private.We are not secretive here we are reducing the dependencies in other parts of the program.So any changes done in my program won't affect other parts of the application.<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh.domain;
import java.util.Date;
public class BankAccount {
private String accountId;
private long balance;
private String accountType;
private Date dateOpened;
public void withdraw() {
System.out.println("Inside withdraw");
}
public void deposit() {
System.out.println("Inside deposit");
}
// setters and getters
} </code></pre>
<br />
<br />
Advantages:<br />
<br />
1) Easy to change our code with new requirements without affecting other parts of the program.<br />
2) Easy for unit testing.<br />
3) Let us control who can access what.<br />
<br />
That's all about Encapsulation...Thanks for reading !!!!!<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-7739184431099129514.post-50903075158599556702014-04-28T04:26:00.002-07:002014-04-29T05:26:15.043-07:00Spring Beans Auto-Wiring<div dir="ltr" style="text-align: left;" trbidi="on">
We can configure Spring beans dependencies using <property> and <consturctor-arg>.But Spring container can auto wire relationships between collaborating objects without using the above mentioned tags.This will allow us to minimize the amount of XML configuration in our Spring Context xml file.But we need to be very careful using auto wiring as this will be difficult if some thing goes wrong and new developers in the team hard to debug how the beans auto wired.<br />
<br />
There are 4 ways we can do the bean auto wiring.By default there is no auto wiring and we need to explicitly mention if we need to let the container know how our beans should be auto wired.<br />
<br />
1)byName<br />
2)byType<br />
3)constructor<br />
4)autodetect<br />
<br />
Lets see each type in action<br />
<br />
<b>1)byName: </b>auto wiring by name. If we defined auto wiring <b>byName </b>in bean definition file then Spring container looks at the properties of the bean and tries to match the name of the property and if both matches it wire its properties.<br />
<br />
Lets see in action.For example if i have a Employee and Address classes and Address is declared as an instance field in Employee class.<br />
<br />
<b>Employee.java</b><br />
<b><br /></b>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh.domain;
public class Employee {
private int id;
private String name;
private long salary;
private Address address;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getSalary() {
return salary;
}
public void setSalary(long salary) {
this.salary = salary;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
} </code></pre>
<br />
<b>Address.java</b><br />
<b><br /></b>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh.domain;
public class Address {
private String street;
private String pinCode;
private String city;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getPinCode() {
return pinCode;
}
public void setPinCode(String pinCode) {
this.pinCode = pinCode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
} </code></pre>
<br />
<br />
<b>spring-context.xml</b><br />
<b><br /></b>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;"><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="employee" class="com.ramesh.domain.Employee" autowire="byName">
<property name="id" value="844" />
<property name="name" value="Ramesh M" />
<property name="salary" value="85000" />
</bean>
<bean id="address" class="com.ramesh.domain.Address">
<property name="street">
<value>Embassy Golflinks Business Park Street</value>
</property>
<property name="city">
<value>Bangalore</value>
</property>
<property name="pinCode">
<value>560071</value>
</property>
</bean>
</beans> </code></pre>
<b><br /></b>
<b><br /></b>
If you notice these lines in our xml file, we didn't mention the address either as a property or a constructor-arg.We mentioned another attribute autowire="byName" for which the Spring container will check a bean name "address" and match both the property mentioned in employee bean and xml file and autowires them<br />
<b><br /></b>
<b><bean id="employee" class="com.ramesh.domain.Employee" autowire="byName"></b><br />
<b><span class="Apple-tab-span" style="white-space: pre;"> </span><property name="id" value="844" /></b><br />
<b><span class="Apple-tab-span" style="white-space: pre;"> </span><property name="name" value="Ramesh M" /></b><br />
<b><span class="Apple-tab-span" style="white-space: pre;"> </span><property name="salary" value="85000" /></b><br />
<b></bean></b><br />
<b><br /></b>
I will explain about the other auto wiring in a while...<br />
<b><br /></b>
Thanks for reading !!!!!!<br />
<b><br /></b></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-71721716782117563422014-04-27T15:06:00.003-07:002014-05-13T14:09:20.748-07:00Binary Search-Sample program in Java<div dir="ltr" style="text-align: left;" trbidi="on">
What is <b>Binary Search</b> by the way?<br />
<br />
A binary search or half-interval search algorithm finds the position of a specified input value (the search "key") within an array sorted by key value.[1][2] For binary search, the array should be arranged in ascending or descending order. In each step, the algorithm compares the search key value with the key value of the middle element of the array. If the keys match, then a matching element has been found and its index, or position, is returned. Otherwise, if the search key is less than the middle element's key, then the algorithm repeats its action on the sub-array to the left of the middle element or, if the search key is greater, on the sub-array to the right. If the remaining array to be searched is empty, then the key cannot be found in the array and a special "not found" indication is returned.<br />
(Source: WikiPedia)<br />
<br />
The requirement for binary search algo is the array should be sorted.We can use Quick Sort or Merge Sort for sorting the array.First we need to take mid element(if low=0 and high=array.length-1 then mid=low+high/2).If the middle element is the one which we are searching we return the index or we just print the element is found in the array at a specified index.<br />
<br />
Lets say the element we are searching is less than the middle element then we will take the sub array by specifying high=mid-1 or if the searching element is greater than the middle element then our sub array becomes low=mid+1.This process will continue until we found the element we are searching.<br />
<br />
<b>Code:</b><br />
<br />
<pre style="color: #333333; line-height: 16.25px;"><span style="color: #888888;">/**</span>
<span style="color: #888888;"> * @author RameshM</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Sample program for Binary Search</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">BinarySearchTest</span> {
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">searchKey</span>(<span style="color: #333399; font-weight: bold;">int</span>[] intArray, <span style="color: #333399; font-weight: bold;">int</span> element) {
<span style="color: #333399; font-weight: bold;">int</span> low = <span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #333399; font-weight: bold;">int</span> high = intArray.<span style="color: #0000cc;">length</span> - <span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #008800; font-weight: bold;">while</span> (low <= high) {
<span style="color: #333399; font-weight: bold;">int</span> middle = (low + high) / <span style="color: #0000dd; font-weight: bold;">2</span>;
<span style="color: #008800; font-weight: bold;">if</span> (element > intArray[middle]) {
low = middle + <span style="color: #0000dd; font-weight: bold;">1</span>;
} <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">if</span> (element < intArray[middle]) {
high = middle - <span style="color: #0000dd; font-weight: bold;">1</span>;
} <span style="color: #008800; font-weight: bold;">else</span> {
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span>;
}
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span>;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span>(String args[]) {
<span style="color: #333399; font-weight: bold;">int</span>[] intArray = { <span style="color: #0000dd; font-weight: bold;">2</span>, <span style="color: #0000dd; font-weight: bold;">4</span>, <span style="color: #0000dd; font-weight: bold;">5</span>, <span style="color: #0000dd; font-weight: bold;">8</span>, <span style="color: #0000dd; font-weight: bold;">9</span>, <span style="color: #0000dd; font-weight: bold;">22</span>, <span style="color: #0000dd; font-weight: bold;">44</span>, <span style="color: #0000dd; font-weight: bold;">55</span>, <span style="color: #0000dd; font-weight: bold;">66</span>, <span style="color: #0000dd; font-weight: bold;">88</span>, <span style="color: #0000dd; font-weight: bold;">100</span> };
<span style="color: #333399; font-weight: bold;">int</span> element = <span style="color: #0000dd; font-weight: bold;">44</span>;
<span style="color: #333399; font-weight: bold;">boolean</span> result = searchKey(intArray, element);
<span style="color: #008800; font-weight: bold;">if</span> (result) {
System.<span style="color: #0000cc;">out</span>.<span style="color: #0000cc;">println</span>(<span style="background-color: #fff0f0;">"The element found in the Array"</span>);
} <span style="color: #008800; font-weight: bold;">else</span> {
System.<span style="color: #0000cc;">out</span>.<span style="color: #0000cc;">println</span>(<span style="background-color: #fff0f0;">"The element is not found in the Array"</span>);
}
}
}</pre>
<br />
<b>Output:</b><br />
<br />
<pre style="background-color: white; color: #333333; font-size: 13px; line-height: 16.25px;"><span style="background-color: #fff0f0;">The element found in the Array</span></pre>
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-25592682755964774572014-04-27T14:15:00.003-07:002014-04-27T14:17:02.271-07:00Java 1.7 features<div dir="ltr" style="text-align: left;" trbidi="on">
Below are the important features introduced in 1.7 in developers point of view.<br />
<br />
1)Strings in switch statement<br />
2)The try-with-resources Statement<br />
3)Binary Literals<br />
4)Underscores in numerical Literals<br />
5)Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking<br />
6)Type Inference for Generic Instance Creation</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-32979475853287578202014-04-27T13:33:00.004-07:002014-05-01T03:37:59.148-07:00Injecting inner beans in Spring<div dir="ltr" style="text-align: left;" trbidi="on">
Similar to Java which provides defining inner class inside another class, Spring IOC provides defining a bean inside another bean.This will be useful when a bean is declared as property in another bean.<br />
<br />
Let us see the inner bean in action<br />
<br />
Lets say i have an Employee bean and employee has an address object declared as a field in Employee object.<br />
<br />
<b>Employee.java:</b><br />
<b><br /></b>
<br />
<pre style="color: #333333; line-height: 16.25px;"><pre><span style="color: #008800; font-weight: bold;">package</span> com.<span style="color: #0000cc;">ramesh</span>.<span style="color: #0000cc;">domain</span>;
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Employee</span> {
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> id;
<span style="color: #008800; font-weight: bold;">private</span> String name;
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">long</span> salary;
<span style="color: #008800; font-weight: bold;">private</span> Address address;
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">getId</span>() {
<span style="color: #008800; font-weight: bold;">return</span> id;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setId</span>(<span style="color: #333399; font-weight: bold;">int</span> id) {
<span style="color: #008800; font-weight: bold;">this</span>.<span style="color: #0000cc;">id</span> = id;
}
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">getName</span>() {
<span style="color: #008800; font-weight: bold;">return</span> name;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setName</span>(String name) {
<span style="color: #008800; font-weight: bold;">this</span>.<span style="color: #0000cc;">name</span> = name;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">long</span> <span style="color: #0066bb; font-weight: bold;">getSalary</span>() {
<span style="color: #008800; font-weight: bold;">return</span> salary;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setSalary</span>(<span style="color: #333399; font-weight: bold;">long</span> salary) {
<span style="color: #008800; font-weight: bold;">this</span>.<span style="color: #0000cc;">salary</span> = salary;
}
<span style="color: #008800; font-weight: bold;">public</span> Address <span style="color: #0066bb; font-weight: bold;">getAddress</span>() {
<span style="color: #008800; font-weight: bold;">return</span> address;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setAddress</span>(Address address) {
<span style="color: #008800; font-weight: bold;">this</span>.<span style="color: #0000cc;">address</span> = address;
}
}</pre>
</pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre style="color: #333333; line-height: 16.25px;">As shown above employee as a Address field.Lets see the Address bean</pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre style="color: #333333; line-height: 16.25px;"><b>Address.java</b></pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre style="color: #333333; line-height: 16.25px;"><pre><span style="color: #008800; font-weight: bold;">package</span> com.<span style="color: #0000cc;">ramesh</span>.<span style="color: #0000cc;">domain</span>;
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Address</span> {
<span style="color: #008800; font-weight: bold;">private</span> String street;
<span style="color: #008800; font-weight: bold;">private</span> String pinCode;
<span style="color: #008800; font-weight: bold;">private</span> String city;
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">getStreet</span>() {
<span style="color: #008800; font-weight: bold;">return</span> street;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setStreet</span>(String street) {
<span style="color: #008800; font-weight: bold;">this</span>.<span style="color: #0000cc;">street</span> = street;
}
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">getPinCode</span>() {
<span style="color: #008800; font-weight: bold;">return</span> pinCode;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setPinCode</span>(String pinCode) {
<span style="color: #008800; font-weight: bold;">this</span>.<span style="color: #0000cc;">pinCode</span> = pinCode;
}
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">getCity</span>() {
<span style="color: #008800; font-weight: bold;">return</span> city;
}
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setCity</span>(String city) {
<span style="color: #008800; font-weight: bold;">this</span>.<span style="color: #0000cc;">city</span> = city;
}
}</pre>
</pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre style="color: #333333; line-height: 16.25px;">Now configure the spring-context.xml </pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre><pre style="color: #333333; line-height: 16.25px;"><span style="color: #557799;"><?xml version="1.0" encoding="UTF-8"?></span>
<span style="color: #007700;"><beans</span> <span style="color: #0000cc;">xmlns=</span><span style="background-color: #fff0f0;">"http://www.springframework.org/schema/beans"</span>
<span style="color: #0000cc;">xmlns:xsi=</span><span style="background-color: #fff0f0;">"http://www.w3.org/2001/XMLSchema-instance"</span> <span style="color: #0000cc;">xmlns:mvc=</span><span style="background-color: #fff0f0;">"http://www.springframework.org/schema/mvc"</span>
<span style="color: #0000cc;">xmlns:context=</span><span style="background-color: #fff0f0;">"http://www.springframework.org/schema/context"</span>
<span style="color: #0000cc;">xsi:schemaLocation=</span><span style="background-color: #fff0f0;">"</span>
<span style="background-color: #fff0f0;"> http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd</span>
<span style="background-color: #fff0f0;"> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd</span>
<span style="background-color: #fff0f0;"> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><bean</span> <span style="color: #0000cc;">id=</span><span style="background-color: #fff0f0;">"employee"</span> <span style="color: #0000cc;">class=</span><span style="background-color: #fff0f0;">"com.ramesh.domain.Employee"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"id"</span> <span style="color: #0000cc;">value=</span><span style="background-color: #fff0f0;">"844"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"name"</span> <span style="color: #0000cc;">value=</span><span style="background-color: #fff0f0;">"Ramesh M"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"salary"</span> <span style="color: #0000cc;">value=</span><span style="background-color: #fff0f0;">"85000"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"address"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><bean</span> <span style="color: #0000cc;">class=</span><span style="background-color: #fff0f0;">"com.ramesh.domain.Address"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"street"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><value></span>Embassy Golflinks Business Park Street<span style="color: #007700;"></value></span>
<span style="color: #007700;"></property></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"city"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><value></span>Bangalore<span style="color: #007700;"></value></span>
<span style="color: #007700;"></property></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"pinCode"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><value></span>560071<span style="color: #007700;"></value></span>
<span style="color: #007700;"></property></span>
<span style="color: #007700;"></bean></span>
<span style="color: #007700;"></property></span>
<span style="color: #007700;"></bean></span>
<span style="color: #007700;"></beans></span></pre>
<pre style="color: #333333; line-height: 16.25px;"><span style="color: #007700;">
</span></pre>
<pre style="line-height: 16.25px;">Since we completed the configuration lets test </pre>
<pre style="line-height: 16.25px;"></pre>
<pre><pre style="color: #333333; line-height: 16.25px;"><span style="color: #008800; font-weight: bold;">package</span> com.<span style="color: #0000cc;">ramesh</span>;
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">org.springframework.context.ApplicationContext</span>;
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">org.springframework.context.support.ClassPathXmlApplicationContext</span>;
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">com.ramesh.domain.Employee</span>;
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">MainApp</span> {
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span>(String[] args) {
ApplicationContext appContext = <span style="color: #008800; font-weight: bold;">new</span> ClassPathXmlApplicationContext(
<span style="background-color: #fff0f0;">"spring-context.xml"</span>);
Employee employee = (Employee) appContext.<span style="color: #0000cc;">getBean</span>(<span style="background-color: #fff0f0;">"employee"</span>);
<span style="color: #888888;">// displaying employee name</span>
System.<span style="color: #0000cc;">out</span>.<span style="color: #0000cc;">println</span>(employee.<span style="color: #0000cc;">getName</span>());
<span style="color: #888888;">// displaying inner bean address details</span>
System.<span style="color: #0000cc;">out</span>.<span style="color: #0000cc;">println</span>(employee.<span style="color: #0000cc;">getAddress</span>().<span style="color: #0000cc;">getStreet</span>());
}
}</pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre style="color: #333333; line-height: 16.25px;"><b>The output:</b></pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre><span style="color: #333333;"><span style="line-height: 16.25px;">INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1b4fad5: defining beans [employee]; root of factory hierarchy</span></span></pre>
<pre><span style="color: #333333;"><span style="line-height: 16.25px;">Ramesh M
Embassy Golflinks Business Park Street</span></span><span style="color: #333333; line-height: 16.25px;">
</span></pre>
<div style="line-height: 16.25px;">
</div>
</pre>
</pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
<pre style="color: #333333; line-height: 16.25px;"></pre>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-80463696504426659732014-04-27T12:11:00.005-07:002014-04-27T12:20:52.777-07:00Spring bean scopes<div dir="ltr" style="text-align: left;" trbidi="on">
Below are the list of Spring scopes<br />
<br />
<b>1)singleton:</b> By default all the beans created in Spring are singleton per container.If you not mention scope attribute in your bean definition file beans then beans will created are singletons only.<br />
<br />
<b>2)prototype:</b> New bean will be created for each request with this scope.You can override the default singleton scope to prototype in bean definition file as shown below.<br />
<br />
<bean id="account" class="com.ramesh.Account" scope="prototype"><br />
<br />
<b>3)request:</b>Scopes a bean definition to a HTTP request.Valid only in the case of web application context(E.g.: Spring MVC)<br />
<br />
<b>4)session: </b>Scopes a bean definition to a HTTP session.Valid only the case of web application context(E.g.: Spring MVC)<br />
<br />
<b>5)global-session:</b> Scopes a bean definition to a global HTTP session.Valid in the case of Portlets context</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-51266264403954963472014-04-27T08:30:00.001-07:002014-04-27T11:48:42.210-07:00Creating Spring beans using Factory method<div dir="ltr" style="text-align: left;" trbidi="on">
We all know we never need to create bean dependencies in Spring with new operator like below<br />
<br />
e.g Employee employee=new Employee();<br />
<br />
<br />
Usually we use constructor or setter methods to inject dependencies.But there are other ways we can create objects in Spring.In some classes its possible that there wont be any public constructor available(E.g.: Creating java singletons objects).In these cases we don't have any option other than using the factory patterns to create objects in Spring.<br />
<br />
Please note if you are testing the beans with private constructor in a normal java program using main program, it wont be a problem.Spring is able to create beans with private constructors using reflection.But if there is a SecurityManager in place and it wont let create beans with private constructors.<br />
<br />
<b>1)Static factory method:</b>Let's say we have a static factory which is responsible for creating Singleton object(Java base Singleton object).We can use Spring bean <b>factory-method</b> attribute in our Spring bean definition file to wire the object.<br />
<b>2)Instance factory method: </b>These objects are created using the bean instance.<br />
<br />
Let us see creating bean instance using <b>Static factory method and Instance factory method </b>in action.<br />
<b><br /></b>
Lets say i have Account interface with few methods and SavingsAccount and CurrentAccount implement this interface<br />
<br />
<b>Account.java</b><br />
<b><br /></b>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;"> public interface Account{
void deposit();
void withdraw();
} </code></pre>
<b><br /></b>
<b>SavingsAccount.java</b><br />
<b><br /></b>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">public class SavingsAccount{
public void deposit(){
System.out.println("Inside Deposit method");
}
public void withdraw(){
System.out.println("Inside Withdraw method");
}
} </code></pre>
<b><br /></b>
<b>CurrentAccount.java</b><br />
<b><br /></b>
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">public class CurrentAccount{
public void deposit(){
System.out.println("Inside Deposit method");
}
public void withdraw(){
System.out.println("Inside Withdraw method");
}
} </code></pre>
<b><br /></b>
<b><br /></b>
Now we need a factory to create SavingsAccount and CurrentAccount instances.<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">public class AccountService{
private static AccountService service = new AccountService();
//Static factory method
public static AccountService createService(){
return service;
}
//Instance factory methods
public Account createSavingsAccountInstance(){
return new SavingsAccount();
}
public Account createCurrentAccountInstance(){
return new CurrentAccount();
}
} </code></pre>
<br />
<br />
Now lets see how to configure bean definition file to call these factory methods.<br />
<br />
These below two are important attributes in our spring context file to call the factory instance method and factory bean methods<br />
<br />
1) factory-method<br />
2)factory-bean<br />
<br />
<b>application-context.xml</b><br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;"><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean id="accountService" class="com.ramesh.AccountService" factory-method="createService"/>
<bean id="createSavingsAccountInstance" factory-bean="accountService" factory-method="createSavingsAccountInstance"/>
<bean id="createCurrentAccountInstance" factory-bean="accountService" factory-method="createCurrentAccountInstance"/>
</beans> </code></pre>
<br />
<br />
<br />
Lets test this code<br />
<br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">com.ramesh;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringApplicationContextLoader{
public static void main (String args[]){
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");
Account savings = (SavingsAccount)applicationContext.getBean("createSavingsAccountInstance");
savings.withdraw();
Account current = (CurrentAccount)applicationContext.getBean("createCurrentAccountInstance");
current.deposit();
}
} </code></pre>
<br />
<br />
<br />
I hope you get the concept :-)<br />
<br />
Thanks for reading!!!!!<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-6864453409824809922014-04-27T00:26:00.000-07:002014-04-27T11:48:31.686-07:00Design patterns used in Spring<div dir="ltr" style="text-align: left;" trbidi="on">
Here is a list of important design patterns used in Spring<br />
<br />
1)Singleton<br />
2)Model View Controller<br />
3)Front Controller<br />
4)ViewResolver<br />
5)Observer<br />
6)Service Locator<br />
7)Proxy<br />
8)Template method<br />
<br />
<br />
Thanks for reading!!!!!!</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-65778622617099286662014-04-27T00:10:00.003-07:002014-04-27T11:48:20.118-07:00How can a class extends another class, extends Object? Is it not multiple inheritance which is not allowed in Java?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div>
Let me explain</div>
<div>
<br /></div>
<div>
We know every class in java extends Object class.Lets say if you have a class Employee</div>
<div>
<br /></div>
<div>
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">public class Employee{
private String name;
// getters and setters
} </code></pre>
</div>
<div>
<br /></div>
<div>
Then this class implicitly like this</div>
<div>
<br /></div>
<div>
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">public class Employee extends Object{
private String name;
// getters and setters
} </code></pre>
</div>
<div>
<br />
<br />
But if your class extends another class explicitly then </div>
<div>
<br /></div>
<div>
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;"> public class Employee extends BaseEmployee{
private String name;
// getters and setters
} </code></pre>
<br /></div>
<div>
Then your Employee class doesn't extends Objects class.Instead your BaseEmployee will extends Object class.</div>
<div>
<br /></div>
<div>
Hope you get it ;)</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-76129971271759658842014-04-26T12:07:00.001-07:002014-05-05T01:49:04.241-07:00Spring Bean Life Cycle<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Lets see the life cycle of bean from cradle to grave or in another words from instantiation to destroy method.<br />
<br />
Once Spring reads the bean definition xml file<br />
<br />
1) Spring instantiates the bean.<br />
2) Spring injects the values and bean references into bean references.<br />
3) If your bean implements the BeanNameAware interface, Spring calls the setBeanName() method.<br />
4) If your bean implements BeanFactoryAware interface then Spring calls the setBeanFactory() method and passing the bean factory itself.<br />
5) If your bean implements ApplicationContextAware interface then Spring calls the setApplicationContext() method.<br />
6) If your bean implements BeanPostProcessor interface then Spring calls postProcessBeforeInitialization() method<br />
7) If your bean implements InitializingBean interface then Spring calls afterPropertiesSet() method and if your bean declared any init-method then the specified init method will be called.<br />
8) If there are any beans that implements BeanPostProcessor then Spring calls postProcessAfterInitialization() method.<br />
9) Now your bean is ready and will be available till the application context is destroyed.<br />
10) If your bean implements DisposableBean interface then Spring will call destroy method similarly if your bean declared any user defined destroy method then Spring calls the destroy-method.<br />
<br />
Thanks for visiting my blog....</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-3148814272195978132014-04-25T12:35:00.000-07:002014-04-27T14:17:24.534-07:00Java 1.5 features<div dir="ltr" style="text-align: left;" trbidi="on">
Java 1.4 -> Java 1.5<br />
<br />
These are the most important features added in Java 1.5<br />
<br />
1)Generics<br />
2)Enhanced for loop<br />
3)Auto Boxing and Unboxing<br />
4)Type Safe Enums<br />
5)Varargs<br />
6)Static Imports<br />
7)Annotations or Metadata<br />
<br />
There are other changes also but the above are the important from the developer's perspective.<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-20029937683702646832014-04-22T11:24:00.002-07:002014-05-13T14:11:49.342-07:00Dependency Injection in Spring<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="color: #674ea7;">What is Dependency Injection?</span></h2>
<div>
<span style="color: #674ea7;"><b>In Layman's Language:</b> In any Object oriented programming language, objects depends on each other and they collaborating on each others by calling their methods. Traditionally we create objects using new operator as shown below.</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;">Lets say i have Employee class and this employee class has a reference of Department object, we create the department object inside Employee class like shown below</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">public class Employee{
private Department dept=new Department();
public void displayMessage(){
dept.displayDeptDetails();
}
} </code></pre>
</div>
<div>
<span style="color: #674ea7;">Did you notice any problem in the above code?</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;">Yes.You guessed it correct. </span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;">The code is tightly coupled.For example if i need to create the department object in another way or simply put if i need to change any changes to department object i need to change the Employee class and if the reference in say in 100 classes in my project i need to change in 100 classes and need to rebuild and redeploy it and possibly insert some bugs if you forget to modify some class(no one is perfect and as developers we keep making mistakes otherwise why the hell the testing teams required :P)</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;">Spring provides solution for this problem in the form of dependency injection.Spring let us configure how the dependencies needs to be created in an xml file/annotation and it will inject the dependencies at run time.</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;">A sample bean declarations in xml file</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; border: 1px solid rgb(214, 214, 214); margin-bottom: 10px; overflow: auto; padding: 5px; width: 549.765625px;"><span style="color: #674ea7;"><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;"><?</span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;">xml version</span><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;">=</span><span class="str" style="font-size: 12px; margin: 0px; padding: 0px;">"1.0"</span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;"> encoding</span><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;">=</span><span class="str" style="font-size: 12px; margin: 0px; padding: 0px;">"UTF-8"</span><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;">?></span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;">
</span><span class="tag" style="font-size: 12px; margin: 0px; padding: 0px;"><beans</span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;"> </span><span class="atn" style="font-size: 12px; margin: 0px; padding: 0px;">xmlns</span><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;">=</span><span class="atv" style="font-size: 12px; margin: 0px; padding: 0px;">"http://www.springframework.org/schema/beans"</span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;">
</span><span class="atn" style="font-size: 12px; margin: 0px; padding: 0px;">xmlns:xsi</span><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;">=</span><span class="atv" style="font-size: 12px; margin: 0px; padding: 0px;">"http://www.w3.org/2001/XMLSchema-instance"</span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;">
</span><span class="atn" style="font-size: 12px; margin: 0px; padding: 0px;">xsi:schemaLocation</span><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;">=</span><span class="atv" style="font-size: 12px; margin: 0px; padding: 0px;">"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"</span><span class="tag" style="font-size: 12px; margin: 0px; padding: 0px;">></span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;">
</span><span class="tag" style="font-size: 12px; margin: 0px; padding: 0px;"><bean</span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;"> </span><span class="atn" style="font-size: 12px; margin: 0px; padding: 0px;">id</span><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;">=</span><span class="atv" style="font-size: 12px; margin: 0px; padding: 0px;">"employee"</span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;"> </span><span class="atn" style="font-size: 12px; margin: 0px; padding: 0px;">class</span><span class="pun" style="font-size: 12px; margin: 0px; padding: 0px;">=</span><span class="atv" style="font-size: 12px; margin: 0px; padding: 0px;">"com.ramesh.Employee"</span><span class="tag" style="font-size: 12px; margin: 0px; padding: 0px;">></span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;">
</span><span style="font-size: 12px;"><constructor-arg ref="department"/></span><span class="pln" style="font-size: 12px; margin: 0px; padding: 0px;">
</span><span class="tag" style="font-size: 12px; margin: 0px; padding: 0px;"></bean> </span><span style="font-size: 12px;"><bean id="department" class="com.ramesh.Department"> </bean> </beans></span></span></pre>
</div>
<div>
<span style="color: #674ea7;"><br /></span>
<span style="color: #674ea7;">We have different bean container implementations for BeanFactory or ApplicationContext.</span><br />
<span style="color: #674ea7;"><br /></span>
<span style="color: #674ea7;">E.g.:</span><br />
<pre style="background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgED09tMsF6W_CZJjjoQ34eyUwrO3aEqYtN54XTeHLIKrn82zDTBBn_qwzL0U39IbozfCCQxBmSbPl9nbp9_8oLiWyZwkmXNVpJMPnaLn_ct57jnnhE2bqbtyJh1520Xj9ovK7-9eFKJdV2/s320/codebg.gif); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 450.828125px;"><code style="word-wrap: normal;">package com.ramesh;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class EmployeeMain{
public staticvoidmain(String[]args){
ApplicationContextcontext=
new ClassPathXmlApplicationContext("EmployeeContext.xml");
Employee emp=(Employee)context.getBean("employee");
dept.displayDeptDetails();
} </code></pre>
<span style="background-color: #f0f0f0; font-family: arial; font-size: 12px; line-height: 20px;"> } </span><span style="color: #674ea7;">When the Spring application reads this xml file it will instantiates the beans and assign a unique id as described in the bean configuration.Now the beans along with their dependencies are ready for use.Since the dependencies injected at run time this will be called </span><b style="color: #674ea7;">Dependency Injection</b><span style="color: #674ea7;">. Most people use Inversion of Control and Dependency Injection interchangeably.</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;"> But IoC is a generic term meaning rather than having the application call the methods in a framework, the framework calls implementations provided by the application.</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;">DI is a form of IoC, where implementations are passed into an object through constructors/setters/service look-ups, which the object will 'depend' on in order to behave correctly.</span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;"><br /></span></div>
<div>
<span style="color: #674ea7;">Thanks for reading!!!!!!!</span></div>
<div>
<br /></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7739184431099129514.post-66914950011618198152014-04-19T13:12:00.003-07:002020-02-26T06:23:54.113-08:00Welcome to Extreme Java<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #0b5394;">Hello Folks,</span><br />
<span style="color: #0b5394;"><br /></span>
<span style="color: #0b5394;">My self Ramesh Mandala.I am a Senior Java Developer in a reputed MNC in Bangalore.I have experience in JAVA/J2EE and related frameworks for more than 8+ years.I am writing this blog for sharing my knowledge.Let me know if some thing wrong in the content so i can correct it. You can comment on the post or you can reach me at ramesh.mandala@gmail.com</span><br />
<span style="color: #0b5394;"><br /></span>
<span style="color: #0b5394;">Thanks for visiting my blog!!!!!!!</span><br />
<span style="color: #0b5394;"><br /></span>
<span style="color: #0b5394;">Cheers,</span><br />
<span style="color: #0b5394;"><br /></span>
<span style="color: #0b5394;">Ramesh</span></div>
Unknownnoreply@blogger.com0