<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:gd="http://schemas.google.com/g/2005" xmlns:georss="http://www.georss.org/georss" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0"><id>tag:blogger.com,1999:blog-14074542</id><updated>2024-09-07T02:26:44.461+05:30</updated><category term="problem solving"/><category term="algorithms"/><category term="interview question"/><category term="microsoft"/><category term="Java"/><category term="array"/><category term="mathematics"/><category term="puzzle"/><category term="riddle"/><category term="amazon"/><category term="cormen"/><category term="linux"/><category term="sort"/><category term="CLRS"/><category term="TDD"/><category term="madhur"/><category term="mock"/><category term="mockito"/><category term="probability"/><category term="recurrsion"/><category term="search"/><category term="tanwani"/><category term="technology"/><category term="unit test"/><category term="C++"/><category term="OCW"/><category term="OOTB"/><category term="Persistent"/><category term="antivirus"/><category term="arithmetic series"/><category term="backtracking"/><category term="bash"/><category term="basics"/><category term="binary trees"/><category term="brindavan garden"/><category term="bulb"/><category term="callback"/><category term="clam"/><category term="clamav"/><category term="clock"/><category term="data structures"/><category term="duplicate"/><category term="easymock"/><category term="education"/><category term="excel"/><category term="freshclam"/><category term="hanoi"/><category term="hashing"/><category term="httpclient"/><category term="humor"/><category term="induction"/><category term="irrational"/><category term="jmockit"/><category term="learning"/><category term="level_easy"/><category term="logger"/><category term="macro"/><category term="matrix"/><category term="mysore"/><category term="networking"/><category term="odd man out"/><category term="oocalc"/><category term="pattern"/><category term="problem"/><category term="proxy"/><category term="proxy selector"/><category term="quote"/><category term="randomized"/><category term="repeating"/><category term="resolution"/><category term="reverse"/><category term="road trip"/><category term="script"/><category term="shell"/><category term="shell script"/><category term="socks"/><category term="solaris"/><category term="solved"/><category term="stock"/><category term="strategy"/><category term="subversion"/><category term="summation"/><category term="svn"/><category term="switch"/><category term="theorem"/><category term="timer"/><category term="todo"/><category term="travel"/><category term="trees"/><category term="tutorial"/><category term="unimodal"/><category term="walk the bridge"/><category term="warmup"/><category term="water jugs"/><category term="windows"/><category term="xkcd joke"/><title type="text">Feed for Gebo - a blog by Madhur Tanwani</title><subtitle type="html">This is the FeedBurner RSS feed for a blog by Madhur Kumar Tanwani - Gebo. This blog is an attempt to share the knowledge &amp; experience with the community. Focus on Algorithms, Problem Solving, Java &amp; Technology</subtitle><link href="http://madhurtanwani.blogspot.com/feeds/posts/default" rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default?redirect=false" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/" rel="alternate" type="text/html"/><link href="http://pubsubhubbub.appspot.com/" rel="hub"/><link href="http://www.blogger.com/feeds/14074542/posts/default?start-index=26&amp;max-results=25&amp;redirect=false" rel="next" type="application/atom+xml"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><generator uri="http://www.blogger.com" version="7.00">Blogger</generator><openSearch:totalResults>51</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-14074542.post-4974415196070556275</id><published>2012-12-07T23:02:00.000+05:30</published><updated>2012-12-07T23:03:35.315+05:30</updated><title type="text"/><content type="html">&lt;div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"&gt;&lt;div&gt;&lt;a name="yqqtyycwtt" title="uuwunhc" href="http://e-banki.info/wp-content/plugins/akismet/howdoit.php"&gt;http://e-banki.info/wp-content/plugins/akismet/howdoit.php&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/4974415196070556275/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/4974415196070556275" rel="replies" title="0 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/4974415196070556275" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/4974415196070556275" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2012/12/httpe-banki.html" rel="alternate" title="" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-3270815046456123827</id><published>2011-03-30T13:59:00.001+05:30</published><updated>2011-03-30T14:08:34.491+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="amazon"/><category scheme="http://www.blogger.com/atom/ns#" term="interview question"/><category scheme="http://www.blogger.com/atom/ns#" term="mathematics"/><title type="text">Twin Primes</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;A Math oriented question asked at a recent Amazon interview.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Q : &lt;/strong&gt;Given any twin prime pair, prove that the number between the twin primes is always divisible by 6.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://en.wikipedia.org/wiki/Twin_prime"&gt;&lt;strong&gt;Twin Prime&lt;/strong&gt; (from Wiipedia) &lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;A twin prime is a prime number that differs from another prime number by two. Except for the pair (2, 3), this is the smallest possible difference between two primes. Some examples of twin prime pairs are (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), ... (821, 823), etc. Sometimes the term twin prime is used for a pair of twin primes; an alternative name for this is prime twin.&lt;/blockquote&gt;&lt;/div&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/3270815046456123827/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/3270815046456123827" rel="replies" title="4 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/3270815046456123827" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/3270815046456123827" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2011/03/twin-primes.html" rel="alternate" title="Twin Primes" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-2438022338682848640</id><published>2011-03-30T13:53:00.003+05:30</published><updated>2011-03-30T14:09:22.179+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="amazon"/><category scheme="http://www.blogger.com/atom/ns#" term="interview question"/><title type="text">Panlindrome Dates</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Asked at a recent Amazon interview : 2001-01-02 is a palindrome date.&lt;br /&gt;
Find&amp;nbsp;the previous closest palindore date?&lt;/div&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/2438022338682848640/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/2438022338682848640" rel="replies" title="1 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/2438022338682848640" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/2438022338682848640" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2011/03/panlindrome-dates.html" rel="alternate" title="Panlindrome Dates" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-5497972742234320509</id><published>2010-12-12T17:50:00.000+05:30</published><updated>2010-12-12T17:50:56.833+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="array"/><category scheme="http://www.blogger.com/atom/ns#" term="interview question"/><category scheme="http://www.blogger.com/atom/ns#" term="problem solving"/><category scheme="http://www.blogger.com/atom/ns#" term="reverse"/><title type="text">Reverse words in a sentence</title><content type="html">Given an array of characters, reverse the words in the sentence.&lt;br /&gt;
For example, if the sentence is "Reverse these words", then the output should be "words these reverse". &lt;br /&gt;
&lt;br /&gt;
Source : &lt;a href="http://kundansingh.com/interview/#q13"&gt;this interview q&lt;/a&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/5497972742234320509/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/5497972742234320509" rel="replies" title="3 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/5497972742234320509" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/5497972742234320509" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/12/reverse-words-in-sentence.html" rel="alternate" title="Reverse words in a sentence" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-7090010737446647353</id><published>2010-12-11T23:38:00.000+05:30</published><updated>2010-12-11T23:38:52.130+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="array"/><category scheme="http://www.blogger.com/atom/ns#" term="CLRS"/><category scheme="http://www.blogger.com/atom/ns#" term="cormen"/><category scheme="http://www.blogger.com/atom/ns#" term="duplicate"/><category scheme="http://www.blogger.com/atom/ns#" term="interview question"/><title type="text">Find duplicates in an array</title><content type="html">Given an array of size 'n', containing elements from 1 to 'n', find out if there are any duplicates in the array. Solve this, if&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;a single duplicate number exists&lt;/li&gt;
&lt;li&gt;multiple duplicate numbers exist&lt;/li&gt;
&lt;/ul&gt;&amp;nbsp;Source : CLRS &amp;amp; &lt;a href="http://inder-gnu.blogspot.com/2010/11/find-duplicates-in-array-of-elements.html"&gt;this blog question&lt;/a&gt; (that I did not get)</content><link href="http://madhurtanwani.blogspot.com/feeds/7090010737446647353/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/7090010737446647353" rel="replies" title="3 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/7090010737446647353" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/7090010737446647353" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/12/find-duplicates-in-array.html" rel="alternate" title="Find duplicates in an array" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-6086168847758166298</id><published>2010-12-11T23:30:00.001+05:30</published><updated>2010-12-11T23:39:40.610+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="array"/><category scheme="http://www.blogger.com/atom/ns#" term="CLRS"/><category scheme="http://www.blogger.com/atom/ns#" term="cormen"/><category scheme="http://www.blogger.com/atom/ns#" term="interview question"/><title type="text">Find subarray with maximum sum</title><content type="html">Given an array of size n, containing positive and negative integers, find the longest sub-array such that the sum of the elements in the sub-array is the maximum.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
Given array :&lt;br /&gt;
10, 8, -5, 1, -27, 5, 7, -5, 11&lt;br /&gt;
the sub array should be : 10, 8&lt;br /&gt;
&lt;br /&gt;
Source : CLRS &amp;amp; &lt;a href="http://kundansingh.com/interview/#q12"&gt;this sample interview question&lt;/a&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/6086168847758166298/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/6086168847758166298" rel="replies" title="1 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/6086168847758166298" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/6086168847758166298" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/12/find-subarray-with-maximum-sum.html" rel="alternate" title="Find subarray with maximum sum" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-1916774108040826149</id><published>2010-09-03T23:18:00.001+05:30</published><updated>2010-10-28T15:11:03.232+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="callback"/><category scheme="http://www.blogger.com/atom/ns#" term="interview question"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="level_easy"/><category scheme="http://www.blogger.com/atom/ns#" term="pattern"/><title type="text">Callbacks in Java</title><content type="html">Recently I interviewed a couple of folks. One of the guys was a C++ guy and I thought of delving into the tricky and interesting land of &lt;a href="http://en.wikipedia.org/wiki/Function_pointer"&gt;function pointers&lt;/a&gt; with him. This is when the question in the title occurred to me : How would you implement callbacks in Java?&lt;br /&gt;
&lt;br /&gt;
Its nothing new, its nothing great, but I was just curious how the candidate would apply his language feature proficiency to implement a real world problem. I asked that question to that candidate and two more, after which I thought I should write this post. None of the three candidates knew how to do it. Worse one of them was completely bewildered and was like "what are you trying to say???". Damn it!!! :(.&lt;br /&gt;
&lt;br /&gt;
Well here is my take on implementing Callbacks in Java. Hope you find it useful.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What are callbacks?&lt;/b&gt;&lt;br /&gt;
A &lt;a href="http://en.wikipedia.org/wiki/Callback_%28computer_science%29"&gt;callback&lt;/a&gt; is a paradigm by which a general purpose library can delegate (generally domain specific) parts of its execution to an external, more appropriate owner. This fits well with the "&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;separation of concerns&lt;/a&gt;"process - your code will do just the work it understands.&lt;br /&gt;
&lt;br /&gt;
A classic example is the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;sort&lt;/span&gt; functionality - references are available in &lt;a href="http://en.wikipedia.org/wiki/Sort_%28C%2B%2B%29"&gt;C++&lt;/a&gt;, &lt;a href="http://download-llnw.oracle.com/javase/6/docs/api/java/util/Collections.html#sort%28java.util.List,%20java.util.Comparator%29"&gt;Java&lt;/a&gt; and other languages. The &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;sort&lt;/span&gt; method, typically, would accept the &lt;i&gt;&lt;span style="font-family: inherit;"&gt;list of objects&lt;/span&gt;&lt;/i&gt; to be sorted, along with an optional &lt;i&gt;&lt;span style="font-family: inherit;"&gt;callback&lt;/span&gt;&lt;/i&gt; for object comparison. The &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;sort&lt;/span&gt; method (the general purpose library) knows how to sort lists very well, but does not need to know the algorithm to decide the ordering of two given data objects (comparison of data objects). Since comparison of the data object (your domain specific decision) is an important part of the sorting algorithm, the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;sort&lt;/span&gt; method will allow you to specify a function that it can call when it needs to compare two of your data objects. This function is the callback.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Why the fuss?&lt;/b&gt;&lt;br /&gt;
Callbacks are great! They are means available for developers to write layers of generic code that is reusable across domains with a minimal overhead. We most certainly use callback in our day-to-day code, probably without realizing them (hence those 3 candidates). Callbacks are the backbone for various implementations - lifecycle listeners (in containers), Spring (HibernateTemplate, JdbcTemplate and more), Collections.sort(), .... the list goes on.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Nice. How are they implemented in Java?&lt;/b&gt;&lt;br /&gt;
Lets just think about it - what is the callback specifying? Its allowing the caller to specify the method to be called from the method to-be-called. This could mean, at least, two things - either the method to-be-called is given the exact callback method (within an instance / global context) OR the method to-be-called declares that it would call a specific method name with specific parameters (on the callback being passed) and its the responsibility of the caller to ensure that such a method exists in the callback object's context.&lt;br /&gt;
&lt;br /&gt;
While the first approach is possible in languages like C++, the second approach fits the Java world. Another read of the second approach tells us that what we taking about is a contract - a binding that the caller must confirm to, which the method to-be-called can rely on.&lt;br /&gt;
&lt;br /&gt;
In Java, how are contracts specified?? Well - by using &lt;a href="http://en.wikipedia.org/wiki/Interface_%28Java%29"&gt;interfaces&lt;/a&gt;. If the method to-be-called accepts an instance of an interface, as its callback parameter, then&amp;nbsp; it will enforce the caller to implement an object that implements the methods from that interface. The method to-be-called should, however, declare beforehand which methods from the interface it would calls from within its code at what time (the contact of the methods).&lt;br /&gt;
&lt;br /&gt;
Hope this brief article was helpful. For further detailed reading (specially the Command pattern usage) please refer to these links :&lt;br /&gt;
&lt;a href="http://www.javaworld.com/javaworld/javatips/jw-javatip10.html"&gt;http://www.javaworld.com/javaworld/javatips/jw-javatip10.html&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.javaworld.com/javaworld/javatips/jw-javatip68.html"&gt;http://www.javaworld.com/javaworld/javatips/jw-javatip68.html&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://stackoverflow.com/questions/1476170/how-to-implement-callbacks-in-java"&gt;http://stackoverflow.com/questions/1476170/how-to-implement-callbacks-in-java&lt;/a&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/1916774108040826149/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/1916774108040826149" rel="replies" title="3 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/1916774108040826149" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/1916774108040826149" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/09/callbacks-in-java.html" rel="alternate" title="Callbacks in Java" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-2690723850345127268</id><published>2010-08-30T19:11:00.004+05:30</published><updated>2010-08-30T22:55:01.513+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="excel"/><category scheme="http://www.blogger.com/atom/ns#" term="macro"/><category scheme="http://www.blogger.com/atom/ns#" term="oocalc"/><category scheme="http://www.blogger.com/atom/ns#" term="quote"/><category scheme="http://www.blogger.com/atom/ns#" term="stock"/><title type="text">BASIC Macro To Get Stock Quotes for OpenOffice Calc</title><content type="html">I've been trying to figure out to keep track of various tips, suggestions and recommendations that various financial experts throw all the time on all the major stock market information websites. While I definitely like &lt;a href="http://moneycontrol.com/"&gt;moneycontrol.com&lt;/a&gt; (for India markets), I really hate the fact that it does not allow me to track my watch list conveniently.  For example, I add stock to a watch list, I enter some notes, but then those notes are not visible to me while viewing the watch list :(&lt;br /&gt;
&lt;br /&gt;
Also, since what I am maintaining is a watch list, I would like to record recommended target / buy prices ad trigger alerts on those. So I came up with this small spreadsheet template that will record all this information and give a snapshot of the watch list.&lt;br /&gt;
&lt;br /&gt;
The biggest blocker in this task was how to populate the "current" stock price. So, I wrote this simple BASIC Macro that,&amp;nbsp; given a stock symbol, will fetch the current price of the stock. Salient points about the script :&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;The script was written for OpenOffice Calc, but should work in Excel as well.&lt;/li&gt;
&lt;li&gt;The script pulls its data from &lt;a href="http://in.finance.yahoo.com/"&gt;in.finance.yahoo.com&lt;/a&gt;, but this can be replaced with the country's specific address and everything should just work fine. For example, for US market replacing &lt;a href="http://in.finance.yahoo.com/"&gt;http://in.finance.yahoo.com&lt;/a&gt; with &lt;a href="http://download.finance.yahoo.com/"&gt;http://download.finance.yahoo.com&lt;/a&gt; will work as-is.&lt;/li&gt;
&lt;li&gt;You can also replace the source &lt;a href="http://in.finance.yahoo.com/"&gt;http://in.finance.yahoo.com&lt;/a&gt;, with something completely different (for example &lt;a href="http://www.nseindia.com/marketinfo/equities/ajaxGetQuote.jsp"&gt;http://www.nseindia.com/marketinfo/equities/ajaxGetQuote.jsp&lt;/a&gt;), but then the parsing of the returned data will have to change.&lt;/li&gt;
&lt;li&gt;To start using the script for your spreadsheet, do ensure that the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;sheetNo&lt;/span&gt;,&amp;nbsp; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;c&lt;/span&gt;,&amp;nbsp; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;r&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;destCol&lt;/span&gt; variables at the start of the script point to correct locations in your file.&lt;/li&gt;
&lt;/ol&gt;Here is the Macro :&lt;br /&gt;
&lt;br /&gt;
&lt;div style="height: 400px; overflow: auto;"&gt;&lt;pre class="brush: vb"&gt;Sub FillStockQuotes
 Dim c as Integer, r as Integer, destCol as Integer, sheetNo as Integer
 Dim Sheet, Cell, DestCell
 Dim symbol as String

 REM Which sheet contais the above rows and columns. This is a zero based index (First sheet is sheet no 0)
 sheetNo=0
 REM Which column has the styock symbol. This is a zero based index (1st column is column no 0)
 c=1
 REM Which row has the styock symbol. This is a zero based index (3rd row is row no 2)
 r=2
 REM Which column do you want to store the quote in. This is a zero based index
 destCol=6
 
 Sheet = thisComponent.Sheets(sheetNo)
 do while true
  Cell = Sheet.getCellByPosition(c, r)
  symbol = Cell.String
  if symbol = "END OF SYMBOLS" then
   Print "Processing Complete"
   exit do
  end if
  Dim stockQuote as Currency
  stockQuote = GetSymbolQuote(symbol, Sheet)
  REM Print " " &amp;amp; symbol &amp;amp; " : " &amp;amp; stockQuote
  if stockQuote &amp;lt;&amp;gt; "" then
   DestCell = Sheet.getCellByPosition(destCol, r)
   DestCell.Value = stockQuote
  end if
  r=r+1
 loop
End Sub

Function GetSymbolQuote(symbol as String, aSheet as Object) As Currency

 if symbol = "" then
  GetSymbolQuote = ""
  Exit Function
 end if

 Dim sUrl As String, sFilter As String
 Dim sOptions As String
 Dim stockSymbol As String
 Dim fValue As Double
 Dim oSheet as Object, oSheets as Object
 
 sUrl = "http://in.finance.yahoo.com/d/quotes.csv?s=" &amp;amp; symbol &amp;amp; "&amp;amp;f=sl1"
 sFilter = "Text - txt - csv (StarCalc)"
 sOptions = "44,34,SYSTEM,1,1/10/2/10/3/10/4/10/5/10/6/10/7/10/8/10/9/10" 
 
 oSheet = createSheet(thisComponent.Sheets)
 oSheet.LinkMode = com.sun.star.sheet.SheetLinkMode.NONE
 oSheet.link(sUrl, "", sFilter, sOptions, 1 )
 
 stockSymbol = oSheet.getCellByPosition(0,0).String
 fValue = oSheet.getCellByPosition(1,0).Value 

 GetSymbolQuote = fValue
End Function

Function createSheet(oSheets as Object)
 Dim oSheet as Object
 
 If oSheets.hasByName("Link") Then
  oSheet = oSheets.getByName("Link")
 Else
  oSheet = oDocument.createInstance("com.sun.star.sheet.Spreadsheet")
  oSheets.insertByName("Link", oSheet)
  oSheet.IsVisible = False
   End If 
   
   createSheet = oSheet
End Function
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;script src="http://sites.google.com/site/madhurtanwani/shCore.js?attredirects=0&amp;amp;d=1" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script src="https://sites.google.com/site/madhurtanwani/shBrushVb.js?attredirects=0&amp;amp;d=1" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type="text/javascript"&gt;
SyntaxHighlighter.config.bloggerMode=true;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/2690723850345127268/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/2690723850345127268" rel="replies" title="5 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/2690723850345127268" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/2690723850345127268" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/08/basic-macro-to-get-stock-quotes-for.html" rel="alternate" title="BASIC Macro To Get Stock Quotes for OpenOffice Calc" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-5749427102001781372</id><published>2010-05-28T20:06:00.015+05:30</published><updated>2010-06-25T23:22:48.161+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="httpclient"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="networking"/><category scheme="http://www.blogger.com/atom/ns#" term="proxy"/><category scheme="http://www.blogger.com/atom/ns#" term="proxy selector"/><category scheme="http://www.blogger.com/atom/ns#" term="socks"/><title type="text">Using ProxySelector to take control of what proxies to use and when</title><content type="html">While helping some developers work with a code that I wrote, that used HttpClient, I was confronted with this problem : their existing code requires to work with a socks proxy, while the functionality that my code was providing would not work if sitting behind a proxy. The JVM was instructed to use socks via the &lt;a href="http://java.sun.com/javase/6/docs/technotes/guides/net/properties.html#socks"&gt;socksProxyHost property&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
After reading this &lt;a href="http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html"&gt;excellent guide on proxies in Java&lt;/a&gt;, I decided to try using the ProxySelector mechanism. The results were awesome!!&lt;br /&gt;
&lt;br /&gt;
Using ProxySelector gives us the flexibility to :&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;decide whether a proxy should be used or not for a URI being connected to. You can choose not to use a proxy altogether.&lt;/li&gt;
&lt;li&gt;specify what proxies (yes multiple!) to use - including varying protocols in each proxy&lt;/li&gt;
&lt;li&gt;manage failures when connecting to proxy servers &lt;/li&gt;
&lt;/ol&gt;So here is what I did :&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Extended a new class from Java's java.net.ProxySelector&lt;/li&gt;
&lt;li&gt;The select method of this class (which is an override of the abstract method from the ProxySelector class), would be called each time Java tries to make a network connection - querying for the proxy to be used for that connection. The URI being connected to is passed to the method. I checked the attributes of this URI and if matched the hostname that my code used to connect to (which did not work via a proxy), I returned a java.net.Proxy.NO_PROXY to signify that no proxy should be used for this URI.&lt;/li&gt;
&lt;li&gt;For all other URIs, I did not want to fidget with the user's settings, so I delegated the proxy decision making to the default ProxySelector that ships with Java&lt;/li&gt;
&lt;/ol&gt;Let me put out the code I used to experiment this and everything should be crystal clear&amp;nbsp; :&lt;br /&gt;
&lt;br /&gt;
&lt;div style="height: 400px; overflow: auto;"&gt;&lt;pre class="brush: java"&gt;/**
 *  Created by : Madhur Tanwani
 *  Created on : May 28, 2010
 */
package edu.madhurtanwani.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 *
 * @author Madhur Tanwani (madhurt@yahoo-inc.com)
 */
class CustomProxySelector extends ProxySelector {

    private final ProxySelector def;

    CustomProxySelector(ProxySelector aDefault) {
        this.def = aDefault;
    }

    @Override
    public List&amp;lt;Proxy&amp;gt; select(URI uri) {
        System.out.println("select for URL : " + uri);

        if ("http".equalsIgnoreCase(uri.getScheme()) || "socket".equalsIgnoreCase(uri.getScheme())) {

            if (uri.getHost().startsWith("mail")) {
                List&amp;lt;Proxy&amp;gt; proxyList = new ArrayList&amp;lt;Proxy&amp;gt;();
                proxyList.add(Proxy.NO_PROXY);
                System.out.println("NO PROXY TO BE USED");
                return proxyList;
            }
        }

        //Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("socks.corp.yahoo.com", 1080));
        List&amp;lt;Proxy&amp;gt; select = def.select(uri);
        System.out.println("Default proxy list : " + select);
        return select;
    }

    @Override
    public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

/**
 *
 * @author Madhur Tanwani (madhurt@yahoo-inc.com)
 */
public class Socks_Public {

    private static final String URL_BEHIND_SOCKS = "http://yahoo.com";
    private static final String URL_NO_SOCKS = "http://mail.yahoo.com";

    public static void main(String[] args) throws Exception {
        ProxySelector.setDefault(new CustomProxySelector(ProxySelector.getDefault()));

        System.out.println("\n\n++++++++++++++++++++USING HTTP CLIENT++++++++++++++++++++");

        HttpClient client = new HttpClient();

        System.out.println("\nURL : " + URL_NO_SOCKS);
        GetMethod get = new GetMethod(URL_NO_SOCKS);
        int response = client.executeMethod(get);
        System.out.println("Response code : " + response + " , Response : " + get.getResponseBodyAsString().substring(0, 50));

        System.out.println("\nURL : " + URL_BEHIND_SOCKS);
        get = new GetMethod(URL_BEHIND_SOCKS);
        response = client.executeMethod(get);
        System.out.println("Response code : " + response + " , Response : " + get.getResponseBodyAsString().substring(0, 50));


        System.out.println("\n\n++++++++++++++++++++USING JAVA URL CONNECTION++++++++++++++++++++");

        System.out.println("\nURL : " + URL_NO_SOCKS);
        URI uri = new URI(URL_NO_SOCKS);
        InputStream is = uri.toURL().openStream();
        BufferedReader rdr = new BufferedReader(new InputStreamReader(is));
        for (int i = 0; i &amp;lt; 2; i++) {
            System.out.println(rdr.readLine());
        }
        is.close();


        System.out.println("\nURL : " + URL_BEHIND_SOCKS);
        uri = new URI(URL_BEHIND_SOCKS);
        is = uri.toURL().openStream();
        rdr = new BufferedReader(new InputStreamReader(is));
        for (int i = 0; i &amp;lt; 2; i++) {
            System.out.println(rdr.readLine());
        }
        is.close();
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And here is the output of the code run :&lt;br /&gt;
&lt;pre class="brush: java"&gt;++++++++++++++++++++USING HTTP CLIENT++++++++++++++++++++
URL : http://mail.yahoo.com
select for URL : socket://mail.yahoo.com:80
NO PROXY TO BE USED
select for URL : socket://login.yahoo.com:443
Default proxy list : [SOCKS @ socks.corp.yahoo.com:1080]
Response code : 200 , Response : 
&amp;lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01

URL : http://yahoo.com
select for URL : socket://yahoo.com:80
Default proxy list : [SOCKS @ socks.corp.yahoo.com:1080]
select for URL : socket://www.yahoo.com:80
Default proxy list : [SOCKS @ socks.corp.yahoo.com:1080]
Response code : 200 , Response : &amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"


++++++++++++++++++++USING JAVA URL CONNECTION++++++++++++++++++++

URL : http://mail.yahoo.com
select for URL : http://mail.yahoo.com/
NO PROXY TO BE USED
&amp;lt;!-- l03.member.in2.yahoo.com uncompressed/chunked Fri May 28 20:32:24 IST 2010 --&amp;gt;
null

URL : http://yahoo.com
select for URL : http://yahoo.com/
Default proxy list : [SOCKS @ socks.corp.yahoo.com:1080]
select for URL : http://www.yahoo.com/
Default proxy list : [SOCKS @ socks.corp.yahoo.com:1080]
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;script src="http://sites.google.com/site/madhurtanwani/shCore.js?attredirects=0&amp;amp;d=1" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script src="http://sites.google.com/site/madhurtanwani/shBrushJava.js?attredirects=0&amp;amp;d=1" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type="text/javascript"&gt;
SyntaxHighlighter.config.bloggerMode=true;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/5749427102001781372/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/5749427102001781372" rel="replies" title="1 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/5749427102001781372" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/5749427102001781372" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/05/using-proxyselector-to-take-control-of.html" rel="alternate" title="Using ProxySelector to take control of what proxies to use and when" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-7506263145127813394</id><published>2010-05-04T18:23:00.011+05:30</published><updated>2010-05-09T22:50:39.898+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="mock"/><category scheme="http://www.blogger.com/atom/ns#" term="mockito"/><category scheme="http://www.blogger.com/atom/ns#" term="TDD"/><category scheme="http://www.blogger.com/atom/ns#" term="technology"/><category scheme="http://www.blogger.com/atom/ns#" term="unit test"/><title type="text">Mock, Mock... who's that? (Part 2)</title><content type="html">Starting off where I left my &lt;a href="http://madhurtanwani.blogspot.com/2010/03/mock-mock-whos-that-part-1.html"&gt;first introductory post&lt;/a&gt; of this series - so I chose Mockito as my mocker. What next?&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;The Requirements For Mocking&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Following are the requirements that we wanted to fill up (for starters). Though these requirements are specific to mine, I'm sure almost every project would have the same / similar mocking requirements :&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;b style="font-family: Verdana,sans-serif;"&gt;Objective : &lt;/b&gt;The most important point of using mocking frameworks was to emulate certain behaviour from instances of external dependencies.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;Lets continue with this example :&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background-color: #eeeeee; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; text-align: center;"&gt;&lt;span style="font-size: small;"&gt;+&lt;/span&gt;&lt;span style="font-size: small;"&gt;----&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;----+&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;|&amp;nbsp; &amp;nbsp; &lt;b style="color: #3d85c6;"&gt;MyLoginService&lt;/b&gt; --uses--&amp;gt;&amp;nbsp; &lt;b style="color: #7f6000;"&gt;BackendAuthService&lt;/b&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;/span&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;authenticates via&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;&lt;span style="color: #741b47;"&gt;DataSource&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;+&lt;/span&gt;&lt;span style="font-size: small;"&gt;----&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;-------&lt;/span&gt;&lt;span style="font-size: small;"&gt;----+&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;Here the objective is to unit test &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;&lt;b style="color: #3d85c6;"&gt;MyLoginService&lt;/b&gt;&lt;/span&gt;'s &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;login&lt;/span&gt; API, which in its integration environment would talk to multiple backend services.&lt;/li&gt;
&lt;li&gt; Lets assume that the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;&lt;b style="color: #7f6000;"&gt;BackendAuthService&lt;/b&gt;&lt;/span&gt; has an API named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;login&lt;/span&gt;, which accepts&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=gebo00-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=1933988274" style="border: medium none ! important; margin: 0px ! important; padding: 0px ! important;" width="1" /&gt; a custom class object. This custom class object contains the details of the credentials to authenticate.&lt;/li&gt;
&lt;li&gt;Further, lets say this API returns another custom class object which is the authenticated token after successful authentication. Also, if the authentication fails when this API throws an exception.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b style="font-family: Verdana,sans-serif;"&gt;Independence : &lt;/b&gt;While unit testing (in my Dev or on the &lt;a href="http://martinfowler.com/articles/continuousIntegration.html"&gt;continuous&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Continuous_integration"&gt;integration&lt;/a&gt; farm), I cannot expect the backend services to be available / functional. Hence, unit testers will choose to mock-out the behaviour expected from these &lt;b&gt;external dependencies&lt;/b&gt;.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;Note that this implies that the developer first needs to know possible behaviours exhibited by these dependencies (SuccessCase1, SuccessCase2, FailCase1, FailCase2, ExceptionCase1, ....).&lt;/li&gt;
&lt;li&gt;Then s/he should code the unit test case, such that when the external dependencies are called / invoked, they exhibit the behaviour the unit test case is supposed to test.&lt;/li&gt;
&lt;li&gt;Generally, there would be at least one unit test case for each expected scenario. In addition there would be &lt;a href="http://en.wikipedia.org/wiki/Negative_test"&gt;negative test&lt;/a&gt; cases as well.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;A point to explain what I mean by&amp;nbsp; "mock-out the behaviour". In the above example, for a positive test case, we need (&lt;i&gt;to simulate&lt;/i&gt;) the backend service returning a valid authenticated token, signifying successful authentication. Using the mocking framework, we can induce this simulation on the backend service instance.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b style="font-family: Verdana,sans-serif;"&gt;Integration : &lt;/b&gt;Moving on, the production code uses implementation classes injected via a Spring(-like) framework. So there are configuration files where mappings are defined, injection customizations and finally, instance look up code.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;Modifying the production code flow, for adding any unit testing capability is forbidden.&lt;/li&gt;
&lt;li&gt;Hence, we want to re-use the injection framework, configuration files and the same instance look up code, to seamlessly work while unit testing.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b style="font-family: Verdana,sans-serif;"&gt;Thread Safety : &lt;/b&gt;We wanted to be able to run unit tests in parallel. This is &lt;a href="http://testng.org/doc/documentation-main.html#parallel-running"&gt;very easily possible via TestNG&lt;/a&gt;, in addition to the load of unit test features it provides. In a typical production environment, all instances of these external dependencies are expected to be &lt;a href="http://en.wikipedia.org/wiki/Thread_safety"&gt;thread safe&lt;/a&gt;. Obviously, we want that behaviour to remain even in the mocks.&lt;/li&gt;
&lt;li&gt;&lt;b style="font-family: Verdana,sans-serif;"&gt;Distinct behaviour per thread : &lt;/b&gt;In spite of requirement (4), since every thread in the unit test case would be a test for a different scenario, a developer would want each mock for each test case to behave differently. So though we want thread safety, we also want the mocks to behave differently in each thread.&lt;/li&gt;
&lt;/ol&gt;Cool! So we now know what we want to do. Moving on to how it was done.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Approaches Possible&lt;/b&gt;&lt;br /&gt;
Before I explicitly state the solution we adopted, I want to discuss the various possibilities we considered. This section talks about those.&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Spring supports &lt;a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-scopes"&gt;two bean scopes&lt;/a&gt; by default for standalone applications - prototype and singleton (default). What we needed was a way to define mock implementation classes in the spring configuration, such that each thread would have its own mocked instance - basically &lt;b&gt;thread scope.&lt;/b&gt; This way the thread safety of the mocked instance and different-behaviour-per-thread requirements can be achieved.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;One way out here was to define a &lt;a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-scopes-custom"&gt;custom scope&lt;/a&gt; in Spring. (see also the &lt;a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/context/support/SimpleThreadScope.html"&gt;SimpleThreadScope&lt;/a&gt; class in available in 3.0.x version).&lt;/li&gt;
&lt;li&gt;Another way out is to ask Spring to use factories for bean creation and then take control over this aspect by implementing a factory. &lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;We wanted the capability to choose / change mocker implementations in the future. Hence, we wanted control over the way these mock objects were created / initialized / refreshed etc... - so we wanted to implement the factory that Spring would turn to for bean instance creation.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;Spring provides a convenient way to do this - using &lt;a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-extension-factorybean"&gt;FactoryBean&lt;/a&gt;s. By implementing FactoryBean interface, we can write a factory class that will generate beans as well as control singleton behaviour.&lt;/li&gt;
&lt;li&gt;Other &lt;a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-class"&gt;methods&lt;/a&gt; using instance factories and static factories are also possible&lt;/li&gt;
&lt;/ul&gt;&lt;/ol&gt;&lt;b&gt;Approach Implemented&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Use an implementation of Spring's &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;FactoryBean&lt;/span&gt; to serve as a factory for creating beans. This implementation, lets name it &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockServiceLookUp&lt;/span&gt;, will be called whenever the code flow requests for some bean.&lt;/li&gt;
&lt;li&gt;The &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockServiceLookUp&lt;/span&gt; implementation is responsible for creating mocked instances for the class that is being looked up - &lt;b&gt;one instance per thread&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockServiceLookUp&lt;/span&gt; implementation will rely on the use of a &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockProvider&lt;/span&gt; to create actual mock objects. The &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockProvider&lt;/span&gt; is the class that will actually use the mocker library to create mocks.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;Ideally, &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockProvider &lt;/span&gt;should be an interface, with multiple implementations for each type of mocker you want to support (so that those can be plugged in as needed).&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Alternately, &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockProvider &lt;/span&gt;can be skipped completely and the mocker library can be used in the look up implementation to create mock instances.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;For every look up request, the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockServiceLookUp &lt;/span&gt;will first check whether a mock implementation for the class being looked up exists in its &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;ThreadLocal&lt;/span&gt;. If it does, the instance is returned, otherwise the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockProvider&lt;/span&gt; is consulted.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;The general case is that unit test will fetch the mock instance for a class that the actual code the unit test is for will be using. Then the unit test would "apply" behaviour mocking on this instance (i.e. &lt;a href="http://mockito.googlecode.com/svn/branches/1.8.0/javadoc/org/mockito/Mockito.html#2"&gt;behavior stubbing&lt;/a&gt;) and finally call the actual API to test.&lt;/li&gt;
&lt;li&gt;Since the API would also look up the same class from Spring (which in turn will request &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockServiceLookUp &lt;/span&gt;for the instance), the API would get a mock instance with appropriate methods stubbed. These methods would be those that the unit test expects the API to call on the backend/dependency. Hence, the unit test would be complete.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;Finally, the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockServiceLookUp &lt;/span&gt;also provided for a "clear all" API to erase all the stubbing performed on the mock instances in its &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;ThreadLocal&lt;/span&gt;.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;This was a useful API for us - to start afresh from within a unit test - where we wanted to discard all previous stubbing&lt;/li&gt;
&lt;li&gt;This API was also called by default from out unit testing infrastructure whenever a new unit test case started - hence ensuring all unit tests started clean.&lt;/li&gt;
&lt;/ul&gt;&lt;/ol&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
This is what the mock framework class diagram &lt;span style="font-size: x-small;"&gt;(taken with permission - thanks to my colleague Siju)&lt;/span&gt; is like :&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5I9DVbMJZyZrZyj-ZWdg9aiEyUCQAvmGBJhB-uLz9nWYKP5MRFPi10cZN6zH2rakeCLmhQLZ6UOKlnD-ykDNPTMnJG8vVQD6PuEYHNAQbC1sRQFe-l2VZs5LUVuY7LnUWT-U5/s1600/MockServiceLookup_ClassDia.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5I9DVbMJZyZrZyj-ZWdg9aiEyUCQAvmGBJhB-uLz9nWYKP5MRFPi10cZN6zH2rakeCLmhQLZ6UOKlnD-ykDNPTMnJG8vVQD6PuEYHNAQbC1sRQFe-l2VZs5LUVuY7LnUWT-U5/s1600/MockServiceLookup_ClassDia.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, a unit test would run like this :&lt;br /&gt;
&lt;ol&gt;&lt;ul style="color: black;"&gt;&lt;li style="color: #3d85c6;"&gt;Unit Test Case Start&lt;/li&gt;
&lt;li style="color: #3d85c6;"&gt;Use Spring to fetch the implementation for &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;&lt;b style="color: #7f6000;"&gt;BackendAuthService&lt;/b&gt;&lt;/span&gt;.&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;Spring would invoke the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockServiceLookUp&lt;/span&gt;'s &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;getObject()&lt;/span&gt; API to get the implementation of &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;&lt;b style="color: #7f6000;"&gt;BackendAuthService&lt;/b&gt;&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockServiceLookUp&lt;/span&gt; would first check if an existing implementation of the class exists already, in its &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;ThreadLocal&lt;/span&gt;. If this is the first &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;getObject&lt;/span&gt; call for this class, then the mock method of the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockProvider&lt;/span&gt; is called. Otherwise, the mock instance from &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;ThreadLocal&lt;/span&gt; is returned.&lt;/li&gt;
&lt;li&gt;The &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;MockProvider&lt;/span&gt; will use Mockito to create the mock instance of the specified class.&lt;/li&gt;
&lt;/ul&gt;
&lt;li style="color: #3d85c6;"&gt;The unit test will override the behaviour of the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;&lt;b style="color: #7f6000;"&gt;BackendAuthService&lt;/b&gt;&lt;/span&gt;'s &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;login&lt;/span&gt; API&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;The behaviour override can be to return valid values (auth tokens) or invalid values (excetpions, errors, invalid auth tokens) depending on what is being tested&lt;/li&gt;
&lt;/ul&gt;
&lt;li style="color: #3d85c6;"&gt;Then the test would make a call to &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;&lt;b style="color: #3d85c6;"&gt;MyLoginService&lt;/b&gt;&lt;/span&gt;'s &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;login&lt;/span&gt; API&lt;/li&gt;

&lt;ul&gt;&lt;li&gt;This implementation would again request Spring for the implementation of the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;&lt;b style="color: #7f6000;"&gt;BackendAuthService&lt;/b&gt;&lt;/span&gt; class, which this time will be the stubbed mock instance.&lt;/li&gt;
&lt;li&gt;When the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;login&lt;/span&gt; API on &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;&lt;b style="color: #7f6000;"&gt;BackendAuthService&lt;/b&gt;&lt;/span&gt; is called the stubbed code executes returning the auth token / exception.&lt;/li&gt;
&lt;/ul&gt;
&lt;li style="color: #3d85c6;"&gt;After the API call completes, the unit test must verify that the auth token returned is valid or not (or if an exception was excepted, whether it was thrown or not).&lt;/li&gt;
&lt;li style="color: #3d85c6;"&gt;Unit Test Case End&lt;/li&gt;
&lt;/ul&gt;&lt;/ol&gt;Hope this post has helped you understand how "instances" of classes are mocked and injected into production code, in a distinct-behaviour-per-thread manner. Good luck with mocking!</content><link href="http://madhurtanwani.blogspot.com/feeds/7506263145127813394/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/7506263145127813394" rel="replies" title="0 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/7506263145127813394" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/7506263145127813394" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/05/mock-mock-whos-that-part-2.html" rel="alternate" title="Mock, Mock... who's that? (Part 2)" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5I9DVbMJZyZrZyj-ZWdg9aiEyUCQAvmGBJhB-uLz9nWYKP5MRFPi10cZN6zH2rakeCLmhQLZ6UOKlnD-ykDNPTMnJG8vVQD6PuEYHNAQbC1sRQFe-l2VZs5LUVuY7LnUWT-U5/s72-c/MockServiceLookup_ClassDia.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-1008717523877262279</id><published>2010-05-04T14:14:00.000+05:30</published><updated>2010-05-04T14:14:05.640+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="hashing"/><category scheme="http://www.blogger.com/atom/ns#" term="irrational"/><category scheme="http://www.blogger.com/atom/ns#" term="mathematics"/><category scheme="http://www.blogger.com/atom/ns#" term="theorem"/><title type="text">Three Distance Theorem</title><content type="html">&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;While learning from &lt;a href="http://www.cs.sunysb.edu/%7Ealgorith/math-video/lec5.html"&gt;this video lecture&lt;/a&gt; by Steve Skiena on Discrete Mathematics, he explains the Three Distance Theorem (at time 37:32).&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;The Three Distance Theorem goes like this :&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;For any irrational number '&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;a&lt;/span&gt;', if the sequence of points &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;{i*a}&lt;/span&gt;, where &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;0 &amp;lt;= i &amp;lt;= n&lt;/span&gt;, are plotted on a unit distance / circle (wrapped at unit distance), then :&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;span style="font-size: small;"&gt;The points divide the circle / line into &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;n+1&lt;/span&gt; distances&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: small;"&gt;The maximum number of distinct distances defined is 3&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: small;"&gt;The minimum number of distinct distances defined is 2&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: small;"&gt;Of the three distinct distances, one is a sum of the other two&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;span style="font-size: small;"&gt;Here is a single page PDF explaining the theorem nicely : &lt;a href="http://myweb1.lsbu.ac.uk/%7Ewhittyr/MathSci/TheoremOfTheDay/NumberTheory/ThreeDistance/TotDThreeDistance.pdf"&gt;http://myweb1.lsbu.ac.uk/~whittyr/MathSci/TheoremOfTheDay/NumberTheory/ThreeDistance/TotDThreeDistance.pdf&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: small;"&gt;The findings are really awesome - as Prof Skiena explains and proves the theorem in the lecture.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;&lt;b&gt;Application To Hashing&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;I think because of the distinct distance generation property of the theorem, the theorem can be an effective way to avoid collisions by the basic &lt;a href="http://en.wikipedia.org/wiki/Hash_table#Open_addressing"&gt;multiplication method&lt;/a&gt;. Ofcourse the other limitations of open addressing apply, but if that approach is chosen, this theorem might be helpful.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;The basic idea for collision resoluton would be hashing in this order :&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;h(k, 1) = H(K*1*a)&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;h(k, 2) = H(K*2*a)&lt;/span&gt;&lt;span style="font-size: small;"&gt; ...&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;where&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace; font-size: small;"&gt;h(k, l)&lt;/span&gt;&lt;span style="font-size: small;"&gt; - hash for the key &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;k&lt;/span&gt;, being hashed for the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;l&lt;/span&gt;th time&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;k&lt;/span&gt; - key to insert / lookup&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;a&lt;/span&gt; - an irrational number&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: small;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;1, 2&lt;/span&gt; - the first, second lookup. The &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;l+1&lt;/span&gt;th lookup should be performed only if &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;l&lt;/span&gt;th lookup had a collision&lt;/span&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/1008717523877262279/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/1008717523877262279" rel="replies" title="0 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/1008717523877262279" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/1008717523877262279" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/05/three-distance-theorem.html" rel="alternate" title="Three Distance Theorem" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-647489257803235544</id><published>2010-05-03T20:40:00.003+05:30</published><updated>2010-05-03T22:38:32.207+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="hanoi"/><category scheme="http://www.blogger.com/atom/ns#" term="mathematics"/><category scheme="http://www.blogger.com/atom/ns#" term="solved"/><category scheme="http://www.blogger.com/atom/ns#" term="warmup"/><title type="text">Tower of Hanoi with a restriction of no direct transfers</title><content type="html">We need to solve the &lt;a href="http://en.wikipedia.org/wiki/Tower_of_Hanoi"&gt;Tower of Hanoi&lt;/a&gt; problem, with this additional restriction : direct moves between the origin and destination towers is disallowed. All other restrictions still apply&amp;nbsp; as-is.&lt;br /&gt;
&lt;br /&gt;
For example, if a single disk is to be moved from Tower A to Tower B (using Tower C), then moving the disk directly from A to B is not allowed. The disk must be first transferred to Tower C and then to Tower B.&lt;br /&gt;
&lt;br /&gt;
The purpose is to find the shortest sequence / number of moves we can do this in :&amp;nbsp; &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;T(0) = 0 (basis case, nothing to move)&lt;/li&gt;
&lt;li&gt;T(1) = 2 (from above)&lt;/li&gt;
&lt;li&gt;T(n-discs) = ???&lt;/li&gt;
&lt;/ul&gt;Source : &lt;a href="http://amzn.to/concretemaths"&gt;Concrete Mathematics (2nd Edition) Ex. 1.2&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=gebo00-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0201558025" style="border: medium none ! important; margin: 0px ! important;" width="1" /&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/647489257803235544/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/647489257803235544" rel="replies" title="4 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/647489257803235544" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/647489257803235544" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/05/tower-of-hanoi-with-restrictions.html" rel="alternate" title="Tower of Hanoi with a restriction of no direct transfers" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-1170016769084454503</id><published>2010-04-16T19:02:00.005+05:30</published><updated>2010-04-16T19:06:40.684+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="arithmetic series"/><category scheme="http://www.blogger.com/atom/ns#" term="induction"/><category scheme="http://www.blogger.com/atom/ns#" term="mathematics"/><category scheme="http://www.blogger.com/atom/ns#" term="summation"/><title type="text">Find the summation of first 'n' odd numbers</title><content type="html">Find a simple formula for the summation of the first 'n' odd numbers (1, 3, 5.....).&lt;br /&gt;
More formally, find a general solution for : 
&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;n&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;
&lt;span style="font-size: x-large;"&gt;Σ &lt;/span&gt;(2k-1)&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;
k=1&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Source : CLRS A.1-1</content><link href="http://madhurtanwani.blogspot.com/feeds/1170016769084454503/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/1170016769084454503" rel="replies" title="3 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/1170016769084454503" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/1170016769084454503" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/04/summation-of-first-n-odd-numbers.html" rel="alternate" title="Find the summation of first 'n' odd numbers" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-3597434132928791608</id><published>2010-03-08T22:55:00.006+05:30</published><updated>2010-03-26T13:17:36.890+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="brindavan garden"/><category scheme="http://www.blogger.com/atom/ns#" term="mysore"/><category scheme="http://www.blogger.com/atom/ns#" term="road trip"/><category scheme="http://www.blogger.com/atom/ns#" term="travel"/><title type="text">Road Trip To Brindavan Garden</title><content type="html">Hola! Sunday afternoon and nothing else to do &lt;span style="font-size: x-small;"&gt;(except a code commit and few distribution builds)&lt;/span&gt; we decided to take a trip the famous &lt;a href="http://en.wikipedia.org/wiki/Brindavan_Gardens"&gt;Brindavan Gardens&lt;/a&gt; built next to the KRS Dam @ Mandya.&lt;br /&gt;
&lt;br /&gt;
Check the petrol, check the tyres and off we were. We started from Old Madras Road (Bangalore) @ 2:30 PM and swearing on the Bangalore roads and traffic subdued when we reached the Mysore highway at about 3:45 PM. Phew!&lt;br /&gt;
&lt;br /&gt;
After that it was a wonderful road (minus those @#!$*@ speed breakers that stopped me from touch 110 kmph) all the way till Mysore. We finally reached the Brindavan Gardens at 6:30 PM - just in time for the entries to start.&lt;br /&gt;
&lt;br /&gt;
We quickly bought ticket (INR 15 per person, INR 50 per camera) and rushed into a huge line for the entry. The lights were already on and the excitement to see the musical fountains was at its peak.&lt;br /&gt;
&lt;br /&gt;
Its a long walk to the musical fountain and by the time we reached there, one round of the show had ended.I clicked the beautifully landscaped garden in the mean time - its awesome to see!!&lt;br /&gt;
&lt;br /&gt;
When the music started again, we rushed to the place. I must say I was a little disappointed by the show, maybe because of my high expectations from all the hype, but I'm sure better music and better fountain synchronization can be achieved. That apart, it was a good show - specially when the water reaches the peaks - its great then!&lt;br /&gt;
&lt;br /&gt;
After the show we returned to the other side of the garden (towards Hotel Orchid), that's on the other side of the walking bridge. I like this part the most - it was calm, had lots of places to sit, no people rush this side, lots of nicely laid fountains and water paths. I loved this place!&lt;br /&gt;
&lt;br /&gt;
We walked all the way upto the Orchid Hotel - the view from the top is amazing!! Finally, I ran out of batteries, most of the garden was clicked and it was almost 8:30 PM - so we decided to head back home,&lt;br /&gt;
&lt;br /&gt;
We reached home @ 12:00. &lt;span style="font-size: x-small;"&gt;Very tired I finished the code commits and disted the builds - may the Force be with the QA team ;-).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This was one hell of a trip - I loved it!!&amp;nbsp; Some photos and videos from the trip : &lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
&lt;a href="http://www.flickr.com/photos/madhurtanwani/4415824085/" title="IMG_0222 by Madhur Kumar Tanwani, on Flickr"&gt;&lt;img alt="IMG_0222" height="180" src="http://farm5.static.flickr.com/4050/4415824085_9e55763e14_m.jpg" width="240" /&gt;&lt;/a&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;a href="http://www.flickr.com/photos/madhurtanwani/4415842097/" title="IMG_0314 by Madhur Kumar Tanwani, on Flickr"&gt;&lt;img alt="IMG_0314" height="180" src="http://farm3.static.flickr.com/2757/4415842097_443df96b4f_m.jpg" width="240" /&gt;&lt;/a&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;a href="http://www.flickr.com/photos/madhurtanwani/4416592250/" title="IMG_0232 by Madhur Kumar Tanwani, on Flickr"&gt;&lt;img alt="IMG_0232" height="180" src="http://farm5.static.flickr.com/4047/4416592250_8e12405f60_m.jpg" width="240" /&gt;&lt;/a&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt; &lt;td align="center" colspan="3"&gt;&lt;br /&gt;
&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" height="300" type="application/x-shockwave-flash" width="400"&gt; &lt;param name="flashvars" value="intl_lang=en-us&amp;photo_secret=2aa107c1bb&amp;photo_id=4415830649&amp;flickr_show_info_box=true"&gt;&lt;/param&gt;&lt;param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"&gt;&lt;/param&gt;&lt;param name="bgcolor" value="#000000"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&amp;photo_secret=2aa107c1bb&amp;photo_id=4415830649&amp;flickr_show_info_box=true" height="300" width="400"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/3597434132928791608/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/3597434132928791608" rel="replies" title="1 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/3597434132928791608" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/3597434132928791608" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/03/road-trip-to-brindavan-garden.html" rel="alternate" title="Road Trip To Brindavan Garden" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="http://farm5.static.flickr.com/4050/4415824085_9e55763e14_t.jpg" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-8488919923624236749</id><published>2010-03-03T02:23:00.002+05:30</published><updated>2010-03-04T23:55:19.468+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="easymock"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="jmockit"/><category scheme="http://www.blogger.com/atom/ns#" term="mock"/><category scheme="http://www.blogger.com/atom/ns#" term="mockito"/><category scheme="http://www.blogger.com/atom/ns#" term="TDD"/><category scheme="http://www.blogger.com/atom/ns#" term="technology"/><category scheme="http://www.blogger.com/atom/ns#" term="unit test"/><title type="text">Mock, Mock... who's that? (Part 1)</title><content type="html">Let me begin with this quote from &lt;a href="http://martinfowler.com/articles/mocksArentStubs.html"&gt;Martin Fowler's post&lt;/a&gt; :&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;The term 'Mock Objects' has become a popular one to  describe special case objects that mimic real objects for  testing. Most language environments now have frameworks that make it  easy to create mock objects. What's often not realized, however, is  that mock objects are but one form of special case test object, one  that enables a different style of testing.&lt;/i&gt;&lt;/blockquote&gt;&lt;b&gt;&lt;span style="font-size: large;"&gt;Mocking - huh?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
This post series is not to explain / debate on mocking and stubbing test strategies. If you are interested in reading what mocks are, why to use them and so on, please refer to the following links :&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;This &lt;a href="http://martinfowler.com/articles/mocksArentStubs.html"&gt;article by Martin Fowler&lt;/a&gt; describing mocks, stubs their differences and test strategies. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Mock_object"&gt;Mock Objects article on Wikipedia&lt;/a&gt; - an excellent starting point.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.mockobjects.com/"&gt;MockObjects.com&lt;/a&gt; - A site dedicated to mock objects!&lt;/li&gt;
&lt;/ul&gt;If you have decided to take the mock path and are interested in how to use mocks, please read on. Here  is my agenda on covering what I've learned from my project's mock  testing efforts :&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Mocking libraries and comparison. What I've  finally used and why&lt;/li&gt;
&lt;li&gt;Mocking of instance functions, in a thread safe manner&lt;/li&gt;
&lt;li&gt; Mocking of static functions, in a thread safe manner&lt;/li&gt;
&lt;li&gt;Mocking of static getInstance() / factory methods, in a thread safe  manner&lt;/li&gt;
&lt;/ol&gt;Though my mock usage examples would be in Java, most of the concepts can be used across languages. So, here we go...&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Mocking libraries and comparison&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
There are multiple library projects that offer mocking and stubbing functionality. The number of choices are overwhelming and its often difficult to decide what's the right one to choose. For starters, simple dynamic proxy or sub-classing "mockers" would be just fine. For advances usages, "mockers" with greater benefits - probably state maintenance, static mocking would be useful.&lt;br /&gt;
&lt;br /&gt;
A comparison of currently available mock libraries can be found here :&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;JMockit documentation recently hosted an &lt;a href="http://code.google.com/p/jmockit/wiki/MockingToolkitComparisonMatrix"&gt;exhaustive comparison matrix&lt;/a&gt; recently.&lt;/li&gt;
&lt;li&gt;A &lt;a href="http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html"&gt;comparison by Vasily Sizov&lt;/a&gt; on his blog from March 2009. &lt;/li&gt;
&lt;li&gt;StackOverFlow.com users had this &lt;a href="http://stackoverflow.com/questions/22697/whats-the-best-mock-framework-for-java"&gt;great discussion over mock library choices&lt;/a&gt; &lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
Our initial set of candidates included &lt;a href="http://easymock.org/"&gt;EasyMock &lt;/a&gt;and &lt;a href="http://code.google.com/p/mockito"&gt;Mockito&lt;/a&gt;. Though &lt;a href="http://code.google.com/p/jmockit"&gt;JMockit &lt;/a&gt;sounded very tempting, due to lack of documentation (about 4 months back - though its improved quite a lot now) we did not want to adopt it - or so we thought.&lt;br /&gt;
&lt;br /&gt;
EasyMock and Mockito are both very easy to code to and it was a tough call which one to use. Finally, multiple team members got their hands dirty using the two libraries and we voted. The winner was &lt;b&gt;&lt;a href="http://code.google.com/p/mockito"&gt;Mockito&lt;/a&gt; &lt;/b&gt;- we simply loved its documentation (everything was just there) and the extensibility for mocking behaviors. I have been happily mocking using Mockito since then - here I have use and like about Mockit :&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;unlike EasyMock, Mockito is not a "record-n-play" mocker. You mock out what is necessary, when it is necessary, make unit test API calls and then verify expectations - all on demand.&lt;/li&gt;
&lt;li&gt;behavior mocking is very simple, written like English sentences in code : &lt;span style="font-size: small;"&gt;&lt;span style="background-color: white; color: #666666; font-family: Verdana,sans-serif;"&gt;when(BasicService.foo()).thenReturn(retval);&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;throwing exceptions, tracking number of calls made was possible and easy&lt;/li&gt;
&lt;li&gt;the return values from mock methods can be customized using the API call parameters. &lt;/li&gt;
&lt;li&gt;verification of mocked behavior is easy. Though there is no auto-verification feature.&lt;/li&gt;
&lt;/ul&gt;Hope this post will help you find your mocker. I will follow up with more posts on how we used mocks in a thread safe manner, injected them into Spring and how mocking static functions made us use a mix of Mockito and JMockit :). Stay tuned!&lt;br /&gt;
&lt;ol&gt;&lt;/ol&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/8488919923624236749/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/8488919923624236749" rel="replies" title="0 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/8488919923624236749" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/8488919923624236749" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/03/mock-mock-whos-that-part-1.html" rel="alternate" title="Mock, Mock... who's that? (Part 1)" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-2614980651249917673</id><published>2010-03-02T01:40:00.001+05:30</published><updated>2010-03-04T23:55:50.812+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="xkcd joke"/><title type="text">Hilarious Strips from xkcd</title><content type="html">After reading this &lt;a href="http://xkcd.com/703/"&gt;hilarious&lt;/a&gt; suggestion, I fooled around to find some more :&lt;br /&gt;
&lt;h1&gt;Zealous Autoconfig&lt;/h1&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://imgs.xkcd.com/comics/zealous_autoconfig.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://imgs.xkcd.com/comics/zealous_autoconfig.png" /&gt;&lt;/a&gt;&lt;/div&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/2614980651249917673/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/2614980651249917673" rel="replies" title="0 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/2614980651249917673" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/2614980651249917673" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/03/hilarious-strips-from-xkcd.html" rel="alternate" title="Hilarious Strips from xkcd" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-7899113775200715477</id><published>2010-01-11T22:58:00.001+05:30</published><updated>2010-01-11T23:00:17.560+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="OCW"/><category scheme="http://www.blogger.com/atom/ns#" term="search"/><category scheme="http://www.blogger.com/atom/ns#" term="unimodal"/><title type="text">Unimodal Search</title><content type="html">An array &lt;span style="font-family: courier new,monospace;"&gt;A[1...n]&lt;/span&gt; is &lt;b&gt;unimodal&lt;/b&gt; if it consists of an increasing sequence followed by a decreasing sequence. More precisely, if there is an index &lt;span style="font-family: comic sans ms,sans-serif;"&gt;m&lt;/span&gt; in &lt;span style="font-family: courier new,monospace;"&gt;{1, 2, ... n}&lt;/span&gt; such that&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;A[i] &amp;lt; A[i+1] &lt;span style="font-family: arial,helvetica,sans-serif;"&gt;for&lt;/span&gt; 1 &amp;lt;= i &amp;lt; m&lt;/span&gt; and&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;A[i] &amp;gt; A[i+1] &lt;span style="font-family: arial,helvetica,sans-serif;"&gt;for&lt;/span&gt; m &amp;lt;= i &amp;lt; n&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In particular, &lt;span style="font-family: courier new,monospace;"&gt;A[m]&lt;/span&gt; is the maximum element, and it is the unique "locally maximum" element surrounded by smaller elements.&lt;br /&gt;
&lt;br /&gt;
Give an algorithm to compute the maximum element of a unimodal input array &lt;span style="font-family: courier new,monospace;"&gt;A[1...n]&lt;/span&gt; in &lt;span style="font-family: courier new,monospace;"&gt;O(lg n)&lt;/span&gt; time.&lt;br /&gt;
&lt;br /&gt;
Source: &lt;a href="http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/Assignments/index.htm"&gt;Problem 1-3.from MIT OpenCourseWare Course - 6.046J / 18.410J Introduction to Algorithms (SMA 5503)&lt;/a&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/7899113775200715477/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/7899113775200715477" rel="replies" title="2 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/7899113775200715477" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/7899113775200715477" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/01/unimodal-search.html" rel="alternate" title="Unimodal Search" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-5470391388757571644</id><published>2010-01-11T00:11:00.000+05:30</published><updated>2010-01-11T00:11:22.354+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="bulb"/><category scheme="http://www.blogger.com/atom/ns#" term="mathematics"/><category scheme="http://www.blogger.com/atom/ns#" term="OOTB"/><category scheme="http://www.blogger.com/atom/ns#" term="switch"/><title type="text">100 Switches &amp; 100 bulbs</title><content type="html">There are 100 switches in a room operating 100 bulbs. At iteration '0' all switches are OFF. For every iteration 'i', all switches that are multiples of 'i' are toggled (turn OFF if ON, turn ON if OFF).&lt;br /&gt;
&lt;br /&gt;
You need to find the state of the 'k'th switch/bulb (1&lt;k&gt;&amp;lt;=100) after the 'i' th iteration&lt;/k&gt;&lt;br /&gt;
&lt;br /&gt;
Expected O(1) time and space complexity.</content><link href="http://madhurtanwani.blogspot.com/feeds/5470391388757571644/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/5470391388757571644" rel="replies" title="2 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/5470391388757571644" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/5470391388757571644" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2010/01/100-switches-100-bulbs.html" rel="alternate" title="100 Switches &amp; 100 bulbs" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-429323671901232882</id><published>2009-12-02T00:02:00.002+05:30</published><updated>2009-12-02T00:03:46.782+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="amazon"/><category scheme="http://www.blogger.com/atom/ns#" term="binary trees"/><category scheme="http://www.blogger.com/atom/ns#" term="data structures"/><category scheme="http://www.blogger.com/atom/ns#" term="recurrsion"/><category scheme="http://www.blogger.com/atom/ns#" term="trees"/><title type="text">[ALGO] Is Binary Search Tree</title><content type="html">Given a binary tree, verify if it is Binary Search Tree</content><link href="http://madhurtanwani.blogspot.com/feeds/429323671901232882/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/429323671901232882" rel="replies" title="4 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/429323671901232882" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/429323671901232882" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2009/12/algo-is-binary-search-tree.html" rel="alternate" title="[ALGO] Is Binary Search Tree" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-6398309975202928148</id><published>2009-12-01T00:01:00.002+05:30</published><updated>2009-12-01T00:04:11.603+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="backtracking"/><category scheme="http://www.blogger.com/atom/ns#" term="matrix"/><category scheme="http://www.blogger.com/atom/ns#" term="microsoft"/><category scheme="http://www.blogger.com/atom/ns#" term="recurrsion"/><title type="text">[ALGO] Find the string in 2 dimensional matrix</title><content type="html">Given a 2-dim matrix of characters 'm' and a string 's' - find if the string 's' is present in the matrix. Only characters in the neighboring cells of a cell can contribute to the string.&lt;br /&gt;
&lt;br /&gt;
For example, for the case below B,D,F,G are neighbors of X. From 'X' possible strings (or substrings) are XB, XD, XF, XH. &lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;|&amp;nbsp; A&amp;nbsp; |&amp;nbsp; B&amp;nbsp; |&amp;nbsp; C&amp;nbsp; |&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;|&amp;nbsp; H&amp;nbsp; |&amp;nbsp; &lt;b&gt;X&lt;/b&gt;&amp;nbsp; |&amp;nbsp; D&amp;nbsp; |&lt;br /&gt;
&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;|&amp;nbsp; G&amp;nbsp; |&amp;nbsp; F&amp;nbsp; |&amp;nbsp; E&amp;nbsp; |&lt;br /&gt;
&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Finally, an example. Given the matrix &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;(0,0)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; y&amp;nbsp; |&amp;nbsp; a&amp;nbsp; |&amp;nbsp; a&amp;nbsp; |&amp;nbsp; o&amp;nbsp; |&lt;br /&gt;
&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; a&amp;nbsp; |&amp;nbsp; o&amp;nbsp; |&amp;nbsp; a&amp;nbsp; |&amp;nbsp; o&amp;nbsp; |&lt;br /&gt;
&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; y&amp;nbsp; |&amp;nbsp; a&amp;nbsp; |&amp;nbsp; o&amp;nbsp; |&amp;nbsp; o&amp;nbsp; |&lt;br /&gt;
&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; h&amp;nbsp; |&amp;nbsp; a&amp;nbsp; |&amp;nbsp; a&amp;nbsp; |&amp;nbsp; o&amp;nbsp; |&lt;br /&gt;
&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; y&amp;nbsp; |&amp;nbsp; a&amp;nbsp; |&amp;nbsp; h&amp;nbsp; |&amp;nbsp; o&amp;nbsp; |&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |-----|-----&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt;|-----|-----|&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (3,3)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
and asked to check for the string 'yahoo' the solution is &lt;span style="font-family: courier new,monospace;"&gt;true&lt;/span&gt; : &lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;y - (3,0)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;a&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt; - (3,1)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;h&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt; - (3,2)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;o&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt; - (3,3)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: courier new,monospace;"&gt;o&lt;/span&gt;&lt;span style="font-family: courier new,monospace;"&gt; - (2,3)&lt;/span&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/6398309975202928148/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/6398309975202928148" rel="replies" title="0 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/6398309975202928148" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/6398309975202928148" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2009/12/algo-find-string-in-2-dimensional.html" rel="alternate" title="[ALGO] Find the string in 2 dimensional matrix" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-9110111024785291490</id><published>2009-11-30T23:43:00.002+05:30</published><updated>2009-11-30T23:45:01.025+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="probability"/><category scheme="http://www.blogger.com/atom/ns#" term="randomized"/><title type="text">[ALGO] Random number generator, with equal probability</title><content type="html">&lt;span style="font-family: courier new,monospace;"&gt;RANDOM(a.b)&lt;/span&gt; is a random number generator that generates integers between a and b (inclusive), all equally likely.&lt;br /&gt;
&lt;br /&gt;
Assuming we have an implementation of &lt;span style="font-family: courier new,monospace;"&gt;RANDOM(0.1)&lt;/span&gt;, how can we implement &lt;span style="font-family: courier new,monospace;"&gt;RANDOM(a.b)&lt;/span&gt; - i.e. given we have a function that returns &lt;b&gt;&lt;span style="font-family: courier new,monospace;"&gt;0&lt;/span&gt;&lt;/b&gt; OR &lt;b style="font-family: courier new,monospace;"&gt;1&lt;/b&gt; both with a probability of &lt;b&gt;&lt;span style="font-family: courier new,monospace;"&gt;1/2&lt;/span&gt;&lt;/b&gt;, how can we implement a function that returns integers from &lt;b&gt;&lt;span style="font-family: courier new,monospace;"&gt;a&lt;/span&gt;&lt;/b&gt; to &lt;b style="font-family: courier new,monospace;"&gt;b&lt;/b&gt; (&lt;b style="font-family: courier new,monospace;"&gt;b&lt;/b&gt; &amp;gt; &lt;b style="font-family: courier new,monospace;"&gt;a&lt;/b&gt;), all with a probability of &lt;b style="font-family: courier new,monospace;"&gt;1/n&lt;/b&gt;, where &lt;b&gt;&lt;span style="font-family: courier new,monospace;"&gt;n = (b-a+1)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Source : Cormen - Problem 5.1-2 (randomized algorithms)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similar problem : &lt;br /&gt;
At a restaurant, how can Veronica choose one out of three desserts with equal probability with the help of a coin?&lt;br /&gt;
&lt;br /&gt;
Its on Gurmeet's site here&amp;nbsp; &lt;a href="http://gurmeetsingh.wordpress.com/2008/09/12/puzzle-tossing-with-one-third-probability/"&gt;http://gurmeetsingh.wordpress.com/2008/09/12/puzzle-tossing-with-one-third-probability/&lt;/a&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/9110111024785291490/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/9110111024785291490" rel="replies" title="3 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/9110111024785291490" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/9110111024785291490" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2009/11/algo-random-number-generator-with-equal.html" rel="alternate" title="[ALGO] Random number generator, with equal probability" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-6550999242213983848</id><published>2009-11-08T23:03:00.002+05:30</published><updated>2009-11-10T22:08:08.923+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="education"/><category scheme="http://www.blogger.com/atom/ns#" term="learning"/><category scheme="http://www.blogger.com/atom/ns#" term="todo"/><title type="text">Things To Do...</title><content type="html">I recently attended a Spring training by SpringSource. While learning the framework and admiring its features, it prick me that there is a LOT that I don't know and have to gather.&lt;br /&gt;
&lt;br /&gt;
So, after a long time I'm starting this post, that I anticipate to update regularly with &lt;b&gt;things I want to do&lt;/b&gt;, &lt;b&gt;things I want to learn&lt;/b&gt; and &lt;b&gt;things I want to talk about&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Expect one blog title for each entry in this list. So, here I go :&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;b style="background-color: white; color: blue;"&gt;&lt;span style="background-color: black; color: orange;"&gt;P1:&lt;/span&gt; &lt;/b&gt;Spring - an E2E tutorial - put to use all the learning from the training into a live example.&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: lime;"&gt;&lt;span style="background-color: black;"&gt;P2:&lt;/span&gt;&lt;/b&gt; OSGi - post an article listing resources I read to understand OSGi. Maybe with a few self comments&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; Groovy - I really loved the way Groovy scripts helped code Java applications quickly. I'm going to try them out&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; Grails - Another quick build of a web application. I'm going to try this out too.&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; Castor - Data binding framework : http://www.castor.org/&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; JBoss Seam&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; Spring Roo : http://en.wikipedia.org/wiki/Spring_Roo&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: lime;"&gt;&lt;span style="background-color: black;"&gt;P2:&lt;/span&gt;&lt;/b&gt; Why should one refrain from using Stubs and prefer using XPath for Web service implementation (server side)&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: lime;"&gt;&lt;span style="background-color: black;"&gt;P2:&lt;/span&gt;&lt;/b&gt; Code-first VS contract-first approach for webservices&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; The JSF standard&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: lime;"&gt;&lt;span style="background-color: black;"&gt;P2:&lt;/span&gt;&lt;/b&gt; Distributed transactions - an interesting concepts / field. How about starting here : &lt;a href="http://www.javaworld.com/javaworld/jw-01-2009/jw-01-spring-transactions.html"&gt;Distributed transactions in Spring, with and without XA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: lime;"&gt;&lt;span style="background-color: black;"&gt;P2:&lt;/span&gt;&lt;/b&gt; Java Persistence API : https://glassfish.dev.java.net/downloads/persistence/JavaPersistence.html&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; JDO : http://java.sun.com/jdo/&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: lime;"&gt;&lt;span style="background-color: black;"&gt;P2:&lt;/span&gt;&lt;/b&gt; JSR-250 Common Annotation&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: blue;"&gt;&lt;span style="background-color: black; color: orange;"&gt;P1:&lt;/span&gt;&lt;/b&gt; Introduction to Algorithms @ MIT Open Courseware - http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/CourseHome/index.htm&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; A course / reading on OOAD, Systems Analysis, Design&lt;/li&gt;
&lt;li&gt;&lt;b style="background-color: white; color: red;"&gt;&lt;span style="background-color: black;"&gt;P?:&lt;/span&gt;&lt;/b&gt; Machine Learning Modeling Algo : Linear CRF - What? How?&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;.... (To be continued...)</content><link href="http://madhurtanwani.blogspot.com/feeds/6550999242213983848/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/6550999242213983848" rel="replies" title="0 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/6550999242213983848" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/6550999242213983848" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2009/11/things-to-do.html" rel="alternate" title="Things To Do..." type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-8361462861592981350</id><published>2009-09-06T16:05:00.003+05:30</published><updated>2009-09-07T23:55:03.052+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="microsoft"/><category scheme="http://www.blogger.com/atom/ns#" term="problem solving"/><category scheme="http://www.blogger.com/atom/ns#" term="riddle"/><category scheme="http://www.blogger.com/atom/ns#" term="walk the bridge"/><title type="text">Walk the bridge, in pairs as fast a possible</title><content type="html">There are 4 women who want to cross a bridge. They all begin on the same side.                  There is one flashlight. A maximum of two people can cross at one time. It is night. Any                  party who crosses, either 1 or 2 people, must have the flashlight with them.                  The flashlight must be walked back and forth, it cannot be thrown, etc. Each                  woman walks at a different speed. A pair must walk together at the rate of the                  slower woman's pace.                 &lt;br /&gt;
Woman 1: 1 minute to cross                     &lt;br /&gt;
Woman 2: 2 minutes to cross                     &lt;br /&gt;
Woman 3: 5 minutes to cross                     &lt;br /&gt;
Woman 4: 10 minutes to cross                     &lt;br /&gt;
&lt;br /&gt;
For example if Woman 1 and Woman 4 walk across first, 10 minutes have elapsed                      when they get to the other side of the bridge. If Woman 4 then returns with the                      flashlight, a total of 20 minutes have passed and you have failed the mission.</content><link href="http://madhurtanwani.blogspot.com/feeds/8361462861592981350/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/8361462861592981350" rel="replies" title="3 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/8361462861592981350" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/8361462861592981350" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2009/09/walk-bridge-in-paris-as-fast-possible.html" rel="alternate" title="Walk the bridge, in pairs as fast a possible" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-8443566051941938916</id><published>2009-09-06T15:55:00.002+05:30</published><updated>2010-04-20T17:42:57.997+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="microsoft"/><category scheme="http://www.blogger.com/atom/ns#" term="odd man out"/><category scheme="http://www.blogger.com/atom/ns#" term="problem solving"/><category scheme="http://www.blogger.com/atom/ns#" term="riddle"/><title type="text">Find jar with the contaminated pills</title><content type="html">You have 4 jars of pills. Each pill is a certain weight, except for                  contaminated pills contained in one jar, where each pill is weight + 1. How                  could you tell which jar had the contaminated pills in just one measurement?&lt;br /&gt;
&lt;br /&gt;
Source : &lt;a href="http://www.sellsbrothers.com/fun/msiview/default.aspx?content=question.htm"&gt;http://www.sellsbrothers.com/fun/msiview/default.aspx?content=question.htm&lt;/a&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/8443566051941938916/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/8443566051941938916" rel="replies" title="1 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/8443566051941938916" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/8443566051941938916" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2009/09/find-jar-with-contaminated-pills.html" rel="alternate" title="Find jar with the contaminated pills" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14074542.post-7660944891087640445</id><published>2009-09-05T23:46:00.003+05:30</published><updated>2010-04-20T17:42:58.002+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="array"/><category scheme="http://www.blogger.com/atom/ns#" term="interview question"/><category scheme="http://www.blogger.com/atom/ns#" term="problem solving"/><category scheme="http://www.blogger.com/atom/ns#" term="repeating"/><title type="text">Algorithms from "100 Interview Questions for Software Developers" : Part 3</title><content type="html">&lt;span style="font-size: x-large;"&gt;Find repeating element in array&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I felt this&amp;nbsp; question deserves a post of its own. So here it is :&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Q5. In an array from 1 to n, one number is present twice. How to do you determine which one?&lt;br /&gt;
&lt;br /&gt;
There are multiple answers - all correct. We would, obviously, aim for the optimized one - benchmark parameters being time &amp;amp; space complexity&lt;br /&gt;
&lt;br /&gt;
Source : &lt;a href="http://www.noop.nl/2009/01/100-interview-questions-for-software-developers.html"&gt;Algorithms from 100 Interview Questions for Software Developers&lt;/a&gt;</content><link href="http://madhurtanwani.blogspot.com/feeds/7660944891087640445/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="http://www.blogger.com/comment/fullpage/post/14074542/7660944891087640445" rel="replies" title="10 Comments" type="text/html"/><link href="http://www.blogger.com/feeds/14074542/posts/default/7660944891087640445" rel="edit" type="application/atom+xml"/><link href="http://www.blogger.com/feeds/14074542/posts/default/7660944891087640445" rel="self" type="application/atom+xml"/><link href="http://madhurtanwani.blogspot.com/2009/09/algorithms-from-100-interview-questions_05.html" rel="alternate" title="Algorithms from &quot;100 Interview Questions for Software Developers&quot; : Part 3" type="text/html"/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05009478527695401190</uri><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>10</thr:total></entry></feed>