tag:blogger.com,1999:blog-18991095898374394822024-03-04T22:26:48.672-08:00Paramesh KorrakutiParamesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-1899109589837439482.post-23332273292837570972015-07-23T13:38:00.001-07:002022-09-14T04:05:50.360-07:00Default & Static methods in Java 8<div dir="ltr" style="text-align: left;" trbidi="on"><br />
Interface: Interface is a business rules specific document/contract among various parties for effective communication between two or more interface systems.<br />
Abstract class: Usually in Java, abstract means – incomplete. Abstract class a template, describing functionality that is common to a group of classes and require unique implementations within each class.<br />
<br />
Prior to Java 8, Interfaces contain only “static final constants & abstract methods”. Below are the two new features introduced for Interfaces in Java 8.<br />
Default Methods<br />
Static Methos:<br />
<br />
1. Default Methods:<br />
Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces.<br />
<br />
Syntax:<br />
<pre class="markdown">
```java
public interface Transaction {<br />
void insertRecord();<br />
void updatedRecord();<br />
void deleteRecord();<br />
default void auditTransaction() {<br />
// Implementation to persist information about transaction for an audit purpose<br />
}
}
```
</pre>
<br />
<br />
Why do we need Default Methods in Interface?<br />
In Java, interfaces are tightly coupled with their implementation classes. It’s not at all possible to add a new method in interface without implementing the same in its all implementers. So adding a new method in interface will break all its implementers.<br />
So for backward compatibility, Java 8 provides a feasibility to add a new method definition an to interface.<br />
One of the default method available in Java 8 java.util Collections’s is “forEach()”. This method is neither implemented in List nor in Collection. But, we can use this method across all List implementers.<br />
Hierarchy:<br />
List<t> -> Collection<t> -> Iterable<t>.<br />
So, forEach() method definition available in Iterable interface as follows:<br />
default void forEach(Consumer<? super T> action) {<br />
Objects.requireNonNull(action);<br />
for (T t : this) {<br />
action.accept(t);<br />
}<br />
}<br />
<br />
<br />
Conflicts with multiple interface implementations:<br />
When a class implements two or more interfaces and a default method with the same signature available in more than one interface, then implementer class will gets ambiguity to reuse which interface’s default method definition.<br />
Error details:<br />
Duplicate default methods named <methodname> with the <parameters () and ()> are inherited from the types <interfacexxx> and <interfaceyyy>.<br />
<br />
<br />
In this scenario, we need to override method definition in implementer class as required. <br />
package com.sample;<br />
<br />
public interface MetropolitonCity {<br />
<br />
default public Integer getPropertyTaxPercent() {<br />
return new Integer(10);<br />
}<br />
}<br />
package com.sample;<br />
<br />
<br />
public interface CapitalCity {<br />
<br />
default public Integer getPropertyTaxPercent() {<br />
return new Integer(8);<br />
}<br />
}<br />
package com.sample;<br />
<br />
<br />
public class Bangalore implements MetropolitonCity, CapitalCity {<br />
<br />
public Integer getPropertyTaxPercent() {<br />
Integer taxpercent;<br />
// Can reuse from any one the interfaces<br />
taxpercent = MetropolitonCity.super.getPropertyTaxPercent();<br />
// or<br />
taxpercent = CapitalCity.super.getPropertyTaxPercent();<br />
// or we can add its own definition<br />
taxpercent = new Integer(12);<br />
return taxpercent;<br />
}<br />
}<br />
<br />
<br />
Abstract class Vs Interfaces:<br />
Once default methods introduced, both Abstract class & Interfaces looks similar. But still there is significant difference between them.<br />
<br />
Abstract class can have constructors and member variables. Hence it can hold state of an object, whereas interfaces cannot hold the state of an object.<br />
Methods in abstract classes can use and modify method arguments as well as the fields of their class. But default method can only access its arguments as interfaces do not have any state.<br />
Note:<br />
The default method cannot be final, so as to prevent modifying the default implementation of the method in the inherited classes.<br />
The default method cannot be synchronized, while the synchronized block can be added inside the default method.<br />
The default method cannot be used to override any non-final method of java.lang.Object class. Since Object is a super class for all classes in java, can cause confusion about its actual implementation in the sub classes. <br />
<br />
2. Static Methods:<br />
In general, a static method is a method that is associated with the class in which it is defined rather than with any object.<br />
In addition to default methods, we can define static methods in Interfaces. It makes easier to organize helper methods in our library rather than keeping them in a separate utility class.<br />
package com.sample;<br />
<br />
<br />
public interface StaticMethodDemo {<br />
<br />
static void staticMethod() {<br />
System.out.println("Sample static method");<br />
}<br />
}<br />
3. Functional Interfaces:<br />
Marker Interfaces: The interfaces which contains no members in it called Marker Interfaces. Marker Interfaces are used to indicate something to Compiler, JVM.<br />
Examples:<br />
Java.util.Serializable : If JVM finds a class is implementing Serializable interface, it allows to persist the state of an object.<br />
Java.lang.Clonebale: If JVM finds as a Class is implementing Clonebale interface, it performs some operation to support cloning.<br />
The interface which contains a single abstract method is called “Functional Interface”. In Java 8, we can annotate functional interfaces with the annotation @FunctionalInterface. This annotation performs the violations at compilation time.<br />
If an interface annotated with @FunctionalInterface and contains more/less than one abstract method, compiler throws an error as “Invalid '@FunctionalInterface' annotation; is not a functional interface”.<br />
package com.sample;<br />
<br />
@FunctionalInterface<br />
public interface CapitalCity {<br />
<br />
public abstract Integer getPropertyTaxPercent();<br />
<br />
}<br />
Popular Functional Interfaces in Java:<br />
public interface Runnable { void run(); } <br />
public interface Callable<v> { V call() throws Exception; } <br />
public interface ActionListener { void actionPerformed(ActionEvent e); } <br />
public interface Comparator<t> { int compare(T o1, T o2); boolean equals(Object obj); } <br />
Functional interface can:<br />
Have many number of default methods along with single abstract class. Since, default methods have already method definition.<br />
Override public methods of java.lang.Object class and mark them as abstract. The overridden methods from Object class will not be considered as its own abstract methods.<br />
Ex: java.util.Comporator has default, static methods and along with overridden methods from Object class. Functional interface implementation with inner class:<br />
<pre class="markdown">
```java
Thread thread = new Thread(new Runnable() {<br />
<br />
@Override<br />
public void run() {<br />
System.out.println(“This is a thread created with Runnable interface”);<br />
}<br />
});<br />
The functional interfaces can be converted as Lambda Expressions with the following syntax.<br />
(method arguments) -> {method body}<br />
```
</pre>
Ex:<br />
<pre class="markdown">
Thread thread = new Thread(() -> System.out.println("This is a thread created with Lambda Expression"));<br />
Comparator Interface:<br />
public class Employee {<br />
private Integer id;<br />
private String name;<br />
private Double salary;<br />
<br />
public Employee(Integer id, String name, Double salary) {<br />
this.id = id;<br />
this.name = name;<br />
this.salary = salary;<br />
}<br />
<br />
public Integer getId() {<br />
return id;<br />
}<br />
<br />
public void setId(Integer id) {<br />
this.id = id;<br />
}<br />
<br />
public String getName() {<br />
return name;<br />
}<br />
<br />
public void setName(String name) {<br />
this.name = name;<br />
}<br />
<br />
public Double getSalary() {<br />
return salary;<br />
}<br />
<br />
public void setSalary(Double salary) {<br />
this.salary = salary;<br />
}<br />
}<br />
<br />
public class EmpSorting {<br />
<br />
public void main(String[] args) {<br />
List<employee> employees =<br />
Arrays.asList(new Employee(1, "abc", new Double("10.00")),<br />
new Employee(3, "def", new Double("15.00")),<br />
new Employee(2, "ghi", new Double("5.00")));<br />
<br />
// Sort employees list with prior to Java 8 approach<br />
Collections.sort(employees, new Comparator<employee>() {<br />
<br />
@Override<br />
public int compare(Employee o1, Employee o2) {<br />
return o1.id.compareTo(o2.id);<br />
}<br />
});<br />
<br />
// Sorting employees list with Java 8 Lambda Expression<br />
Collections.sort(employees, (Employee o1, Employee o2) -> {return o1.id.compareTo(o2.id);});<br />
// Alos can be written as below. Here parameters datatypes can be auto detect<br />
Collections.sort(employees, (o1, o2) -> {return o1.id.compareTo(o2.id);});<br />
}<br />
}<br />
<br />
</pre>
</div>Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-86582123916066943482015-02-07T02:07:00.000-08:002015-02-16T04:40:45.567-08:00What is Type Erasure in Java Generics<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Introduction:</b><br />
Generics is one the most important features introduced in JDK 1.5.this feature is provided to perform compile-time checking and removing risk of ClassCastException that occures at runtime generally working with collections.<br />
<br />
The whole collection framework re-written to use generics for type-safety. Lets discuss, how we can avoid type-safety in JDK 1.5 through examples.<br />
<br />
<b>JDK 1.4 coding style:</b><br />
<pre class="brush:java">List collection = new ArrayList();
colection.add("This is a String object");
collection.add(new Integer(10));
collection.add(new UserdefinedObject());
for(int index = 0; index < collection.size(); index++) {
Integer int = (Integer) collection.get(index);
}
</pre>
Here, there is no type-check validation performed at compilation time. Hence, any kind of objected can be able to added the list. But while iterating at run-time there is no guarantee that all the elements are of type Integer. So there are more chances of getting ClasscastException.<br />
<br />
To overcome this limitation, generics are introduced in JDK 5.<br />
<br />
<b>JDK 1.5 coding style:</b><br />
<pre class="brush:java">List<Integer> collection = new ArrayList<Integer>();
collection.add(new Integer(10));
collection.add(new UserdefinedObject()); // Gives compilation error
for(Integer int : collection) {
// No explicit casting required, since the collcetion object have only Integer objects.
}
</pre>
<br />
<b>What is Type Erasure in Generics:</b><br />
To discuss this, lets take an example. We have a requirement to create two similar methods(overloading), one to accept list of Employee objects and another to accept list of Assests objects to perform required business logic.<br />
<br />
So, our code looks like as follows:<br />
<pre class="brush:java">public Double calculateCost(List<Employee> empList) {
// business logic
}
public Double calculateCost(List<Asset> assetList) (
// business logic
}
</pre>
The above gives compilation error, saying "Method has the same easure as another method in type".<br />
<br />
The reason for above compilation error is due to Java generics uses type erasure. It means that, Java generics is implemented on the compilation level. The byte code generated from compiler does not contain type information of generic type for the run-time execution.<br />
<br />
After compilation, both list of employee and list of assest become List.<br />
If we observe the code by using Java Decompiler, the code looks like below:<br />
<pre class="brush:java">public Double calculateCost(List empList) { }
public Double calculateCost(List assetList) { }
</pre>
Hence, while runtime both methods appears same signature. So JVM gets ambiguity to call which method to perform required operation.<br />
<br />
In the case of above situations, we can use <span class="_Tgc"><b>Wildcard characters</b></span> in the methods signature as follows:<br />
<pre class="brush:java">public Double calculateCost(List<?> list) { }
</pre>
<br />
<b>Note:</b> <br />
During the type erasure process, the Java compiler erases all type
parameters and replaces each with its first bound if the type parameter
is bounded or <tt>Object</tt> if the type parameter is unbounded.<br />
<br />
Reference : <a href="http://docs.oracle.com/javase/tutorial/java/generics/erasure.html" rel="nofollow" target="_blank">http://docs.oracle.com/javase/tutorial/java/generics/erasure.html</a><br />
. </div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-25677058516617414062014-10-08T08:57:00.000-07:002015-08-19T11:33:17.397-07:00Examples of Comparable, Comparator, equals() & hashCode()<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
We can discuss the use of Comparable, Comparator interfaces & equals(), hashCode() methods by using some problem description.<br />
<br />
In Java, there is an utility called Collections to perform most of the required operations on collection framework classes.<br />
One of the most frequently used operation is Sorting. We can do the sorting by using Collections.sort() method.<br />
Collections.sort() method has the following two forms.<br />
<br />
sort(List<t> list) - Sorts the specified list into ascending order, according to the natural ordering of its elements.<br />
sort(List<t> list, Comparator c) - Sorts the specified list according to the order induced by the specified comparator.<br />
<br />
Comparable and Comparator are two interfaces provided by Java Core API. From their names, we can tell they may be used for comparing stuff in some way. But what exactly are they and what is the difference between them?<br />
<br />
<b>Comparable:</b>Comparable is implemented by a class in order to be able to comparing object of itself with some other objects. The class itself must implement the interface in order to be able to compare its instance(s). The method required for implementation is compareTo().<br />
Objects which implement Comparable in java can be used as keys in a SortedMap like TreeMap or SortedSet like TreeSet without implementing any other interface.<br />
<br />
<b>Comparator:</b><br />
Class whose objects to be sorted do not need to implement this interface. Some third class can implement this interface to sort.<br />
Using Comparator interface, we can write different sorting based on different attributes of objects to be sorted.You can use anonymous comparator to compare at particular line of code.<br />
<br />
<br />
<t><t><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--> <table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="mso-cellspacing: 0in; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"> <td style="background: #8DB3E2; mso-background-themecolor: text2; mso-background-themetint: 102; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Parameter</span></b></div>
</td> <td style="background: #8DB3E2; mso-background-themecolor: text2; mso-background-themetint: 102; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Comparable</span></b></div>
</td> <td style="background: #8DB3E2; mso-background-themecolor: text2; mso-background-themetint: 102; padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Comparator</span></b></div>
</td> </tr>
<tr style="mso-yfti-irow: 1;"> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Sorting logic</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Sorting logic must be in same class whose objects are being sorted. Hence this is called natural ordering of objects</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Sorting logic is in separate class. Hence we can write different sorting based on different attributes of objects to be sorted. E.g. Sorting using id,name etc.</span></div>
</td> </tr>
<tr style="mso-yfti-irow: 2;"> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Implementation</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Class whose objects to be sorted must implement this interface.e.g Country class needs to implement comparable to collection of country object by id</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Class whose objects to be sorted do not need to implement this interface.Some other class can implement this interface. E.g.-CountrySortByIdComparator class can implement Comparator interface to sort collection of country object by id</span></div>
</td> </tr>
<tr style="mso-yfti-irow: 3;"> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<a href="https://draft.blogger.com/null" name="_GoBack"></a><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"><br />
Sorting method</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">int compareTo(Object o1)<br />
This method compares this object with o1 object and returns a integer.Its value has following meaning<br />
1. positive – this object is greater than o1<br />
2. zero – this object equals to o1<br />
3. negative – this object is less than o1</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">int compare(Object o1,Object o2)<br />
This method compares o1 and o2 objects. and returns a integer.Its value has following meaning.<br />
1. positive – o1 is greater than o2<br />
2. zero – o1 equals to o2<br />
3. negative – o1 is less than o1</span></div>
</td> </tr>
<tr style="mso-yfti-irow: 4;"> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Calling method</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Collections.sort(List)<br />
Here objects will be sorted on the basis of CompareTo method</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Collections.sort(List, Comparator)<br />
Here objects will be sorted on the basis of Compare method in Comparator</span></div>
</td> </tr>
<tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes;"> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Package</span></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Java.lang.Comparable</span></div>
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
</td> <td style="padding: 0in 0in 0in 0in;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Java.util.Comparator</span></div>
</td> </tr>
</tbody></table>
<br />
</t></t></t></t><t><t><t><t><b>equals() & hashCode() methods:</b></t></t></t></t><t><t><t><t><b> </b>In Java every object has access to equals() & hashCode() methods, since these are available in java.lang.Object class & Object class is super class by default for all the classes. The main intention of these methods are to compare the given two or more objects and identify their equality. </t></t></t></t><br />
<br />
The default implementation of <code>equals()</code> method in <code>Object</code> class simply checks if two
object references x and y refer to the same object. i.e. It checks if <code>x == y</code>. This particular comparison
is also known as "shallow comparison".<br />
<t><t><t><t></t></t></t></t><t><t><t><t><b> </b></t></t></t></t> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><br />
<!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style> <![endif]--> <br />
<div class="MsoNormal">
These two methods have significant relationship with each other. If we want to override any one of the methods, need to override both the methods. We will discuss why do we need to override both, otherwise what is the impact.</div>
<!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style> <![endif]--> <br />
<div class="MsoNormal">
<br />
The <code><span style="font-size: 10.0pt; line-height: 115%; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">equals()</span></code> method must exhibit the following properties:</div>
<ol style="text-align: left;">
<li><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Symmetry: For two references, </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">a</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"> and </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">b</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">, </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">a.equals(b)</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"> if and only if </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">b.equals(a)</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"></span></li>
<li><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Reflexivity: For all non-null references, </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">a.equals(a)</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"></span></li>
<li><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Transitivity: If </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">a.equals(b)</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"> and </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">b.equals(c)</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">, then </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">a.equals(c)</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"></span></li>
<li><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Consistency with </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">hashCode()</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">: Two equal objects must have the same </span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">hashCode()</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"> value</span></li>
</ol>
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; text-align: justify;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Why do we need to override equals() method:</span></b><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"> An object might have many number of variables, but we may
need to consider only few variables into consideration while comparing the
objects.</span></div>
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; text-align: justify;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Suppose,
customer landed on some eCommerce application and would like buy some article. Article
may have many number of properties such as name, capacity, cost, availability,
seller_name, seller_location, delivery_date..etc. But while coming to
comparison, customer may consider name, price & delivery_date.</span></div>
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Hence, it require to apply equals()
methods to lookup only these properties while determining equality. </span></div>
<div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%; mso-fareast-font-family: "Times New Roman";">Why to override hashCode() method:</span></b>
hashCode() method is used to get a unique integer for given object. This
integer is used for determining the bucket location, when this object needs to
be stored in some HashTable, HashMap like data structure. By default, Object’s
hashCode() method returns an integer representation of memory address where
object is stored.</div>
<div class="MsoNormal" style="text-align: justify;">
The hashCode() method of objects
is used when we insert them into a HashTable, HashMap or HashSet. More about <a href="http://en.wikipedia.org/wiki/Hashtable" target="_blank">hastables on
Wikipedia.org</a> for reference. </div>
<div class="MsoNormal" style="text-align: justify;">
To insert any entry in map data
structure, we need both key and value. If both key and values are user define data
types, the hashCode() of the key will be determine where to store the object
internally. When require to lookup the object from the map also, the hash code
of the key will be determine where to search for the object.</div>
<div class="MsoNormal" style="text-align: justify;">
The hash code only points to a
certain "area" (or list, bucket etc) internally. Since different key
objects could potentially have the same hash code, the hash code itself is no
guarantee that the right key is found. The HashTable then iterates this area
(all keys with the same hash code) and uses the key's equals() method to find
the right key. Once the right key is found, the object stored for that key is
returned. </div>
<div class="MsoNormal" style="text-align: justify;">
So, as we can see, a combination
of the hashCode() and equals() methods are used when storing and when looking
up objects in a HashTable.</div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b style="mso-bidi-font-weight: normal;"><u>NOTES:<span style="mso-spacerun: yes;"></span></u></b></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: .25in; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -.25in;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;">1.<span style="font: 7.0pt "Times New Roman";">
</span></span></span>Always use same attributes of an object to
generate hashCode() and equals() both. As in our case, we have used employee
id.</div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: .25in; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -.25in;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;">2.<span style="font: 7.0pt "Times New Roman";">
</span></span></span>equals() must be <i>consistent</i> (if the
objects are not modified, then it must keep returning the same value).</div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: .25in; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -.25in;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;">3.<span style="font: 7.0pt "Times New Roman";">
</span></span></span>Whenever <b>a.equals(b)</b>, then <i>a.hashCode()</i>
must be same as <i>b.hashCode()</i>.</div>
<div class="MsoListParagraphCxSpLast" style="margin-left: .25in; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -.25in;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;">4.<span style="font: 7.0pt "Times New Roman";">
</span></span></span>If you override one, then you should override
the other.</div>
<br />
<span style="font-size: small;"><b>Problem Statement:</b></span><br />
There are 2 travel companies who have buses travelling from dest A to dest B. they want to merge their buses timetable and produce it to the customer so that they can find out which bus is effective for them and choose bus accordingly(o/p).<br />
<br />
They will provide a text file having the I/P as shown above and we need to give O/P as shown above.<br />
<br />
<b>Conditions:</b><br />
1) If the bus travel time is greater than 1hr then it should not be displayed.<br />
2) If the both the travel agency having same time of dept and arrival then we need to show only volvo travel time and ignore BMW.<br />
3) we need to format O/P as<br />
a) if busA starts at 10 and arrives at 11, if busB starts at 10:05 and arrives at 11, then busB has to come before busA.<br />
b) if busA starts late and arrives before busB,then busA has to come before busB.<br />
c) if busA starts at same time as busB but reaches before,then busA has to come before busB.<br />
<br />
<b>Input file:</b></div>
<br />
<br />
<pre class="brush:java">volvo 10:10 11:05
volvo 10:15 11:05
volvo 11:00 12:15
volvo 11:50 12:50
volvo 12:00 12:45
BMW 10:05 11:05
BMW 10:10 11:05
BMW 10:50 11:45
volvo 10:50 11:45
BMW 11:05 12:15
</pre>
<br />
Output:<br />
<pre class="brush:java">volvo 10:15 11:05
volvo 10:10 11:05
BMW 10:05 11:05
volvo 10:50 11:45
volvo 12:00 12:45
volvo 11:50 12:50
</pre>
<br />
<b>BusInfoVO:</b> Its a Data transfer object which holds the information of a bus.<br />
<pre class="brush:java" name="code">package com.exer.files.vo;
import java.io.Serializable;
import java.util.Date;
public class BusInfoVO implements Comparable<BusInfoVO>, Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String busType;
private Date startTime;
private Date endTime;
private transient Long duration;
public String getBusType() {
return busType;
}
public void setBusType(String busType) {
this.busType = busType;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public Long getDuration() {
return duration;
}
public void setDuration(Long duration) {
this.duration = duration;
}
@Override
public int compareTo(BusInfoVO busInfo) {
if((this.getStartTime().equals(busInfo.getStartTime())) && (this.getEndTime().equals(busInfo.getEndTime()))) {
return 0;
} if((this.getStartTime().equals(busInfo.getStartTime())) || (this.getEndTime().equals(busInfo.getEndTime()))) {
return this.getDuration() < busInfo.getDuration() ? -1 : 1;
} else if((this.getStartTime().after(busInfo.getStartTime())) && (this.getEndTime().before(busInfo.getEndTime()))) {
return -1;
} else if(this.getStartTime().before(busInfo.getStartTime())) {
return -1;
}
return 1;
}
@Override
public boolean equals(Object busInfo) {
boolean result = false;
if (busInfo == null || (this.getClass() != busInfo.getClass())) {
return result;
}
BusInfoVO other = (BusInfoVO) busInfo;
if((this.getStartTime().equals(other.getStartTime())) && (this.getEndTime().equals(other.getEndTime()))) {
return true;
}
return result;
}
@Override
public int hashCode() {
int hash = 10;
hash = hash + this.getStartTime().getHours() + this.getStartTime().getMinutes();
hash = hash + this.getEndTime().getHours() + this.getEndTime().getMinutes();
return hash;
}
}
</pre>
<br />
Here BusInfoVO class implementing Comparable interface and overrides compareTo() method.<br />
<br />
<b>FilesReader.java:</b> Where data can be read and processed as expected output.<br />
<pre class="brush:java">package com.exe.files.reader;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;
import com.exer.files.vo.BusInfoVO;
public class FilesReader {
private static DateFormat dateFormat = new SimpleDateFormat("HH:mm");
private List<BusInfoVO> busInfoVOList;
public List<BusInfoVO> getBusInfoVOList(String path) {
if(path != null) {
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
busInfoVOList = new ArrayList<BusInfoVO>();
for (int i = 0; i < listOfFiles.length; i++) {
try (Scanner scanner = new Scanner(listOfFiles[i])) {
while (scanner.hasNextLine()) {
String[] info = scanner.nextLine().toString().split(" ");
if (info != null && info.length > 0) {
BusInfoVO vo = new BusInfoVO();
vo.setBusType(info[0]);
Date startTime = dateFormat.parse(info[1]);
Date endTime = dateFormat.parse(info[2]);
vo.setStartTime(startTime);
vo.setEndTime(endTime);
vo.setDuration((endTime.getTime() - startTime.getTime()) / (60 * 1000)); // In minutes.
if(vo.getDuration() <= 60) {
busInfoVOList.add(vo);
}
}
}
} catch(ParseException | FileNotFoundException exp) {
exp.printStackTrace();
}
}
Collections.sort(busInfoVOList, new Comparator<BusInfoVO>() {
@Override
public int compare(BusInfoVO o1, BusInfoVO o2) {
return o2.getBusType().compareTo(o1.getBusType());
}
});
return busInfoVOList;
}
return null;
}
public static void main(String[] args) throws ParseException, FileNotFoundException {
String path = "D:\\PARAMESH\\FILES";
FilesReader reader = new FilesReader();
List<BusInfoVO> list = reader.getBusInfoVOList(path);
TreeSet<BusInfoVO> set = new TreeSet<BusInfoVO>();
for(BusInfoVO vo : list) {
set.add(vo);
}
for(BusInfoVO vo : set) {
System.out.println(vo.getBusType() + " " + dateFormat.format(vo.getStartTime()) + " " + dateFormat.format(vo.getEndTime()));
}
}
}
</pre>
<br />
Here, we used(@ L 50) "sort(List<T> list, Comparator c)" method to sort the list based on the name field of BusInfoVO.<br />
<br />
While adding to the set.add(vo) (@L 69), its looks for the equals() method definition available in BusInfoVO class and compares the given object with all existing objects in the set.<br />
If equals returns : true - Will add the given object to the set.<br />
false - Will not add the given object to the set. <br />
Also, when we add the elements in TreeSet, it internally calls compareTo() method available in the given for sorting.</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-7616553883714877762014-03-13T10:52:00.001-07:002014-06-04T05:56:44.692-07:00Best approach for formatting date in java<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">The most common approach to format the date as required by using SimpleDateFormat.<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">This approach causes problems when multiple threads access the same instance of the class variable, due to lack of synchronization.<o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">The note from JAVA API is </span><span style="background: white; color: #333333; font-family: "Times New Roman","serif"; font-size: 12.0pt;"><a href="http://docs.oracle.com/javase/6/docs/api/java/text/DateFormat.html">“Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.”</a></span><span style="font-family: 'Times New Roman', serif; font-size: 12pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="font-family: 'Times New Roman', serif; font-size: 12pt;">The below are the most frequent exceptions will occurs:</span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"></div><ul style="text-align: left;"><li><span style="background-color: white; color: #333333; font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 19.8pt; text-indent: -18pt;">java.lang.NumberFormatException</span></li>
<li><span style="background-color: white; color: #333333; font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 19.8pt; text-indent: -18pt;">java.lang.ArrayIndexOutOfBoundsException</span></li>
</ul><br />
<div class="MsoNormal"><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%;">There are two approaches to handle these exceptions in Multi-threading environment.</span></div><div class="MsoNormal"></div><ol style="text-align: left;"><li><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%; text-indent: -18pt;">By using ThreadLocal<SimpleDateFormat>: ThreadLocal</span><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%; text-indent: -18pt;"> is a best appraoch to implement Per Thread Singleton classes or per thread context information.</span></li>
<li><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%; text-indent: -18pt;">FastDateFormat.</span><i style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%; text-indent: -18pt;">getInstance(): </i><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%; text-indent: -18pt;">FastDateFormat is available in <b>commons-lang-version.jar</b>. it has several overloaded methods of <b>getInstance()</b> to provide the date format for Thread-safe environment. Please find the API documents</span><i style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%; text-indent: -18pt;"> <a href="https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/time/FastDateFormat.html">here</a>.</i></li>
</ol><div class="MsoListParagraphCxSpLast" style="mso-list: l2 level1 lfo3; text-indent: -18.0pt;"><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%;"><i><br />
</i></span></div><b>Sample code snippet by using SimpleDateFormat:</b><br />
<pre class="brush:java" name="code">package com.samples;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SimpleDateFormatExample {
private static DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
public static void main(String[] args) {
Date currentDate = new Date();
System.out.println("Current Time: " + dateFormat.format(currentDate));
}
}
</pre><br />
<br />
<br />
<b>Sample code snippet by using ThreadLocal:</b><br />
<pre class="brush:java" name="code">package com.samples;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ThreadLocalDateFormatExample {
private static ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>() {
protected DateFormat initialValue() {
return new SimpleDateFormat("MM/dd/yy");
}
};
public static void main(String[] args) {
Date currentDate = new Date();
System.out.println("Current Time: " + dateFormat.get().format(currentDate));
}
}
</pre><br />
<br />
<b>Sample code snippet by using FastDateFormat:</b><br />
<pre class="brush:java" name="code">package com.samples;
import java.util.Date;
import org.apache.commons.lang.time.FastDateFormat;
public class FastDateFormatExample {
private static final FastDateFormat dateFormat = FastDateFormat.getInstance("dd-MM-yyyy");
public static void main(String[] args) {
Date currentDate = new Date();
System.out.println("Current Time: " + dateFormat.format(currentDate));
}
}
</pre><br />
Hence, the best approach is to format the date isby using FastDateFormat if your project has commons-lang.jar dependency, otherwise can use Threadlocal approach.</div>Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-18359927512981347832014-03-05T10:36:00.000-08:002014-03-05T11:36:19.054-08:00Unix basic commands<div dir="ltr" style="text-align: left;" trbidi="on">
Below are the few basic Unix commands which will be more useful for Java developers who are working in Unix environment.<br />
<br />
<b>List all users:</b><br />
<b>$ </b>cat /etc/passwd |grep "/home" |cut -d: -f1<br />
<b>$ </b>awk -F":" '{ print "username: " $1 "\t\tuid:" $3 }' /etc/passwd<br />
<br />
The above commands will list all the users in the system.<br />
<br />
<b>Some Basic commands:</b><br />
<b>$ </b>cd path - change directory.<br />
<b>$ </b>mv path1/filename1 path2/filename2 - Move files from one directory to another directory.<br />
<b>$ </b>ls [options]- list the file names.<br />
<b>$ </b>ll [options]- list the file names with permissions and size.<br />
<b>$ </b>cp path/filename1 path2/filename2 - Copy files from one directory to another directory.<br />
<b>$ </b>cat filename - To print the content of the file.<br />
<b>$ </b>diff filenmae1 filename2 - To view the differences between two files.<br />
<b>$ </b>./filename.sh - To run sh files. This is mostly used for executing shell scripts and server stop start.<br />
<b>$ </b>view filename - To view the content of the file.<br />
<b>$ </b>vi filename - To view and update the file.<br />
<b>$ </b>top<span class="Apple-tab-span" style="white-space: pre;"> </span>- To check the CPU performance and utilization.<br />
<b>$ </b>df<span class="Apple-tab-span" style="white-space: pre;"> </span>- To check the disk space utilized.<br />
<br />
vi & view editor commands:<br />
----------------------------<br />
When a opened a file with vi/view command, the file will open in command mode as default. To make changes in the files needs bring to "Insert Mode".<br />
i/<Ins> - insert text before cursor, until <Esc> hit. Also called "Insert Mode".<br />
I <span class="Apple-tab-span" style="white-space: pre;"> </span>- insert text at beginning of current line, until <Esc> hit<br />
<Esc> <span class="Apple-tab-span" style="white-space: pre;"> </span>- Change to "Command Mode".<br />
<br />
:w <span class="Apple-tab-span" style="white-space: pre;"> </span>- saves the current file without quitting<br />
:# <span class="Apple-tab-span" style="white-space: pre;"> </span>- move to line #<br />
:$ <span class="Apple-tab-span" style="white-space: pre;"> </span>- move to last line of file<br />
?string - Search backward for string<br />
/string - Search forward for string<br />
n<span class="Apple-tab-span" style="white-space: pre;"> </span>- move to next occurrence of search string<br />
N<span class="Apple-tab-span" style="white-space: pre;"> </span>- move to next occurrence of search string in opposite direction<br />
<Esc>:w! - Saves the file<br />
<Esc>:q! - Quit editing, no save<br />
<br />
<b>Create a .jar file:</b><br />
<b>$</b> jar -cvf <file_namer.jar> <class_file_path><br />
<br />
To work with above command, first we need to change the directory to JDK installed bin directory and execute the command.<br />
<br />
Ex:<br />
<b>$</b> /opt/WebSphere7/AppServer/java/bin/jar -cvf calculator.jar com/calc/Calculator.class<br />
<b>$</b> /opt/WebSphere7/AppServer/java/bin/jar -cvf ibank.jar com/calc/*.class<br />
<br />
The second command is useful when there are multiple class to be include in a jar. the path /opt/WebSphere7/AppServer/java/bin is a JDK installed path from whepsher server.<br />
<br />
<br />
<b>Update a .jar file:</b><br />
<b>$ </b>jar -uvf <file_namer.jar> <class_file_path><br />
<br />
Ex:<br />
<b>$</b> /opt/WebSphere7/AppServer/java/bin/jar -uvf calculator.jar com/calc/Calculator.class<br />
<b>$</b> /opt/WebSphere7/AppServer/java/bin/jar -uvf calculator.jar com/calc/*.class<br />
<br />
<b>Unzar a .jar file:</b><br />
<b>$</b> jar -xvf <file_namer.jar><br />
<br />
Ex:<br />
<b>$</b> /opt/WebSphere7/AppServer/java/bin/jar -xvf calculator.jar<br />
Once the above command executed, we will get the class files in unix files system. So first we need to change the directory where we need the files to be located and provide bin full path while executing the command.<br />
If we not change the directory and executed from JDK installed path, all extracted files will be placed in JDK installed path.<br />
<br />
<b>Find a Class file in .jar file:</b><br />
<b>$ </b>grep classname *.jar<br />
<br />
Ex:<br />
<b>$ </b>grep com/calc/Calculator.class *.jar<br />
<b>$ </b>grep Ibank.class *.jar<br />
<br />
To Know the package exactly:<br />
<b>$</b> /opt/WebSphere7/AppServer/java/bin/jar -tvf calculator.jar|grep Calculator*<br />
<br />
<b>Check HTTP Server status:</b><br />
<b>$ </b>ps -efw|grep httpd<br />
<br />
File system size:<br />
When we are facing with file system space issue and not able to find which directory occupies more memory, use the below command.<br />
<br />
<b>$ </b>du -sm *| sort -nr | head -15<br />
<b>$ </b>du -sh * | sort -nr | more<br />
<br />
To transfer tar files from one IP to another IP:<br />
Login to the IP address, where the file is available and execute the below command.<br />
<b>$ </b>/usr/local/openssh/bin/scp <path>/<file_name> <userid>@<ip_address>:/tmp/<br />
<br />
<br /></div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-89188002063396528902014-01-30T09:42:00.000-08:002014-01-30T20:14:43.656-08:00Spring Annotations<div dir="ltr" style="text-align: left;" trbidi="on">
<h1>
Introduction:</h1>
In Spring, XML based configurations is the most popular configuration style. Spring uses annotations as an alternative to XML for declarative configuration.<br />
<br />
To make annotations and work in spring, use the <context:component-scan> tag in spring bean configuration file. So that spring will scan and find out the beans and register in the Spring Container.<br />
<br />
Syntax:<br />
<pre class="brush:java" name="code"><context:component-scan base-package="basepackage">
</context:component-scan></pre>
Ex:<br />
<pre class="brush:java" name="code"><context:component-scan base-package="com.parmi.blog">
</context:component-scan></pre>
<b>Note:</b> If it requires adding multiple packages to scan, use comma separator.<br />
<br />
<b>Auto Components Scan Annotation Types:</b><br />
In Spring, there are 4 types of auto components scan annotation types<br />
<ul>
<li>@Component – Indicates an auto scan component.</li>
<li>@Repository – Indicates DAO component in the persistence layer.</li>
<li>@Service – Indicates a Service component in the business layer.</li>
<li>@Controller – Indicates a controller component in the presentation layer.</li>
</ul>
<br />
<context:annotation-config> is used to activate annotations in beans already registered in the application context.<br />
<br />
<b>Component-scan vs annotation-config:</b><br />
<context:annotation-config>: Only registers 4 BeanPostProcessors that are part of the Spring Framework and have specific configuration objectives.<br />
<ul>
<li>CommonAnnotationBeanPostProcessor: Recognizes and processes the JSR 250 common annotations (@PostConstruct, @PreDestroy, @Resource).<br />
</li>
<li>AutowiredAnnotationBeanPostProcessor: Recognizes the Autowired related annotations (@Autowired, @Value, @Inject, @Qualifier, etc)<br />
</li>
<li>RequiredAnnotationBeanPostProcessor: Recognizes the @Required annotation<br />
</li>
<li>PersistenceAnnotationBeanPostProcessor: Recognizes the @PersistenceUnit and @PersistenceContext annotations (related to JPA).<br />
</li>
</ul>
All of these annotations are typically placed either on a class field, constructor or method. <context:component-scan>: is a super set of the <context:annotation-config> tag. It registers the same bean post processors and also will perform component scanning. It looks for classes in the given base-package that are annotated with a category of annotations (@Component, @Repository, @Controller, etc). The purpose of using <context:component-scan> is to provide an alternative way to 'discover' Spring components other than using XML. </context:component-scan><br />
<h2>
Spring related Annotations:</h2>
Below are the few important spring related annotations and their package.<br />
<div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;"><tbody>
<tr> <td style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpFirst" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<b><span lang="EN-US">Spring Annotation<o:p></o:p></span></b></div>
</td> <td style="background: #C6D9F1; border-left: none; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<b><span lang="EN-US">Package<o:p></o:p></span></b></div>
</td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@Controller</span></div>
</td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">org.springframework.stereotype.Controller</span></div>
</td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@RequestMapping</span></div>
</td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">org.springframework.web.bind.annotation.RequestMapping</span></div>
</td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@RequestParam</span></div>
</td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">org.springframework.web.bind.annotation.RequestParam</span></div>
</td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@PathVariable</span></div>
</td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">org.springframework.web.bind.annotation.PathVariable</span></div>
</td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@ModelAttribute</span></div>
</td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">org.springframework.web.bind.annotation.ModelAttribute</span></div>
</td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@SessionAttributes</span></div>
</td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">org.springframework.web.bind.annotation.SessionAttributes</span></div>
</td> </tr>
<tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@PreAuthorize</span></div>
</td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">org.springframework.security.access.prepost.PreAuthorize</span></div>
</td> </tr>
</tbody></table>
<h2>
@Controller Annotation:</h2>
The @Controller annotation indicates that a particular class serves the role of a controller. The controller class is no longer need to extends any of base controllers. When we @Controller annotation, its mandatory to use @RequestMapping annotation. This annotation is used to map a particular http/https request. <br />
<h2>
@RequestMapping Annotation:</h2>
This annotation can be used at both class level and method level. In case of multi-action controller, it’s recommended to use this annotation at method level and also at class level if required.<br />
<b><br /></b>
<b>Syntax at class level:</b> @RequestMapping("/<path>") </path><br />
<path><b>Syntax at method level:</b> @RequestMapping(value = “/<path>”, method = RequestMethod.[GET/POST]) </path></path><br />
<path><path><br /></path></path>
<path><path>We can use wildcard characters like * for path pattern matching. </path></path><br />
<path><path><b><br /></b></path></path>
<path><path><b>Simple scenario:</b> </path></path><br />
<pre class="brush:java" name="code">@Controller
@RequestMapping("/blogspot")
public class blogspotController {
@RequestMapping(value="/properties")
public String findAllProperties(){
}
}
</pre>
<b>Testing URL:</b> /blogspot/properties<br />
<b><br /></b>
<b>Request parameter binding:</b> <br />
<pre class="brush:java" name="code">@RequestMapping(value="/properties")
public String findByProperty(@RequestParam("propertyId") String propertyId){
}
</pre>
<b>Testing URL:</b> /blogspot/properties?propertyId =<some_id><br />
<b><br /></b>
<b>Extracting path variables:</b> <br />
<pre class="brush:java" name="code">@RequestMapping(value="/blogspot/{propertyId}")
public String findByProperty(@PathVariable String paropertyId){
}
</pre>
(OR) <br />
<pre class="brush:java" name="code">@RequestMapping(value="/blogspot/{propertyId}")
public String findByProperty(@PathVariable("propertyId") String somePropertyId){
}
</pre>
<b>Testing URL:</b> /blogspot/properties/propertyId/23<br />
<b><br /></b>
<b>Extracting multiple path variables:</b> <br />
<pre class="brush:java" name="code">@RequestMapping(value="/properties/{propertyId}/owner/{ownerId}")
public String findByProperty( @PathVariable String propertyId, @PathVariable String ownerId){
}
</pre>
<b>Testing URL:</b> /blogspot/ properties/23/owner/39<br />
<br />
<b>Extracting regular expressions:</b> <br />
<pre class="brush:java" name="code">@RequestMapping(value="/{textualPart:[a-z-]+}.{numericPart:[\\d]+}")
public String regularExpression( @PathVariable String textualPart, @PathVariable String numericPart){
}
</pre>
<b>Testing URL:</b> /blogspot/text_chars.123 <br />
<h2>
@RequestParam Annotation:</h2>
It’s a method argument annotation. This @RequestParam annotation can be used for getting the parameters from the request(query parameters). The scope of the variable passed is method scope. <b>Syntax:</b> <br />
<pre class="brush:java" name="code">@RequestParam(value = “requestParam”, required = true/false, defaultValue = "defaultVal") dataTye variableName)
</pre>
<b>Ex:</b> <br />
<pre class="brush:java" name="code">public void printPageInfo(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber)
</pre>
<h2>
@PathVariable Annotation:</h2>
It’s a method argument annotation. The @PathVariable annotation can be used for getting the value of URI template variable. <b>Syntax:</b> <br />
<pre class="brush:java" name="code">@PathVariable("pathVarName") dataTyep variableName)
</pre>
Ex: If we want to create a controller that would allow users to see view pages by using a URL as below http://parameshk.blogspot.in/search/label/Java - display details for java http://parameshk.blogspot.in/search/label/Spring - display details for spring <br />
<pre class="brush:java" name="code">@Controller
@RequestMapping("/search")
public class ShowPagesController {
@RequestMapping("/label/{labelName}") // Handle any request of the form "/label/XXXXX"
public String showProduct(Model model, @PathVariable("labelName") String labelName) {
}
}
</pre>
<h2>
@ModelAttribute Annotation:</h2>
It supports RequestMapping annotated handler classes. It binds a method parameter or method return value to a named model attribute that exposed to a web view. Uses of @ModelAttribute: Useful to read data from an existing model by assigning it to handler method parameters. If a view/jsp want to populate some values while onload, we can inject the data to jsp by using this annotation. Ex: Below is the code snippet, which binds Employee object to a view page. Code snippet in controller: <br />
<pre class="brush:java" name="code">@RequestMapping(value="/property-details")
public ModelAndView processPerson(@ModelAttribute Property prop) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("property-details");
modelAndView.addObject("property", prop);
return modelAndView;
}
</pre>
Code snippet in jsp/view page: <br />
<pre class="brush:java" name="code">Property Details:
Property Name: ${ property.name}
Property Location: ${ property.location}
Property Owner: ${ property.owner}
</pre>
<h2>
@ SessionAttributes Annotation:</h2>
The @SessionAttributes annotation is used to store the model object in the session. It is used on the Controller class level to declare used session attributes. All Model attributes having names or types defined in this annotation will be automatically persisted and restored between the subsequent requests. It’s a very small declaration instead of using HttpSession's getAttribute() & setAttribute() calls. Model attributes are persisted at the end of request handling by AnnotationMethodHandlerAdapter, after calling the handler method responsible for request handling and after determining the ModelAndView for the response. Their names in Model are used as their names in the persistent storage. Ex: @SessionAttributes("form") will trigger persisting Model attribute named "form" as HttpSession attribute named "form". Persisted Model attributes will be removed only when SessionStatus.setComplete() method called in handler methods. Ex: <br />
<pre class="brush:java" name="code">@Controller
@RequestMapping(value="/dashboard", method=RequestMethod.POST)
@SessionAttributes("property")
public class LoginController {
@RequestMapping(value="/authenticate",method=RequestMethod.POST)
public String authenticate(@RequestParam String propertyId, Model model){
Property property = new Property();
property.setPropertyId(propertyId);
property.setName("PPB_1");
property.setLocation("USA");
model.addAttribute("property", property);
return "xxxxx";
}
}
</pre>
<b>Note:</b> To store multiple objects in @SessionAttributes use comma separator. <br />
<br />
<h1>
RESTful Web Service - JAX-RS Annotations:</h1>
<ul>
<li>Jersey, the reference implementation of JAX-RS, implements support for the annotations defined in JSR 311, making it easy for developers to build RESTful web services by using the Java programming language.</li>
<li>REST is an architectural style which is based on web-standards and the HTTP protocol.</li>
<li>In REST based architecture everything is a resource. A resource is accessed via a common interface based on the HTTP standard methods.</li>
<li>In a REST based architecture you typically have a REST server which provides access to the resources and a REST client which accesses and modify the REST resources. </li>
<li>Every resource should support the HTTP common operations. Resources are identified by global IDs (which are typically URIs). </li>
<li>REST allows that resources have different representations, e.g. text, xml, json etc. The rest client can ask for specific representation via the HTTP protocol (content negotiation). </li>
</ul>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;"><tbody>
<tr> <td style="background: #C6D9F1; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpFirst" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<b><span lang="EN-US">JAX-RS Annotation<o:p></o:p></span></b></div>
</td> <td style="background: #C6D9F1; border-left: none; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<b><span lang="EN-US">Package<o:p></o:p></span></b></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@Path</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.Path</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@Produces</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.Produces</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@Consumes</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.Consumes</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@GET</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.GET</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@POST</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.POST</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@PUT</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.PUT</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@DELETE</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.DELETE</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@FormParam</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.FormParam</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@PathParam</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.PathParam</span></div>
</td> </tr>
<tr> <td style="background: white; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">@QueryParam</span></div>
</td> <td style="background: white; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 239.4pt;" valign="top" width="319"><div class="MsoNormalCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-align: justify;">
<span lang="EN-US">javax.ws.rs.QueryParam</span></div>
</td> </tr>
</tbody></table>
<h2>
</h2>
<h2>
@Path Annotation:</h2>
It’s a both class & method level annotation. This identifies the URI path template to which the resource responds. The @Path annotation's value is a partial URI path template relative to the base URI of the server on which the resource is deployed, the context root of the WAR, and the URL pattern to which the Jersey helper servlet responds.<br />
<b><br /></b>
<b>Syntax:</b><br />
@Path("/uri")<br />
<br />
The @Path annotation is not limited to simple path expressions. We can also have the ability to insert regular expressions into @Path's value.<br />
<br />
<b>Syntax:</b> @Path (“uri/{variable[:regular-expression]}”)<br />
<b>Ex:</b> <br />
<pre class="brush:java" name="code">import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/properties")
public class UserRestService {
@GET
public Response getProperties() {
//TODO provide method body
}
//Target Url: /properties
@GET
@Path("/ppb")
public Response getPropertyPPB() {
//TODO provide method body
}
//Target Url: /properties/ppb
@GET
@Path("{name}")
public Response getPropertyByName(@PathParam("name") String name) {
//TODO provide method body
}
//Target Url: /properties/abcdefg
@GET
@Path("{id : \\d+}") //id is regular expression which accepts only numbers
public Response getPropertyById(@PathParam("id") String id) {
//TODO provide method body
}
//Target Url: /properties/1234
@GET
@Path("/propertyname/{propertyname : [a-zA-Z][a-zA-Z_0-9]+}")
public Response getPropertyByPropertyName(@PathParam("propertyname") String propertyname) {
//TODO provide method body
}
//Target Url: /properties/propertyname/myproperty123
}
</pre>
<h2>
@Consumes Annotation:</h2>
The @Consumes annotation is used to specify which MIME media types of representations, a resource can accept/ consume from the client. @Consumes annotation can be applied at both the class and method levels. If it’s applied at class level, by default all the methods will accept the same MIME type. If it’s applied at the method level, overrides the class level annotation if applied. The possible MIME types which can be used for this annotation can be available in the class javax.ws.rs.core.MediaType.<br />
<b><br /></b>
<b>Syntax: </b><br />
@Consumes(MediaType.XXX) @Consumes({MediaType.XXX, MediaType.YYY, …}) <br />
<h2>
@Produces Annotation:</h2>
The @Produces annotation is used to specify the MIME media types of representations a resource can produce and send back to the client. @Produces annotation can be applied at both the class and method levels. If it’s applied at class level, by default all the methods will accept the same MIME type. If it’s applied at the method level, overrides the class level annotation if applied. The possible MIME types which can be used for this annotation can be available in the class javax.ws.rs.core.MediaType.<br />
<br />
<b>Syntax: </b><br />
@Produces (MediaType.XXX) @Produces ({MediaType.XXX, MediaType.YYY, …}) <br />
<h2>
@GET, @PUT, @POST, @DELETE & @HEAD Annotations:</h2>
@GET, @PUT, @POST, @DELETE and @HEAD are resource method designator annotations defined by JAX-RS and which correspond to the similarly named HTTP methods. In the example above, the annotated Java method will process HTTP GET requests. The behavior of a resource is determined by which of the HTTP methods the resource is responding to. <br />
<ul>
<li>GET defines a reading access of the resource without side-effects. The resource is never changed via a GET request, e.g. the request has no side effects (idempotent). </li>
<li>PUT creates a new resource, must also be idempotent. </li>
<li>DELETE removes the resources. The operations are idempotent, they can get repeated without leading to different results. </li>
<li>POST updates an existing resource or creates a new resource. </li>
</ul>
<h2>
@QueryParam Annotation:</h2>
Binds the value of a HTTP query parameter to a resource method parameter or resource class field or resource class bean property. A default value can be specified using the @DefaultValue annotation. <b>Syntax: </b> <br />
<pre class="brush:java" name="code">@QuaryParam(“param1”) @DefaultValue(“defaultVal”) datatype varName
</pre>
Ex: <br />
<pre class="brush:java" name="code">@QuaryParam(“param1”) @DefaultValue(“defaultVal”) datatype varName
</pre>
<br />
Ex:<br />
<pre class="brush:java" name="code">@GET
@Path("eligibleBooks")
public ProductInfos getEligibleProducts(
@QueryParam("category") @DefaultValue("JAVA") String category,
@QueryParam(bookId) String bookId,
@QueryParam("bookName") String bookName,
@QueryParam("accountType") String accountType,
@QueryParam("countryCode") @DefaultValue("US") String countryCode) {
//TODO method body
}
</pre>
<br />
<b>Target URL:</b> /eligibleBooks?category=JAVA&bookId=1234&bookName=abcd123&accountType=technology&countryCode=IN</div>
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-76426079993810261682013-12-03T08:58:00.000-08:002013-12-27T06:45:12.023-08:00Java Program that provides optimized solution for a builder<div dir="ltr" style="text-align: left;" trbidi="on"><br />
Write a java program to provide the optimised solution for the below requirements.<br />
<ol><li>Program should have three input parameters:<br />
<ol type="a"><li>Total number of rooms</li>
<li>Minimum rooms per building</li>
<li>Maximum room per building.</li>
</ol></li>
<li>Should calculate the number of rooms per building between min-max number provided<br />
<li>Choose a factor that gives minimum reminder<br />
<li>If there are more than one factor giving minimum reminder, choose the highest factor.<br />
</ol><b>Program:</b> <pre class="brush:java" name="code">package com.builder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BuildingOptimizer {
/**
* @param args
*/
public static void main(String[] args) {
printOptimizedSolution(16, 4, 8);
}
public static void printOptimizedSolution(int totalNum, int minNum, int maxNum) {
Map<Integer, Integer> reminderMap = new HashMap<Integer, Integer>();
StringBuffer output = new StringBuffer("Optimised Solution is : " );
for(int statNum = maxNum; statNum <= minNum; statNum--) {
if(totalNum % statNum == 0) {
reminderMap.put(0, statNum);
break;
}
}
if(reminderMap.size() == 0) {
for(int statNum = minNum; statNum <= maxNum; statNum++) {
reminderMap.put((totalNum % statNum), statNum);
}
}
List<Integer> remindersList = new ArrayList<Integer>(reminderMap.keySet());
Collections.sort(remindersList);
Integer devider = reminderMap.get(remindersList.get(0));
Integer divisions = totalNum / devider;
for(int i = 1; i <= divisions; i++ ) {
output.append(devider);
if(i != divisions) {
output.append(", "); // comma should not append at the end
}
}
if(remindersList.get(0) != 0) {
output.append(", ").append(remindersList.get(0));
}
System.out.println(output);
}
}
</pre></div>Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-64573429817314938742013-11-20T13:03:00.000-08:002013-11-20T13:11:05.851-08:00Why wait() ,notify() and notifyAll() methods are in Object class instead of Thread class?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<div class="MsoNormal">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">These methods works on the locks and
locks are associated with Object and not Threads. Hence, it is in Object class.</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"><br /></span></div>
</div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">The methods wait(), notify() and
notifyAll() are not only just methods, these are synchronization utility and
used in communication mechanism among threads in Java. <o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b><span style="background: white; color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">Synchronization:</span></b><span style="background: white; color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;"> The concept of synchronization will make sure that only one
Thread is accessing an object/resource at the same time.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">Java concurrency model uses <b>locks</b> to
implement mutually exclusive access to objects in a multi-threaded environment.
Locks are associated with objects not with the Threads. Hence, Locks are
made available on per Object basis.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"> In Java, to achieve mutually
exclusive access on objects, a threads needs to acquire lock and other threads
needs to wait to acquire lock. And they don’t know which threads holds lock
instead they just know the lock is hold by some other thread and they should
wait for lock instead of knowing which thread is inside the synchronized block
and asking them to release lock. This analogy fits with wait and notify being
on object class rather than thread in Java.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">Example:</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhprjbe2E-DnvNvowYJg9BHxQveAWxf8S06jhkJd3WItTmDlrsrg5FDB5ew1fsgyAr9Bo05agC9E6JibzbFExZXQ-5u4gJNS8ABIAKsniJofhAuHlHlRM6GCfkGuT8ZHwunmADaZ-oO-vjP/s1600/Object_Lock_Ex.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhprjbe2E-DnvNvowYJg9BHxQveAWxf8S06jhkJd3WItTmDlrsrg5FDB5ew1fsgyAr9Bo05agC9E6JibzbFExZXQ-5u4gJNS8ABIAKsniJofhAuHlHlRM6GCfkGuT8ZHwunmADaZ-oO-vjP/s320/Object_Lock_Ex.png" width="256" /></a></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"> <v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape id="Picture_x0020_17" o:spid="_x0000_i1025" style="height: 355.5pt; mso-wrap-style: square; visibility: visible; width: 287.25pt;" type="#_x0000_t75">
<v:imagedata cropbottom="1221f" o:title="" src="file:///C:\Users\1361606\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">I would like to discuss with a well
known example to get a clear understanding of this topic. Let’s take a real time
banking scenario. Suppose two or more customers having a joint account, which
can be permitted to perform the transactions through multiple channels like
Teller, ATM, Mobile Banking, and Internet Banking. Currently the account having
the balance 2000/- and the first user trying to purchase worth of 1500/-
through Internet Banking other user trying to withdraw 1500/- through ATM. Here
whichever the channel first access the account to perform the transaction will acquires
a lock and other channel will wait for the lock. The channel which is waiting
for lock status is not aware of which channel acquires the lock and at the same
time the channel which is already acquired the lock is not aware of that who
are waiting to acquire lock on the particular account. Here lock is applied on
the account and not on channel.<o:p></o:p></span></div>
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com1tag:blogger.com,1999:blog-1899109589837439482.post-37752465460448912622013-11-15T20:22:00.000-08:002014-10-15T03:30:35.698-07:00Prototype Design Pattern in Java<div dir="ltr" style="text-align: left;" trbidi="on">
In general, a prototype is a template of any object before the actual object is constructed. This design pattern is useful when your application needs to create a number of similar instances of a class with small variations. <br />
Also creation of a new object is a time taking process and an expensive too. So this pattern works by cloning of an object rather than creation.<br />
<br />
<b>When to use this pattern?</b><br />
<ul>
<li> If the cost of creating the object is expensive or complicated.<br />
</li>
<li> When trying to keep the number of classes in an application to a minimum.<br />
</li>
<li> When adding or removing objects at runtime<br />
</li>
<li> When the client application needs to be unaware of the object creation, composition and representation.<br />
</li>
<li> Objects are required which are similar to the existing objects.<br />
</li>
</ul>
<b>What does Prototype pattern do?</b> <br />
It allows making new instances by copying the existing instances. The copied cloned object is different from the original object. The state of the original is the same as the cloned one, at the time of cloning. Thereafter each object may undergo state change based on the operations performed on it. We can modify the objects to perform different things as well. <br />
Please ensure that you want to deep clone or shallow clone your prototype because both will have different behaviour on runtime. If deep copy is needed, you can use a good technique given here using in memory serialization. <br />
<b>Shallow Clone:</b> <br />
When copied object contains references of other objects, the contained objects will not be cloned. Shallow clone copies only top level structure of an object. It can be done by using clone() method.<br />
<b>Deep Clone:</b> <br />
The object is copied along with the objects it refers to. Deep clone copies all the levels of the object from top to the bottom recursively. It can be done by using serialization or by overriding writing clone method in such way that to take all copied of contained objects. <br />
<b>Contained Object:</b> Suppose Subject is a class which used by other classes. <br />
<pre class="brush:java" name="code">package com.edu;
public class Subject {
private String subjectName;
public Subject(String subj) { //Constructor
this.subjectName = subj;
}
public String getSubjectName() {
return subjectName;
}
public void setSubjectName(String subjectName) {
this.subjectName = subjectName;
}
}
</pre>
<b>Implementing Shallow Clonning:</b> <br />
<pre class="brush:java" name="code">package com.edu.shallow;
import com.edu.Subject;
public class Student implements Cloneable {
private String studentName;
private Subject subject; //Contained Object
public Student(String studName, String subjName) {
this.studentName = studName;
this.subject = new Subject(subjName);
}
@Override
public Object clone() {
//Shallow Copy
try {
return super.clone();
} catch(CloneNotSupportedException cnsExp) {
return null;
}
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public Subject getSubject() {
return subject;
}
public void setSubject(Subject subjectName) {
this.subject = subjectName;
}
@Override
public String toString() {
return "studentName = " + studentName + ", subject = " + subject.getSubjectName();
}
}
</pre>
<b>Test Shallow Clonning:</b> <br />
<pre class="brush:java" name="code">package com.edu.shallow;
public class ShallowCloneTest {
public static void main(String[] args) {
Student stud = new Student("Mohan", "Discrete Structures");
System.out.println("Original Object: " + stud.toString());
//Clone Object
Student clonedStud = (Student) stud.clone();
System.out.println("Cloned Object: " + clonedStud.toString());
//Modify the Original Object
stud.setStudentName("Rajesh");
stud.getSubject().setSubjectName("Computer Organisation");
System.out.println("Original Object after it is updated: " + stud.toString());
System.out.println("Cloned Object after updating original object: " + clonedStud.toString());
}
}
</pre>
<b>Shallow Clonning Testing Output:</b> <br />
<pre class="brush:java" name="code">Original Object: studentName = Mohan, subject = Discrete Structures
Cloned Object: studentName = Mohan, subject = Discrete Structures
Original Object after it is updated: studentName = Rajesh, subject = Computer Organisation
Cloned Object after updating original object: studentName = Mohan, subject = Computer Organisation
</pre>
<b>Implementing Deep Clonning by overriding clone() method:</b> <br />
<pre class="brush:java" name="code">package com.edu.deep;
import com.edu.Subject;
public class Student implements Cloneable {
private String studentName;
private Subject subject; //Contained Object
public Student(String studName, String subjName) {
this.studentName = studName;
this.subject = new Subject(subjName);
}
@Override
public Object clone() {
Student student = new Student(studentName, subject.getSubjectName());
return student;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public Subject getSubject() {
return subject;
}
public void setSubject(Subject subjectName) {
this.subject = subjectName;
}
@Override
public String toString() {
return "studentName = " + studentName + ", subject = " + subject.getSubjectName();
}
}
</pre>
<b>Test Deep Clonning:</b> <br />
<pre class="brush:java" name="code">package com.edu.deep;
public class DeepCloneTest {
public static void main(String[] args) {
Student stud = new Student("Mohan", "Discrete Structures");
System.out.println("Original Object: " + stud.toString());
//Clone Object
Student clonedStud = (Student) stud.clone();
System.out.println("Cloned Object: " + clonedStud.toString());
//Modify the Original Object
stud.setStudentName("Rajesh");
stud.getSubject().setSubjectName("Computer Organisation");
System.out.println("Original Object after it is updated: " + stud.toString());
System.out.println("Cloned Object after updating original object: " + clonedStud.toString());
}
}
</pre>
<b>Deep Clonning Test Output:</b> <br />
<pre class="brush:java" name="code">Original Object: studentName = Mohan, subject = Discrete Structures
Cloned Object: studentName = Mohan, subject = Discrete Structures
Original Object after it is updated: studentName = Rajesh, subject = Computer Organisation
Cloned Object after updating original object: studentName = Mohan, subject = Discrete Structures
</pre>
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-62162462065623121332013-11-14T10:40:00.000-08:002013-11-14T10:40:34.443-08:00How to call Stored Procedures in Hibernate?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b>DB Objects:<o:p></o:p></b></div>
<div class="MsoListParagraphCxSpFirst" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l1 level1 lfo1; text-align: justify; text-indent: -.25in;">
<!--[if !supportLists]--> 1.<span style="font-size: 7pt; line-height: normal;"> </span><!--[endif]-->Tables</div>
<div class="MsoListParagraphCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l1 level1 lfo1; text-align: justify; text-indent: -.25in;">
<!--[if !supportLists]--> 2.<span style="font-size: 7pt; line-height: normal;"> </span><!--[endif]-->Views</div>
<div class="MsoListParagraphCxSpMiddle" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l1 level1 lfo1; text-align: justify; text-indent: -.25in;">
<!--[if !supportLists]--> 3.<span style="font-size: 7pt; line-height: normal;"> </span><!--[endif]-->Sequences</div>
<div class="MsoListParagraphCxSpLast" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l1 level1 lfo1; text-align: justify; text-indent: -.25in;">
<!--[if !supportLists]--> 4.<span style="font-size: 7pt; line-height: normal;"> </span><!--[endif]-->Stored
Procedures, etc.</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
All Object/Relational mapping frameworks will have
entity relationship between DB Tables/Views with Java POJO Data Transfer
Objects. To communicate with these DB objects is very easy and can be managed
with the method given by framework like save(), update(), delete(),
saveOrUpadate(), etc.</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
In Hibernate, if user wants to communicate with Stored
Procedures from underlying DB, needs to follow the below approach. </div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
Procedures have two kinds of parameters in any
Database.</div>
<div class="MsoListParagraphCxSpFirst" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l2 level1 lfo2; text-align: justify; text-indent: -.25in;">
<!--[if !supportLists]--> 1.<span style="font-size: 7pt; line-height: normal;"> </span><!--[endif]-->IN
Parameters</div>
<div class="MsoListParagraphCxSpLast" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l2 level1 lfo2; text-align: justify; text-indent: -.25in;">
<!--[if !supportLists]--> 2.<span style="font-size: 7pt; line-height: normal;"> </span><!--[endif]-->OUT
Parameters</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 40.5pt; margin-right: 0in; margin-top: 0in; text-align: justify; text-indent: -40.5pt;">
<b>Step #1:</b> Open a
connection from StatelessSession.</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 40.5pt; margin-right: 0in; margin-top: 0in; text-align: justify; text-indent: -40.5pt;">
<b>Step #2:</b> Call
stored procedure by using prepareCall() method of <b>Statement</b> object.</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 40.5pt; margin-right: 0in; margin-top: 0in; text-align: justify; text-indent: -40.5pt;">
<b>Step #3:</b>
Pass/Provide all <b>IN</b> parameters of
stored procedures by using setXXX() of <b>Statement</b>
object.</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 40.5pt; margin-right: 0in; margin-top: 0in; text-align: justify; text-indent: -40.5pt;">
<b>Step #4:</b> Register
the type of OUT parameters by using registerOutParameter() of <b>Statement</b> object.</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 40.5pt; margin-right: 0in; margin-top: 0in; text-align: justify; text-indent: -40.5pt;">
<b>Step #5:</b> Call executeUpdate()
method on Statement Object.</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 40.5pt; margin-right: 0in; margin-top: 0in; text-align: justify; text-indent: -40.5pt;">
<b>Step #6:</b> Get the <b>OUT</b> parameters provided by stored
procedures by using getXXX() method of <b>Statement</b>
object. </div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b>Code Snippet:<o:p></o:p></b></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #B6DDE8; border-collapse: collapse; border: none; mso-background-themecolor: accent5; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184; width: 655px;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 491.4pt;" valign="top" width="655">
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
String
queryString = "{call schema.storedProcExample(?,?,?,?)}";</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
int
sequenceNo = 0;</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
Connection
con = getSessionFactory().openStatelessSession().connection();</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
CallableStatement
stmt = null;</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
try {</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
stmt =
con.prepareCall(queryString);</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
stmt.registerOutParameter(1,
java.sql.Types.INTEGER);</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
stmt.setInt(2, 1);</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
stmt.setString(3, “2”);</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
stmt.setDate(4, new java.sql.Date(System.currentTimeMillis(<u>)</u>));</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
stmt.executeUpdate();</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
sequenceNo = stmt.getInt(1);</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
} catch
(SQLException e) {</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
LOGGER.info("getTransactionSequenceNo
: {}", "Exception");</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
LOGGER.info("getTransactionSequenceNo
Exception: {}", e);</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
} finally
{</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
try {</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
if (stmt != null)</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
stmt.close();</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
} catch (Exception e) {</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
LOGGER.error("exception
while closing statement", e);</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
}</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
try {</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
if (con != null)</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
con.close();</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
} catch (Exception e) {</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
LOGGER.error("exception
while closing connection", e);</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
}</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
}<o:p></o:p></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b>Note:</b> The types
of OUT parameters can be available from java.sql.Types class file. </div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in;">
<b>Characteristics of StatelessSession
in Hibernate:<o:p></o:p></b></div>
<div class="MsoListParagraphCxSpFirst" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l0 level1 lfo3; text-indent: -.25in;">
<span style="font-family: Wingdings; line-height: 150%; text-indent: -0.25in;"> Ø<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;"> </span></span><span style="background-color: white; line-height: 150%; text-indent: -0.25in;">Neither does not implement a first-level cache
nor interact with any second-level cache</span><span style="line-height: 150%; text-indent: -0.25in;">.</span></div>
<div class="MsoListParagraphCxSpFirst" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l0 level1 lfo3; text-indent: -.25in;">
<span style="font-family: Wingdings; line-height: 150%; text-indent: -0.25in;"> Ø<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;"> </span></span><span style="background-color: white; line-height: 150%; text-indent: -0.25in;">Collections are ignored.</span></div>
<div class="MsoListParagraphCxSpFirst" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l0 level1 lfo3; text-indent: -.25in;">
<span style="font-family: Wingdings; line-height: 150%; text-indent: -0.25in;"> Ø<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;"> </span></span><span style="background-color: white; line-height: 150%; text-indent: -0.25in;">Operations performed via a stateless session
bypass Hibernate's event model and interceptors</span><span style="line-height: 150%; text-indent: -0.25in;">.</span></div>
<br />
<br />
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in;">
</div>
<div class="MsoListParagraphCxSpLast" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<o:p></o:p></div>
<br />
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-73882072056801021442013-11-12T13:48:00.001-08:002015-08-15T09:58:49.884-07:00Singleton Design Pattern in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Singleton Class:</b> <br />
The implementation of a Singleton class enforces, there must be a maximum of only one object of its type at any given time. Also Singleton class will make sure that its object won’t be garbage collected during the application running. <br />
<br />
First of all to construct a Singleton object, programmer should aware of in how many ways an object can be created. So that can take precautions to make sure that the class following Singleton Design Pattern. <br />
<br />
<b>1. Possible ways to create an Object:</b><br />
1.1. By using new keyword. This is the most commonly used approach in java. <br />
<pre class="brush:java">SingletonObject object = new SingletonObject();
</pre>
<br />
1.2. By using Class.forName(). It can be possible if the class has public default constructor. <br />
<pre class="brush:java">SingletonObject object = (SingletonObject) Class.forName("com.edu.SingletonObject").newInstance();
</pre>
<br />
1.3. By using the clone() method we can create a copy of an existing object. <br />
<pre class="brush:java">SingletonObject object = new SingletonObject();
SingletonObject anotherObj = object.clone();
</pre>
<br />
1.4. By using the Object deserialization, can able to create an object from its serialized form. <br />
<pre class="brush:java">ObjectInputStream inStream = new ObjectInputStream(inputStream );
SingletonObject object = (SingletonObject) inStream.readObject();
</pre>
<br />
<b>2. Construction of Singleton Object by preventing above possibilities:</b> <br />
2.1. Use a private constructor, hence we cannot create an object of a class outside of it’s by using new keyword. This also prevents creation of an object from Class.forName(). Will get the flowing exception at run time. <br />
<pre class="brush:java">private SingletonObject() {}
</pre>
<br />
2.2. To prevents from cloning, simple write a clone() method in Singleton java file and throw an exception saying that cloning is not supported. <br />
<pre class="brush:java">public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
</pre>
<br />
2.3. To prevent from de-serialization process, implement Serialization interface and provide the body for both methods readObject() and readResolve() in such a way that it should provide the same current object. The total implementation of a Singleton Java class as follows: <br />
<pre class="brush:java">package com.edu;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.lang.reflect.Constructor;
import java.io.Serializable;
public class SingletonObject implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private static SingletonObject singletonObject;
public static int x;
private SingletonObject() { }
public static synchronized SingletonObject getInstance() {
if (singletonObject == null) {
singletonObject = new SingletonObject();
singletonObject.x = x + 10;;
}
return singletonObject;
}
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
ois.defaultReadObject();
synchronized (SingletonObject.class) {
if (singletonObject == null) {
singletonObject = this; // only if everything succeeds
}
}
}
private Object readResolve() throws ObjectStreamException {
if(singletonObject != null);
return singletonObject;
}
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
}
</pre>
<br />
<b>3. Why synchronized keyword used for getInstance() method:</b> <br />
Since the singleton instance is a static class variable in the stored in the PermGen space of the heap. This applies getInstance() instance method as well since it is static too. In the multithreading environment to prevent each thread to create another instance of singleton object and thus creating concurrency issue we will need to use locking mechanism. This can be achieved by synchronized keyword. By using this synchronized keyword we prevent Thread2 or Thread3 to access the singleton instance while Thread1 inside the method getInstance(). <br />
<br />
<b>Client Code:</b> <br />
<pre class="brush:java">package com.edu;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationTargetException;
public class SingletonTest {
public static void main(String[] args) throws SecurityException, NoSuchMethodException,
IllegalArgumentException, InvocationTargetException, CloneNotSupportedException {
try {
//1. TO test for new keyword
/*
SingletonObject obj1 = new SingletonObject();
*/
//2. To test Class.forName()
/*
SingletonObject obj = (SingletonObject)Class.forName("com.edu.SingletonObject").newInstance();
System.out.println(obj.getInstance().x);
*/
//3. To test Reflection
/*
Class<SingletonObject> obj = (Class<SingletonObject>) Class.forName("com.edu.SingletonObject");
Constructor<SingletonObject> constructor = obj.getDeclaredConstructor();
SingletonObject obj1 = constructor.newInstance("SingletonObject");
SingletonObject object = obj1.getInstance();
*/
//4. To test cloning
/*
SingletonObject obj = SingletonObject.getInstance();
obj.clone();
System.out.println(obj.x);
*/
//5. To test object de-serialization
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(SingletonObject.getInstance());
oos.close();
java.io.InputStream is = new java.io.ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(is);
SingletonObject singletonObject = (SingletonObject)ois.readObject();
System.out.println(singletonObject.x);
} catch(Exception e) {
e.printStackTrace();
}
}
}
</pre>
<br />
<b>Test Results:</b> <br />
Enable either one option in the test program and run one by one. <br />
1. Will get compilation error. <br />
Error: The constructor SingletonObject() is not visible. <br />
2. Will get Runtime error. <br />
Error: <br />
<pre class="brush:java">java.lang.IllegalAccessException: Class com.edu.SingletonTest can not access a member of class com.edu.SingletonObject with modifiers "private"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.Class.newInstance0(Class.java:351)
at java.lang.Class.newInstance(Class.java:310)
at com.edu.SingletonTest.main(SingletonTest.java:21)
</pre>
<br />
3. Will get runtime error: <br />
Error: <br />
<pre class="brush:java">java.lang.IllegalAccessException: Class com.edu.SingletonTest can not access a member of class com.edu.SingletonObject with modifiers "private"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Constructor.newInstance(Constructor.java:505)
at com.edu.SingletonTest.main(SingletonTest.java:30)
</pre>
<br />
4. Since we have provided the method implementation for this scenario in such a way that to provide the same copy of an object. It will provide the same. <br />
<br />
<b>When to use Singleton Design Pattern:</b> <br />
Any class which you want to be available to whole application and whole only one instance is viable is candidate of becoming Singleton. One example of this is Runtime class , since on whole java application only one runtime environment can be possible making Runtime Singleton is right decision. Another example is a utility classes like Popup in GUI application, if you want to show popup with message you can have one PopUp class on whole GUI application and anytime just get its instance, and call show() with message. <br />
<br />
<b>Uses of Singleton Design Pattern:</b> <br />
<b>DB Connection:</b> We can create a Database connection once and can provide a global point of reference. <br />
<b>Configuration File:</b> It creates a single instance of the configuration file which can be accessed by multiple calls concurrently as it will provide static config data loaded into in-memory objects. The application only reads from the configuration file at the first time and thereafter from second call onwards the client applications read the data from in-memory objects. <br />
<b>Cache:</b> We can use the cache as a singleton object as it can have a global point of reference and for all future calls to the cache object the client application will use the in-memory object.</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-7056038813605852282013-11-09T01:52:00.001-08:002013-12-27T06:59:57.841-08:00Spring Batch Flat File Reader reads multiple files<div dir="ltr" style="text-align: left;" trbidi="on"> <br />
<b>Problem :</b> <br />
Implement a standalone flight search engine that lists matching flights for a traveller who is looking to fly between 2 locations on a given date. The input locations should be in 3-letter location code format as present in the airlines flight data. <br />
<b>Specifications:</b> You are given 3 CSV files, each containing the available flights data for British Airways, Lufthansa Airlines and Air France respectively. <br />
<b>Each file contains the following fields:</b> <br />
<ol><li>FLIGHT_NUM - Unique flight number, starting with 2-letter airline code.<br />
<li>DEP_LOC - Departure location code of the flight.<br />
<li>ARR_LOC - Arrival location code of the flight.<br />
<li>VALID_TILL - Date (DD-MM-YYYY) till which each flight is available. It means that this flight would fly once every day till this date.<br />
<li>FLIGHT_TIME - Local time (HHmm) at which the flight departs from the departure location.<br />
<li>FLIGHT_DURN - Flight duration (HH.mm) from departure location to the arrival location.<br />
<li>FARE - This is the fare of the flight per person in $ (US Dollars). </ol>
<b>Following are the constraints should apply:</b>
<ul><li>The engine should accept 4 input parameters: Departure Location, Arrival Location, Flight Date, Output Preference. “Output Preference” is a String suggesting whether the flight results should be sorted only by fare, or by both fare and flight duration.<br />
<li>The engine should then search for the flights in all 3 CSV files, and list the aggregate results on standard output, sorted by Fare and Flight Duration, depending on “Output Preference”.<br />
<li>The engine should be written considering that there could be more CSV files in future, and each CSV file might contain more data than present.<br />
<li>If the Departure location or/and Arrival location is not present in any of the CSV files, then engine should return a user friendly error.<br />
<li>If there are no flights available for the user entered input parameters, then engine should return a different user friendly error. </ul>
<b>Input data:</b>
The following PIPE delimited sample data is given to you. You are allowed to extend on this data and create heavier input files.
<b>Flight_Details_1.csv</b>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9;"><tr><td> FLIGHT_NUM|DEP_LOC|ARR_LOC|VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE<br />
AF299|FRA|LHR|20-11-2010|0600|4.10|480<br />
AF118|DUB|MUC|21-12-2010|1410|5.40|580<br />
AF371|AMS|MAD|30-11-2010|1210|3.45|320<br />
AF453|BOS|CDG|20-11-2010|1350|7.30|1000<br />
AF544|BOM|LHR|10-12-2010|1150|8.10|950<br />
AF271|AMS|MAD|27-10-2010|1100|3.30|500<br />
AF249|JFK|LHR|01-12-2010|1550|8.40|1030<br />
</td></tr>
</table>
<b>Flight_Details_2.csv</b>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9;"><tr><td> FLIGHT_NUM|DEP_LOC|ARR_LOC|VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE<br />
AF299|FRA|LHR|20-11-2010|0600|4.10|480<br />
AF118|DUB|MUC|21-12-2010|1410|5.40|580<br />
AF371|AMS|MAD|30-11-2010|1210|3.45|320<br />
AF453|BOS|CDG|20-11-2010|1350|7.30|1000<br />
AF544|BOM|LHR|10-12-2010|1150|8.10|950<br />
AF271|AMS|MAD|27-10-2010|1100|3.30|500<br />
AF249|JFK|LHR|01-12-2010|1550|8.40|1030<br />
</td></tr>
</table>
<b>Flight_Details_3.csv</b>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9;"><tr><td> FLIGHT_NUM|DEP_LOC|ARR_LOC|VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE<br />
BA123|DEL|AMS|12-10-2010|0050|8.00|950<br />
BA412|BOS|CDG|31-12-2010|0210|7.50|800<br />
BA413|BOS|AMS|30-11-2010|1530|7.00|750<br />
BA111|LHR|PEK|30-10-2010|2340|12.50|1200<br />
BA765|LHR|BOM|31-12-2010|1420|8.50|825<br />
BA322|CDG|NRT|15-11-2010|0010|13.00|1150<br />
BA438|DEL|AMS|30-11-2010|1325|10.50|920<br />
</td></tr>
</table>
<b>Problem Solution:</b>
<ol><li>Create a Data TransferObject/ValueObject which can hold the properties of the flight.<br />
<li>Create another Data Transfer Objects which suits for search criteria.<br />
<li>Create a mapper class which splits the each line at specified delimiter and map the tokens to ValueObject.<br />
<li>Create a Writer class and implement the business logic.<br />
<li>Make necessary configurations to run the program.<br />
<li>Create a client program and to provide search criteria. </ol>
<b>FlightDetailsVO.java:</b> A Data Transfer/Value Object which has the flight properties. <pre class="brush:java">package com.flight.dto;
import java.io.Serializable;
import java.util.Date;
public class FlightDetailsVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String flightNum;
private String depLoc;
private String arrLoc;
private Date validTill;
private String flightTime;
private double flightDuration;
private double fare;
public String getFlightNum() {
return flightNum;
}
public void setFlightNum(String flightNum) {
this.flightNum = flightNum;
}
public String getDepLoc() {
return depLoc;
}
public void setDepLoc(String depLoc) {
this.depLoc = depLoc;
}
public String getArrLoc() {
return arrLoc;
}
public void setArrLoc(String arrLoc) {
this.arrLoc = arrLoc;
}
public Date getValidTill() {
return validTill;
}
public void setValidTill(Date validTill) {
this.validTill = validTill;
}
public String getFlightTime() {
return flightTime;
}
public void setFlightTime(String flightTime) {
this.flightTime = flightTime;
}
public double getFlightDuration() {
return flightDuration;
}
public void setFlightDuration(double flightDuration) {
this.flightDuration = flightDuration;
}
public double getFare() {
return fare;
}
public void setFare(double fare) {
this.fare = fare;
}
@Override
public String toString() {
return flightNum + "|"
+ depLoc + "|"
+ arrLoc + "|"
+ validTill + "|"
+ flightTime + "|"
+ flightDuration + "|"
+ fare;
}
}
</pre>
<b>SearchVO.java:</b> It is used to pass the user given search criteria to search engine. <pre class="brush:java">package com.flight.dto;
import java.io.Serializable;
import java.util.Date;
public class SearchVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String depLoc;
private String arrLoc;
private Date flightDate;
private String sortedBy;
public String getDepLoc() {
return depLoc;
}
public void setDepLoc(String depLoc) {
this.depLoc = depLoc;
}
public String getArrLoc() {
return arrLoc;
}
public void setArrLoc(String arrLoc) {
this.arrLoc = arrLoc;
}
public Date getFlightDate() {
return flightDate;
}
public void setFlightDate(Date flightDate) {
this.flightDate = flightDate;
}
public String getSortedBy() {
return sortedBy;
}
public void setSortedBy(String sortedBy) {
this.sortedBy = sortedBy;
}
}
</pre>
<b>FlightSearchFieldSetMapper.java:</b> It’s a field set mapper and it will fetch all the lines from multiple files and will set to a list and will provide the same to writer. <pre class="brush:java">package com.flight.mapper;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.validation.BindException;
import com.flight.dto.FlightDetailsVO;
public class FlightSearchFieldSetMapper implements FieldSetMapper<FlightDetailsVO> {
private static final String PARSE_ERROR = "PARSE_ERROR";
@Override
public FlightDetailsVO mapFieldSet(FieldSet fieldSet) throws BindException {
FlightDetailsVO flightDetailsVO = new FlightDetailsVO();
flightDetailsVO.setFlightNum(fieldSet.readString(0));
flightDetailsVO.setDepLoc(fieldSet.readRawString(1));
flightDetailsVO.setArrLoc(fieldSet.readRawString(2));
String validTill = fieldSet.readRawString(3);
try {
flightDetailsVO.setValidTill(convertStringToDate(validTill));
} catch(ParseException pe) {
flightDetailsVO.setFlightNum(PARSE_ERROR);
}
flightDetailsVO.setFlightTime(fieldSet.readRawString(4));
flightDetailsVO.setFlightDuration(Double.parseDouble(fieldSet.readRawString(5)));
flightDetailsVO.setFare(Double.parseDouble(fieldSet.readRawString(6)));
return flightDetailsVO;
}
public Date convertStringToDate(String strDate) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
return formatter.parse(strDate);
}
public Date converStringToTime(String StrTime) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
return formatter.parse(StrTime);
}
}
</pre>
<b>FlightSearchItemWriter.java:</b> It’s Item Writer, in our program it will act as search engine. <pre class="brush:java">package com.flight.writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemWriter;
import com.flight.dto.FlightDetailsVO;
import com.flight.dto.SearchVO;
public class FlightSearchItemWriter implements ItemWriter<FlightDetailsVO>, ItemStream {
private SearchVO searchVO;
@Override
public void write(List<? extends FlightDetailsVO> flightDetailsVOList) throws Exception {
ArrayList<FlightDetailsVO> flightDetailsList = new ArrayList>FlightDetailsVO<(flightDetailsVOList);
ArrayList<FlightDetailsVO> availFlightsList = new ArrayList>FlightDetailsVO<();
if(getSearchVO() != null) {
for(FlightDetailsVO currVO : flightDetailsList) {
if(currVO.getValidTill().compareTo(searchVO.getFlightDate()) >= 0) {
availFlightsList.add(currVO);
}
}
if(availFlightsList != null && availFlightsList.size() > 0) {
System.out.println("FLIGHT_NUM|DEP_LOC|ARR_LOC|VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE");
System.out.println("------------------------------------------------------------------");
Collections.sort(availFlightsList, new Comparator<FlightDetailsVO>() {
@Override
public int compare(FlightDetailsVO o1, FlightDetailsVO o2) {
int fareComp = Double.compare(o1.getFare(), o2.getFare());
if(searchVO.getSortedBy().equalsIgnoreCase("both")) {
if (fareComp != 0) {
return fareComp;
}
int durComp = Double.compare(o1.getFlightDuration(), o2.getFlightDuration());
return durComp;
}
return fareComp;
}
});
for(FlightDetailsVO availFlightVO : availFlightsList) {
System.out.println(availFlightVO.toString());
}
}
} else {
System.out.println("Search criteria is not provided.....");
}
}
@Override
public void close() throws ItemStreamException {
}
@Override
public void open(ExecutionContext arg0) throws ItemStreamException {
}
@Override
public void update(ExecutionContext arg0) throws ItemStreamException {
}
public SearchVO getSearchVO() {
return searchVO;
}
public void setSearchVO(SearchVO searchVO) {
this.searchVO = searchVO;
}
}
</pre>
<b>flight-seaarch-context.xml:</b> It’s a configuration file, which contain all spring beans definitions. <pre class="brush:xml"><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<batch:job id="flightSearchJob">
<batch:step id="step1">
<batch:tasklet>
<batch:chunk reader="multiResourceReader" writer="flightSearchItemWriter" commit-interval="100" />
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="multiResourceReader" class="org.springframework.batch.item.file.MultiResourceItemReader">
<property name="resources" value="resources/*.txt" />
<property name="delegate" ref="flightSearchItemReader" />
</bean>
<bean id="flightSearchItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="linesToSkip" value="1" />
<!-- <property name="resource" value="classpath:resources/Flight_Details.txt" /> -->
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="delimiter" value="|" />
</bean>
</property>
<property name="fieldSetMapper">
<bean class="com.flight.mapper.FlightSearchFieldSetMapper" />
</property>
</bean>
</property>
</bean>
<bean id="flightSearchItemWriter" class="com.flight.writer.FlightSearchItemWriter">
</bean>
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
</beans>
</pre>
<b>FlightSearchRun.java:</b> Its client program for Flight Search engine. <pre class="brush:java">package com.flight.main;
import java.text.SimpleDateFormat;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.flight.dto.SearchVO;
import com.flight.writer.FlightSearchItemWriter;
public class FlightSearchRun {
public static void main(String[] args) {
String[] springConfig = {"resources/xml/flight-seaarch-context.xml"};
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("flightSearchJob");
try {
SearchVO searchVO = new SearchVO();
searchVO.setDepLoc("DUB");
searchVO.setArrLoc("MUC");
searchVO.setSortedBy("both");
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
searchVO.setFlightDate(formatter.parse("21-12-2013"));
FlightSearchItemWriter writer = (FlightSearchItemWriter) context.getBean("flightSearchItemWriter");
writer.setSearchVO(searchVO);
JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception e) {
e.printStackTrace();
}
}
}
</pre>
</div>Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-4926467978819581082013-10-29T21:10:00.000-07:002013-11-14T10:32:34.967-08:00How to describe a table in DB2.<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
The below query will describe the table.</div>
<div class="MsoNormal">
<br /></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #B6DDE8; border-collapse: collapse; border: none; mso-background-themecolor: accent5; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184; width: 655px;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 491.4pt;" valign="top" width="655"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
select
distinct(name), coltype, length from sysibm.syscolumns where tbname =
'<table_name>' for read only with ur</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
</td>
</tr>
</tbody></table>
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-41913859597463140412013-10-29T12:43:00.000-07:002013-11-14T10:35:55.116-08:00Spring method Replacement<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="text-align: justify;">
<b><span style="font-family: "Verdana","sans-serif";">Need of method
replacement:</span></b><span style="font-family: "Verdana","sans-serif";"> Suppose
some bug is identified during last phase of testing, analysed the same and
found that the root cause is third party jar/API. To rectify the same we need
to look for update on this API. Since our testing is in last phase and there is
no time to analyse the impact of using updated API in our system. We can use
this feature of spring.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b><span style="font-family: "Verdana","sans-serif";">Simple Requirement:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">Now
there is a requirement to wish a customer saying “Dear Customer, Good
Morning/Good Afternoon/Good Evening….”, based on the customer login time.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9; border-collapse: collapse; border: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638">
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">package</span></b><span style="font-family: Consolas;"> com.thirdpartyapi;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">import</span></b><span style="font-family: Consolas;"> java.util.Calendar;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">class</span></b><span style="font-family: Consolas;"> WishCustomer {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">void</span></b><span style="font-family: Consolas;"> sayWishes() {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> Calendar cal = Calendar.<i>getInstance</i>();</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">int</span></b><span style="font-family: Consolas;"> currHour = cal.get(Calendar.</span><i><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">HOUR_OF_DAY</span></i><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">if</span></b><span style="font-family: Consolas;">(currHour < 12) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">out</span></i><span style="font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"Dear Valued Customer, Good Morning....."</span><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> } </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">else</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">if</span></b><span style="font-family: Consolas;">(currHour >= 12 && currHour < 18) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">out</span></i><span style="font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"Dear Valued Customer, Good Afternoon....."</span><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> } </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">else</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">if</span></b><span style="font-family: Consolas;">(currHour >= 18 && currHour < 24) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">out</span></i><span style="font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"Dear Valued Customer, Good Evening....."</span><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Consolas;">}</span><span style="font-family: 'Courier New';"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b><span style="font-family: "Verdana","sans-serif";">Spring configuration:<o:p></o:p></span></b></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9; border-collapse: collapse; border: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638">
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"><bean id=</span><i><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">”wishCustomer”</span></i><span style="font-family: 'Courier New';"> class=</span><i><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"com.thirdpartyapi.WishCustomer"
</span></i><span style="font-family: 'Courier New';">/><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">The
above code given by third party API has clearly satisfied the requirement. Now
the business has enhanced and got the client over the world. <o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b><i><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt;">Problem</span></i></b><b><span style="font-family: "Verdana","sans-serif";">:</span></b><span style="font-family: "Verdana","sans-serif";"> Irrespective of the user time zone,
the above class wishes the customer based on the application server time zone.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<b><i><span style="font-family: "Verdana","sans-serif"; font-size: 11.0pt;">Solution</span></i></b><b><span style="font-family: "Verdana","sans-serif";">:</span></b><span style="font-family: "Verdana","sans-serif";"> Need to override </span><span style="font-family: Consolas;">sayWishes() </span><span style="font-family: "Verdana","sans-serif";">method
of </span><span style="font-family: Consolas;">WishCustomer </span><span style="font-family: "Verdana","sans-serif";">class alone without impacting of
other logic in this API.<o:p></o:p></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9; border-collapse: collapse; border: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638">
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">package</span></b><span style="font-family: Consolas;"> com.saywish;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">import</span></b><span style="font-family: Consolas;"> java.lang.reflect.Method;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">import</span></b><span style="font-family: Consolas;"> java.util.Calendar;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">import</span></b><span style="font-family: Consolas;"> java.util.TimeZone;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">import</span></b><span style="font-family: Consolas;">
org.springframework.beans.factory.support.MethodReplacer;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">class</span></b><span style="font-family: Consolas;"> WishCustomerReplacer </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">implements</span></b><span style="font-family: Consolas;"> MethodReplacer {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 76.5pt; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none; text-indent: -40.5pt;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> Object reimplement(Object arg0, Method arg1, Object[]
arg2) </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">throws</span></b><span style="font-family: Consolas;"> Throwable {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> Calendar cal = Calendar.<i>getInstance</i>();</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> <span style="background: yellow; mso-highlight: yellow;">cal.setTimeZone(TimeZone.<i>getTimeZone</i>(</span></span><span style="background: yellow; color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt; mso-highlight: yellow;">"IST"</span><span style="background-color: yellow; background-position: initial initial; background-repeat: initial initial; font-family: Consolas;">));</span><span style="font-family: Consolas;"> </span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><span style="color: #3f7f5f; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">//IST is hard coded,
can be pass dynamically based on user location</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">int</span></b><span style="font-family: Consolas;"> currHour = cal.get(Calendar.</span><i><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">HOUR_OF_DAY</span></i><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">if</span></b><span style="font-family: Consolas;">(currHour < 12) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">out</span></i><span style="font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"Dear Valued Customer, Good Morning....."</span><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> } </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">else</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">if</span></b><span style="font-family: Consolas;">(currHour >= 12 && currHour < 18) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">out</span></i><span style="font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"Dear Valued Customer, Good Afternoon....."</span><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> } </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">else</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">if</span></b><span style="font-family: Consolas;">(currHour >= 18 && currHour < 24) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> System.</span><i><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">out</span></i><span style="font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"Dear Valued Customer, Good Evening....."</span><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">null</span></b><span style="font-family: Consolas;">;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Consolas;">}</span><span style="font-family: 'Courier New';"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">The
yellow highlighted is the customization, setting the time zone value to the Calendar
instance based on the user country time zone.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<b><span style="font-family: "Verdana","sans-serif";">Spring configuration
for Method Replacer:<o:p></o:p></span></b></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9; border-collapse: collapse; border: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638">
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: teal; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><</span><span style="background: silver; color: #3f7f7f; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt; mso-highlight: silver;">bean</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"> <span style="color: #7f007f;">id</span>=<i><span style="color: #2a00ff;">"wishCustomer"</span></i> <span style="color: #7f007f;">class</span>=<i><span style="color: #2a00ff;">"com.thirdpartyapi.WishCustomer"</span></i> <span style="color: teal;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><span style="background: yellow; color: teal; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt; mso-highlight: yellow;"><</span><span style="background: yellow; color: #3f7f7f; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt; mso-highlight: yellow;">replaced-method</span><span style="background: yellow; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt; mso-highlight: yellow;"> <span style="color: #7f007f;">name</span>=<i><span style="color: #2a00ff;">"sayWishes"</span></i>
<span style="color: #7f007f;">replacer</span>=<i><span style="color: #2a00ff;">"wishCustomerReplacer"</span></i> <span style="color: teal;">/></span></span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: teal; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"></</span><span style="background: silver; color: #3f7f7f; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt; mso-highlight: silver;">bean</span><span style="color: teal; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">></span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: teal; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><</span><span style="color: #3f7f7f; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">bean</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"> <span style="color: #7f007f;">id</span>=<i><span style="color: #2a00ff;">"wishCustomerReplacer"</span></i> <span style="color: #7f007f;">calss</span>=<i><span style="color: #2a00ff;">"com.saywish.WishCustomerReplacer"</span></i>
<span style="color: teal;">/></span></span><span style="font-family: 'Courier New';"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-11841655960100088102013-10-27T12:11:00.000-07:002013-10-27T12:17:44.735-07:00Setter Injection Vs Constructor Injection<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="text-align: justify;">
<b><span style="font-family: "Verdana","sans-serif";">Setter-Injection</span></b><span style="font-family: "Verdana","sans-serif";"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">The
basic-idea is that class have a no argument-constructor which creates the object
with “reasonable-defaults”. The user of the object can then call setters on the
object to override the collaborators of the object in order to wire
the object graph together or to replace the key collaborators with
test-doubles.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b><span style="font-family: "Verdana","sans-serif";">Constructor-Injection</span></b><span style="font-family: "Verdana","sans-serif";"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">The
basic idea with constructor-injection is that the object has no defaults and
instead you have a single constructor where all of
the collaborators and values need to be supplied before you can
instantiate the object.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">Fundamental
difference between setter and constructor injection, as their
name implies is how dependency is injected. Setter injection in
Spring uses setter methods like setDependency() to inject
dependency on any bean managed by Spring's IOC container. On the other
hand constructor injection uses constructor to inject
dependency on any Spring managed bean.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">Constructor
based dependency injection forces to set the property. However the property
cannot be changed later on. Setter based dependency injection allows reconfiguration
later on. We can have both Constructor based dependency injection and Setter
based dependency injection also together.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo2; text-align: justify; text-indent: -.25in;">
<br />
<ul>
<li><span style="font-family: "Verdana","sans-serif"; text-indent: -0.25in;"> </span><span style="font-family: "Verdana","sans-serif"; text-indent: -0.25in;">Setter Injection is more readable
than constructor injection in Spring configuration file. Since setter method
has name e.x. setReporotService() by reading Spring XML configuration
file you know which dependency you are setting. While
in constructor injection, since it uses index to inject dependency,
it’s not as readable as setter injection and you need to refer
either Java documentation or code to find which index corresponds to
which property.</span></li>
<li><span style="font-family: "Verdana","sans-serif"; text-indent: -0.25in;"> <span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><span style="font-family: "Verdana","sans-serif"; text-indent: -0.25in;">Another difference
between setter vs constructor injection in Spring and one
of the drawback of setter injection is that it does not
ensures dependency Injection. You cannot guarantee that certain
dependency is injected or not, which means you may have an object with
incomplete dependency. On other hand constructor Injection does not
allow you to construct object, until your dependencies are ready.</span></li>
<li><span style="font-family: "Verdana","sans-serif"; text-indent: -0.25in;"> </span><span style="font-family: "Verdana","sans-serif"; text-indent: -0.25in;">One more drawback of setter Injection is
Security. By using setter injection, you
can override certain dependency which is not possible which is
not possible with constructor injection because every time you call constructor,
a new object is gets created.</span></li>
</ul>
</div>
<div class="MsoNormal" style="line-height: 150%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">In
Summary both Setter Injection and Constructor Injection has
their own advantage and disadvantage. Good thing about Spring is that it
doesn't restrict to use either Setter Injection
or Constructor Injection and free to use both of them in one Spring configuration file.
Use Setter injection when number of dependency is more or if
readability needed. Use Constructor Injection when Object must be created
with all of its dependencies.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<h3>
<a href="http://www.blogger.com/blogger.g?blogID=1899109589837439482" name="_Toc345111062"><span lang="EN-US" style="font-family: "Verdana","sans-serif";">Constructor
Injection:</span></a><span lang="EN-US" style="font-family: "Verdana","sans-serif";"><o:p></o:p></span></h3>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">ConstructorInjection.java:<o:p></o:p></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9; border-collapse: collapse; border: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">package</span></b><span style="font-family: 'Courier New';">
com.scb.spring;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">class</span></b><span style="font-family: 'Courier New';">
ConstructorInjection </span><b><span style="font-family: 'Courier New';">{</span></b><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">private</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">int</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">bankid</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">private</span></b><span style="font-family: 'Courier New';">
String </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">private</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">double</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> <b>private</b>
SupportingInfo </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo</span><span style="font-family: 'Courier New';">;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; margin-left: 1.25in; margin-right: 0in; margin-top: 0in; mso-layout-grid-align: none; text-autospace: none; text-indent: -1.25in;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';">
ConstructorInjection(</span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">int</span></b><span style="font-family: 'Courier New';">
bankid, String name, </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">double</span></b><span style="font-family: 'Courier New';">
salary, SupportingInfo
</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo</span><span style="font-family: 'Courier New';">) {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">this</span></b><span style="font-family: 'Courier New';">.</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">bankid</span><span style="font-family: 'Courier New';"> =
bankid;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">this</span></b><span style="font-family: 'Courier New';">.</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';"> =
name;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">this</span></b><span style="font-family: 'Courier New';">.</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';"> =
salary;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> this.</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo = </span><span style="font-family: 'Courier New';">supportingInfo;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';">
String getEmpInfo() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #2a00ff; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">"Bank
ID :"</span><span style="font-family: 'Courier New';">+ getBankid() +</span><span style="color: #2a00ff; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">", Name :"</span><span style="font-family: 'Courier New';">+ </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';"> +</span><span style="color: #2a00ff; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">",
Salary :"</span><span style="font-family: 'Courier New';">+</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';"> ;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">int</span></b><span style="font-family: 'Courier New';">
getBankid() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">bankid</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';">
String getName() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">double</span></b><span style="font-family: 'Courier New';">
getSalary() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Verdana","sans-serif";"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Verdana","sans-serif";"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';">
SupportingInfo getSupportingInfo() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b><span style="font-family: 'Courier New';">}</span></b><b><span style="font-family: "Verdana","sans-serif";"><o:p></o:p></span></b></div>
</td>
</tr>
</tbody></table>
<h2 style="mso-list: none; text-indent: 0in;">
<b><span style="color: windowtext; font-family: "Verdana","sans-serif"; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Calibri;"> </span></b></h2>
<div class="MsoNormal">
context.xml</div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9; border-collapse: collapse; border: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"><beans> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"> <bean id="constructorInjection" class="com.scb.spring.ConstructorInjection"><br />
<constructor-arg index="0"type=”int” value="1361606" /><br />
<constructor-arg index="1" type=”java.lang.String”
value="Paramesh" /><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"> <constructor-arg index="2"
type=”double” value="1234" /><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"> <constructor-arg index="3" ref=”supportingInfo”
/><br />
</bean><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"> <bean id=”supportingInfo”
class=”com.scb.spring.SupportingInfo” /><br />
</beans></span><span style="font-family: 'Courier New';"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<h2 style="margin-left: 0in; mso-list: none; text-indent: 0in;">
<b><span style="color: windowtext; font-family: "Verdana","sans-serif"; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: Calibri;"> </span></b></h2>
<h3>
<a href="http://www.blogger.com/blogger.g?blogID=1899109589837439482" name="_Toc345111063"><span style="font-family: "Verdana","sans-serif"; mso-ansi-language: EN-GB;">Setter Injection:</span></a><span style="font-family: "Verdana","sans-serif"; mso-ansi-language: EN-GB;"><o:p></o:p></span></h3>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">ConstructorInjection.java:<o:p></o:p></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9; border-collapse: collapse; border: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">package</span></b><span style="font-family: 'Courier New';">
com.scb.spring;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">class</span></b><span style="font-family: 'Courier New';">
ConstructorInjection </span><b><span style="font-family: 'Courier New';">{</span></b><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">private</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">int</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">bankid</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">private</span></b><span style="font-family: 'Courier New';">
String </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">private</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">double</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"> <b>private</b>
SupportingInfo supportingInfo;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';">
String getEmpInfo() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #2a00ff; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">"Bank
ID :"</span><span style="font-family: 'Courier New';">+ getBankid() +</span><span style="color: #2a00ff; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">", Name :"</span><span style="font-family: 'Courier New';">+ </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';"> +</span><span style="color: #2a00ff; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">",
Salary :"</span><span style="font-family: 'Courier New';">+</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';"> ;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">void</span></b><span style="font-family: 'Courier New';">
setBankid(</span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">int</span></b><span style="font-family: 'Courier New';"> bankid) {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">this</span></b><span style="font-family: 'Courier New';">.</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">bankid</span><span style="font-family: 'Courier New';"> =
bankid;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">int</span></b><span style="font-family: 'Courier New';">
getBankid() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">bankid</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">void</span></b><span style="font-family: 'Courier New';">
setName(String name) {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">this</span></b><span style="font-family: 'Courier New';">.</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';"> =
name;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';">
String getName() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">void</span></b><span style="font-family: 'Courier New';">
setSalary(</span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">double</span></b><span style="font-family: 'Courier New';"> salary) {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">this</span></b><span style="font-family: 'Courier New';">.</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';"> =
salary;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">double</span></b><span style="font-family: 'Courier New';">
getSalary() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: 'Courier New';">
SupportingInfo getSupportingInfo() {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: 'Courier New';"> </span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">
public</span></b><span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">void</span></b><span style="font-family: 'Courier New';">
setSupportingInfo(SupportingInfo supportingInfo) {</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> </span><b><span style="color: #7f0055; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">this</span></b><span style="font-family: 'Courier New';">.</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo</span><span style="font-family: 'Courier New';"> =
supportingInfo;</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: 'Courier New';"> }</span><span style="font-family: "Courier New"; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: 'Courier New';">}</span><o:p></o:p></b></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
context.xml</div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #D9D9D9; border-collapse: collapse; border: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"><bean id="
constructorInjection" class="com.scb.spring.ConstructorInjection"><br />
<property name="</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">bankid</span><span style="font-family: 'Courier New';">" value="</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">1361606</span><span style="font-family: 'Courier New';">" /><br />
<property name="</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">name</span><span style="font-family: 'Courier New';">" value="</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">Paramesh</span><span style="font-family: 'Courier New';">" /><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"> <property name="</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">salary</span><span style="font-family: 'Courier New';">" value="</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">1234</span><span style="font-family: 'Courier New';">" /><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"> <property name="</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo</span><span style="font-family: 'Courier New';">" ref="</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo</span><span style="font-family: 'Courier New';">" /><br />
</bean><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: 'Courier New';"> <bean id=”</span><span style="color: #0000c0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">supportingInfo</span><span style="font-family: 'Courier New';">”
class=”com.scb.spring.SupportingInfo” /><br />
</beans><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
<h3>
<a href="http://www.blogger.com/blogger.g?blogID=1899109589837439482" name="_Toc345111064"><span style="font-family: "Verdana","sans-serif"; mso-ansi-language: EN-GB;">Injecting Collection Objects</span></a><span style="font-family: "Verdana","sans-serif"; mso-ansi-language: EN-GB;"><o:p></o:p></span></h3>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Verdana","sans-serif";">TO
inject Java Collection types List, Set, Map, and Properties etc, Spring offers
four types of collection configuration elements which are as follows:<o:p></o:p></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: #F7F7F7; border-collapse: collapse; border: none; margin-left: -3.35pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 0in 0in 0in 0in; mso-yfti-tbllook: 1184; width: 634px;">
<tbody>
<tr>
<td style="background: #EEEEEE; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; padding: 0in 0in 0in 0in; width: 75.75pt;" valign="top" width="101"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: Verdana, sans-serif; font-size: 9pt;">Data Type<o:p></o:p></span></b></div>
</td>
<td style="background: #EEEEEE; border-left: none; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt; width: 75.75pt;" width="101"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: Verdana, sans-serif; font-size: 9pt;">Element<o:p></o:p></span></b></div>
</td>
<td style="background: #EEEEEE; border-left: none; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="font-family: Verdana, sans-serif; font-size: 9pt;">Description<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 0in 0in 0in 0in;" valign="top"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">java.util.List/<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">array<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;"><list><o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">Helps to inject a
list of values, allowing duplicates.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 0in 0in 0in 0in;" valign="top"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">java.util.Set<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;"><set><o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">Helps to inject a
set of values, without duplicates.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 0in 0in 0in 0in;" valign="top"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">java.util.Map<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;"><map><o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">Helps to inject a
collection of name-value pairs where name and value can be of any type.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 0in 0in 0in 0in;" valign="top"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">java.util.Properties<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;"><props><o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">Helps to inject a
collection of name-value pairs where the name and value are both Strings.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 0in 0in 0in 0in;" valign="top"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">Another Bean /<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">Any java class<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;"><ref><o:p></o:p></span></div>
</td>
<td style="border-bottom: solid #D6D6D6 1.0pt; border-left: none; border-right: solid #D6D6D6 1.0pt; border-top: none; mso-border-alt: solid #D6D6D6 .75pt; mso-border-left-alt: solid #D6D6D6 .75pt; mso-border-top-alt: solid #D6D6D6 .75pt; padding: 3.75pt 3.75pt 3.75pt 3.75pt;"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif; font-size: 9pt;">Helps to inject
another bean.<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-84173405297400234502013-10-27T10:36:00.001-07:002013-10-27T11:27:31.517-07:00How to pass delimiter dynamically to spring DelimitedLineTokenizer<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">In spring
batch, if the user wants to decide a Delimiter at run time based on the certain
criteria. Built-in spring batch Tokenizer classes won’t support this feature.
If we use our own customized class instead of using spring provided Tokenizer
class, spring batch throws an error.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">Actual Configuration:</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"><o:p></o:p></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #B6DDE8; border-collapse: collapse; border: none; mso-background-themecolor: accent5; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184; width: 655px;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 491.4pt;" valign="top" width="655"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<bean
id="defaultTokenizer"
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<property
name="delimiter" value="," /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</bean></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<bean
id="fieldSetMapper"
class="com.mapper.CustomDataUploadFieldSetMapper" /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<bean
id="defaultLineMapper"
class="org.springframework.batch.item.file.mapping.DefaultLineMapper"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<property
name="lineTokenizer"
ref="defaultTokenizer"></property></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<property
name="fieldSetMapper"
ref="fieldSetMapper"></property></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</bean></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<bean
id="customDataItemReader"
class="com.reader.CustomDataLoadReader"
scope="prototype"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<property
name="lineMapper"
ref="defaultLineMapper"></property></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</bean></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">Here, if
we provide overridden Tokenizer instead of DelimitedLineTokenizer,
spring container will throw an error while server starts up.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">We can
overcome this limitation by using anonymous inner bean configuration as
follows.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #B6DDE8; border-collapse: collapse; border: none; mso-background-themecolor: accent5; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 465.0pt;" valign="top" width="620"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<bean
id="customDataItemReader"
class="com.reader.customerDataItemReader"
scope="prototype"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<property name="lineMapper"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<bean
class="com.mapper.CustomLineMapper"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<property
name="lineTokenizer"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<property
name="delimiter" value="," /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</bean></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</property></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<property
name="fieldSetMapper"></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<bean
class="com.mapper.SegmentFieldSetMapper" /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</property></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</bean></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</property></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
</bean></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">Write a CustomLineMapper by extending DefaultLineMapper and
override <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">mapLine(String
line, int lineNumber) throws Exception</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"> method according
to requirements.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">Example:</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"> Now
we need use pipe(|) symbol as delimiter if existed in the line, else need
to use comma(,) as default delimiter.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<br /></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="background: #B6DDE8; border-collapse: collapse; border: none; mso-background-themecolor: accent5; mso-background-themetint: 102; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 465.0pt;" valign="top" width="620"><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">class</span></b><span style="font-family: Consolas;"> <u>CustomLineMapper</u><T> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">extends</span></b><span style="font-family: Consolas;"> <u>DefaultLineMapper</u><T>
{</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">private</span></b><span style="font-family: Consolas;"> <u>LineTokenizer</u> </span><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">lineTokenizer</span><span style="font-family: Consolas;">;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">private</span></b><span style="font-family: Consolas;"> <u>FieldSetMapper</u><<u>CustomerInformationVO</u>>
</span><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">fieldSetMapper</span><span style="font-family: Consolas;">;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> <<u>T</u>> <u>mapLine(String line, </u></span><b><u><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">int</span></u></b><u><span style="font-family: Consolas;">
lineNumber) </span></u><b><u><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">throws</span></u></b><u><span style="font-family: Consolas;"> Exception</span></u><span style="font-family: Consolas;"> {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">try</span></b><span style="font-family: Consolas;"> {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> <u>setLineTokenizer</u>(</span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">new</span></b><span style="font-family: Consolas;"> <u>DelimitedLineTokenizer</u>(<u>StringUtils</u>.contains(</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> line, </span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">'|'</span><span style="font-family: Consolas;">) ? </span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">'|'</span><span style="font-family: Consolas;"> : </span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">','</span><span style="font-family: Consolas;">));</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: Consolas;"> </span><b><u><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">this</span></u></b><u><span style="font-family: Consolas;">.fieldSetMapper</span></u><span style="font-family: Consolas;">.mapFieldSet(</span><b><u><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">this</span></u></b><u><span style="font-family: Consolas;">.lineTokenizer</span></u><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;">
.tokenize(line));</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> } </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">catch</span></b><span style="font-family: Consolas;"> (Exception ex) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">throw</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">new</span></b><span style="font-family: Consolas;"> <u>FlatFileParseException</u>(</span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"Parsing error at line: "</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> +
lineNumber + </span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">", input=["</span><span style="font-family: Consolas;"> + line + </span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"]"</span><span style="font-family: Consolas;">, ex, line,</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;">
lineNumber);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> <u>LineTokenizer</u> getLineTokenizer() {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">return</span></b><span style="font-family: Consolas;"> </span><u><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">lineTokenizer</span></u><span style="font-family: Consolas;">;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">void</span></b><span style="font-family: Consolas;"> setLineTokenizer(<u>LineTokenizer</u> lineTokenizer) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><u><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">this</span></u></b><u><span style="font-family: Consolas;">.</span></u><u><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">lineTokenizer</span></u><span style="font-family: Consolas;"> = lineTokenizer;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">void</span></b><span style="font-family: Consolas;"> afterPropertiesSet() {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> <u>Assert</u>.notNull(</span><b><u><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">this</span></u></b><u><span style="font-family: Consolas;">.</span></u><u><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">lineTokenizer</span></u><span style="font-family: Consolas;">, </span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"The
LineTokenizer must be set"</span><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> <u>Assert</u>.notNull(</span><b><u><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">this</span></u></b><u><span style="font-family: Consolas;">.</span></u><u><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">fieldSetMapper</span></u><span style="font-family: Consolas;">, </span><span style="color: #2a00ff; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">"The
FieldSetMapper must be set"</span><span style="font-family: Consolas;">);</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> FieldSetMapper<CustomerInformationVO<span style="background: silver; mso-highlight: silver;">></span>
getFieldSetMapper() {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> return </span><u><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">fieldSetMapper</span></u><span style="font-family: Consolas;">;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">public</span></b><span style="font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">void</span></b><span style="font-family: Consolas;"> setFieldSetMapper(</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> <u>FieldSetMapper</u><<u>CustomerInformationVO</u>>
fieldSetMapper) {</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> </span><b><u><span style="color: #7f0055; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">this</span></u></b><u><span style="font-family: Consolas;">.</span></u><u><span style="color: #0000c0; font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;">fieldSetMapper</span></u><span style="font-family: Consolas;"> = fieldSetMapper;</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"> }</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;">}</span><span style="font-family: Consolas; mso-bidi-font-family: Consolas; mso-bidi-font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
</td>
</tr>
</tbody></table>
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0tag:blogger.com,1999:blog-1899109589837439482.post-19874224038758709152013-10-27T10:09:00.002-07:002014-10-20T11:15:53.776-07:00Common problems facing while csv file writing in java<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in; text-align: justify;">
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">A few common problems we are facing while writing csv file in java.
First of all csv file is a comma separated plain text file and can be
opened with excel viewer. If a single word contains a comma, it can be
considered as two words and will occupy two cells. Where as it should occupy
only once cell.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">Problem
#1:</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"> </span><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">When a value contains comma symbol, but still needs to be
fitted into a single cell.<o:p></o:p><o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">Solution:</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;"> Enclose
the string in double quotes.<o:p></o:p><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 14.25pt;">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;"><br /></span></b>
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">Code:</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;"> </span><br />
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">String string_variable = "Its heavy, but looks good";</span><br />
<span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">new StringBuffer(</span><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">"\"").append(string_variable).append("\"").toString();<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 58.5pt; text-align: justify; text-indent: -58.5pt;">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;">Problem #2:</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB;"> </span><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">When
a value contains numeric values starting with zeros, most of the programmers
will suggest append single quote(') in front of the numeric number. But cell
looks different when we add quote symbol.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 58.5pt; text-align: justify; text-indent: -58.5pt;">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">Solution:</span></b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;"> </span><br />
<span style="color: #333333; line-height: 19px; text-align: left; text-indent: 0px;">String </span><span style="color: #333333; text-indent: -58.5pt;">string_variable = "0009098765";</span><br />
<span style="color: #333333; line-height: 19px; text-align: left; text-indent: 0px;">new StringBuffer(</span><span style="color: #333333; text-indent: -58.5pt;">"\t").append(string_variable).toString();</span><br />
<span style="color: #333333; text-indent: -58.5pt;"><br /></span>
<span style="color: #333333; text-indent: -58.5pt;"><b>Note:</b> When we are not aware coming value having either leading zero or commas, we can combine both solutions.</span><br />
<span style="color: #333333; text-indent: -58.5pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 14.25pt;">
<b><span style="color: #333333; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt;">Code:</span></b><br />
<span style="color: #333333;">new StringBuffer(</span><span style="color: #333333;">"\"").append("\t").append(</span><span style="color: #333333; line-height: normal; text-align: justify; text-indent: -78px;">string_variable)</span><span style="color: #333333; line-height: 14.25pt;">.append("\"").toString();</span></div>
</div>
Paramesh Korrakutihttp://www.blogger.com/profile/00565098713095946935noreply@blogger.com0