<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6420322864018902279</id><updated>2012-02-16T03:12:28.701-08:00</updated><category term='computer science'/><category term='URL Matcher'/><category term='Constructor'/><category term='Firefox'/><category term='Javascript'/><category term='Multithreaded'/><category term='Regular Expressions'/><category term='Information Retrieval'/><category term='Singleton'/><category term='Class Hierarchy'/><category term='graph'/><category term='philosophy'/><category term='__proto__'/><category term='Java'/><category term='Addons'/><category term='prototype'/><category term='Functions'/><category term='Inheritance'/><title type='text'>trash of a luring machine</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-7530254460717589660</id><published>2011-06-21T22:23:00.000-07:00</published><updated>2011-08-02T08:05:35.089-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='graph'/><category scheme='http://www.blogger.com/atom/ns#' term='computer science'/><title type='text'>Implementation of undirected graph in java</title><content type='html'>A minimal implementation of undirected graph in Java :&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.util.Collections;&lt;br /&gt;import java.util.HashMap;&lt;br /&gt;import java.util.HashSet;&lt;br /&gt;import java.util.Iterator;&lt;br /&gt;import java.util.Map;&lt;br /&gt;import java.util.NoSuchElementException;&lt;br /&gt;import java.util.Set;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @author Narendra Yadala&lt;br /&gt; * Implementation of undirected graph represented using adjacency list.&lt;br /&gt; */&lt;br /&gt;public final class UndirectedGraph&amp;lt;T&gt; implements Iterable&amp;lt;T&gt;{&lt;br /&gt; private final Map&amp;lt;T, Set&amp;lt;T&gt;&gt; graph = new HashMap&amp;lt;T, Set&amp;lt;T&gt;&gt;();&lt;br /&gt;&lt;br /&gt; public boolean addNode(T node) {&lt;br /&gt;  if (graph.containsKey(node))&lt;br /&gt;   return false;&lt;br /&gt;&lt;br /&gt;  graph.put(node, new HashSet&amp;lt;T&gt;());&lt;br /&gt;  return true;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void addEdge(T start, T dest) {&lt;br /&gt;  if (!graph.containsKey(start) || !graph.containsKey(dest))&lt;br /&gt;   throw new NoSuchElementException("Nodes must be in the graph.");&lt;br /&gt;  &lt;br /&gt;  graph.get(start).add(dest);&lt;br /&gt;  graph.get(dest).add(start);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void removeEdge(T start, T dest) {&lt;br /&gt;  if (!graph.containsKey(start) || !graph.containsKey(dest))&lt;br /&gt;   throw new NoSuchElementException("Nodes must be in the graph.");&lt;br /&gt;&lt;br /&gt;  graph.get(start).remove(dest);&lt;br /&gt;  graph.get(dest).remove(start);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public boolean isEdgeExists(T start, T end) {&lt;br /&gt;  if (!graph.containsKey(start) || !graph.containsKey(end))&lt;br /&gt;   throw new NoSuchElementException("Nodes must be in the graph.");&lt;br /&gt;&lt;br /&gt;  return graph.get(start).contains(end);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Set&amp;lt;T&gt; getNeighbors(T node) {&lt;br /&gt;  Set&amp;lt;T&gt; neighbors = graph.get(node);&lt;br /&gt;  if (neighbors == null)&lt;br /&gt;   throw new NoSuchElementException("Node does not exist.");&lt;br /&gt;&lt;br /&gt;  return Collections.unmodifiableSet(neighbors);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Iterator&amp;lt;T&gt; iterator() {&lt;br /&gt;  return graph.keySet().iterator();&lt;br /&gt; }&lt;br /&gt; public Iterable&amp;lt;T&gt; getNodes() {&lt;br /&gt;  return graph.keySet();&lt;br /&gt; }&lt;br /&gt; public int size() {&lt;br /&gt;  return graph.size();&lt;br /&gt; }&lt;br /&gt; public boolean isEmpty() {&lt;br /&gt;  return graph.isEmpty();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-7530254460717589660?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/7530254460717589660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=7530254460717589660' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/7530254460717589660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/7530254460717589660'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2011/06/simple-implementation-of-undirected.html' title='Implementation of undirected graph in java'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-4452942503212393244</id><published>2011-04-26T04:43:00.000-07:00</published><updated>2011-04-28T02:37:34.441-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Inheritance'/><category scheme='http://www.blogger.com/atom/ns#' term='__proto__'/><category scheme='http://www.blogger.com/atom/ns#' term='prototype'/><title type='text'>Inheritance in Javascript</title><content type='html'>Javascript does not provide inheritance as a built-in feature like Java/C++ but it can be easily programmed by using the prototype property of an object.  &lt;br /&gt;&lt;br /&gt;Every Javascript object has two internal properties 'constructor' and '__proto__'. For this post I will just confine to '__proto__' property as it is more instrumental in understanding the prototypal inheritance provided by Javascript. Also, the constructor property is quite confusing and demands an entire post for itself.&lt;br /&gt;&lt;br /&gt;Let us see what happens when we create an object invoking new operator on a function.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var Animal = function() { this.eat = function(){console.log('EATING')} }&lt;br /&gt;Animal.prototype = { sleep : function(){console.log('SLEEPING')} }&lt;br /&gt;&lt;br /&gt;animal = new Animal();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The __proto__ property of animal object is set from the prototype property of Animal constructor function. That is why the statement animal.__proto__ == Animal.prototype returns true. When we call animal.sleep function the interpreter checks if the animal object has its own property 'sleep' and if it does not, then it searches for 'sleep' property in animal.__proto__ object. &lt;br /&gt;&lt;br /&gt;Similarly when we call animal.toString() method, then it checks for toString property inside animal object and finds nothing there. Then it goes ahead and checks in animal.__proto__ object and finds nothing there. It does not stop there and checks for toString property in animal.__proto__.__proto__ object which points to Object.prototype object. It finally finds the toString property there and then executes it. And, since the Animal object did not override the toString method of Object object we get the raw output "[object Object]".&lt;br /&gt; &lt;br /&gt;This form of chaining of prototypes forms the basis of inheritance in Javascript. Let us create a Dog object to see how we can create a inheritance hierarchy :&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var Dog = function(){this.bark = function(){console.log('BARKING')}}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Dog is an animal so it needs to inherit from Animal. All we need for this is to set the prototype of the Dog object to point to an Animal object : &lt;br /&gt;&lt;pre&gt;&lt;span style="font-weight:bold;"&gt; Dog.prototype = new Animal(); &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Above statement sets Dog.prototype.__proto__ to Animal.prototype which is what we wanted. We now instantiate dog objects using the Dog function we created.&lt;br /&gt;&lt;pre&gt;dog = new Dog();&lt;/pre&gt;&lt;br /&gt;We can now call dog.bark() , dog.sleep(), dog.eat() and dog.toString() seamlessly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-4452942503212393244?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/4452942503212393244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=4452942503212393244' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/4452942503212393244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/4452942503212393244'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2011/04/inheritance-in-javascript.html' title='Inheritance in Javascript'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-7829066144054667170</id><published>2011-03-31T04:04:00.000-07:00</published><updated>2011-03-31T06:40:50.762-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Functions'/><title type='text'>Functions in Javascript</title><content type='html'>In Javascript functions are &lt;a href="http://en.wikipedia.org/wiki/First-class_object"&gt;first-class objects&lt;/a&gt;. &lt;br /&gt;&lt;blockquote&gt;In computing, a first-class object (also value, entity, and citizen), in the context of a particular programming language, is an entity that can be passed as a parameter, returned from a subroutine, or assigned into a variable.&lt;/blockquote&gt; &lt;br /&gt;This means that Javascript can support functional programming constructs such as anonymous functions, higher order functions, nested functions, closures, currying etc.&lt;br /&gt;&lt;br /&gt;This is best understood through an example :&lt;br /&gt;function sum(a,b) {return a+b}&lt;br /&gt;function incrementer(a) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;return function(b) { //here we are returning a function and also &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//creating an anonymous function&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return sum(a,b); //here we are using closure by &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//referring to local variable a of the incrementer function&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;var incrementBy1 = incrementer(1);&lt;br /&gt;incrementBy1(10); //returns 11&lt;br /&gt;var incrementBy2 = incrementer(2);&lt;br /&gt;incrementBy2(10); //returns 12&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-7829066144054667170?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/7829066144054667170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=7829066144054667170' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/7829066144054667170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/7829066144054667170'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2011/03/functions-in-javascript.html' title='Functions in Javascript'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-3167364891185236875</id><published>2011-02-25T01:09:00.000-08:00</published><updated>2011-03-01T09:52:44.370-08:00</updated><title type='text'>Tweetify Plain Text</title><content type='html'>When we use twitter API to retrieve the tweets, it gives us the plain text that has to be converted into proper html so that they are rendered to web user in a more usable fashion. For this we need to do three tasks :&lt;br /&gt;1. Replace plain text urls to anchor tags pointing to those urls.&lt;br /&gt;2. Replace @username with proper anchor tags pointing to their twitter accounts.&lt;br /&gt;3. Replace #topic with anchor tags pointing to twitter search api.&lt;br /&gt;&lt;br /&gt;This is the javascript needed to convert a tweet in plain text to that containing proper links, hashtags and @ operators. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function tweetify(text) {&lt;br /&gt;    text = text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0- 9.\-]+[.][a-z]{2,4}\/)(?:(?:[^\s()&lt;&gt;.]+[.]?)+|\((?:[^\s()&lt;&gt;]+|(?:\([^\s()&lt;&gt;]+\)))*\))+(?:\((?:[^\s()&lt;&gt;]+|(?:\([^\s()&lt;&gt;]+\)))*\)|[^\s`!()\[\]{};:'".,&lt;&gt;?«»“”‘’]))/gi, "&amp;lt;a target=_blank href=$1&gt;$1&amp;lt;/a&gt;");&lt;br /&gt;    text = text.replace(/[\@]+([A-Za-z0-9-_]+)/gi, "&amp;lt;a target=_blank href=http://twitter.com/$1&gt;@$1&amp;lt;/a&gt;");&lt;br /&gt;    return text.replace(/(?:^| )[\#]+([A-Za-z0-9-_]+)/gi, "&amp;lt;a target=_blank href=http://search.twitter.com/search?q=&amp;tag=$1&amp;lang=all&gt;#$1&amp;lt;/a&gt;");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-3167364891185236875?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/3167364891185236875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=3167364891185236875' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/3167364891185236875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/3167364891185236875'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2011/02/tweetify-plain-text.html' title='Tweetify Plain Text'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-1813101017732612446</id><published>2011-02-24T03:25:00.000-08:00</published><updated>2011-04-29T04:17:24.003-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><category scheme='http://www.blogger.com/atom/ns#' term='URL Matcher'/><title type='text'>Regular Expressions</title><content type='html'>In programming languages one generally comes across a situation where one needs to match input text against a pattern. I will quickly summarize the basic terminology involving the use of regular expressions.&lt;br /&gt;1. Input text&lt;br /&gt;2. Regular expression - this is also called the search pattern, there is a whole lot of syntax on how to construct this pattern which can be found here ( &lt;a href="http://www.regular-expressions.info/reference.html"&gt;Regular Expression Reference&lt;/a&gt;)&lt;br /&gt;3. Regular expression engine - this is the program that basically matches the regular expression occurring in the input text, and then it can do several operations on the matches that are found such as replacing it with some other text. So this can be thought of as consisting of two main components : a matcher and a replacer&lt;br /&gt;4. Match - the text in the input text that complies exactly to the specification of the regular expression. &lt;br/&gt;&lt;br /&gt;I will take a regex I recently modified (&lt;a href="http://daringfireball.net/2010/07/improved_regex_for_matching_urls"&gt;Original regex&lt;/a&gt;) to explain the concepts involved. This regex basically matches the url inside input text. I was working on showing tweets on a page and I needed to replace the plain URL text inside the tweet with html anchor tag pointing to the the plain URL text. &lt;br/&gt;&lt;br /&gt;Here I am using javascript regex syntax to show how one can use this regex to convert text 'This is the URL of current webpage http://wearmyhat.blogspot.com' to 'This is the URL of current webpage &lt; a href="http://wearmyhat.blogspot.com"&gt;http://wearmyhat.blogspot.com&lt; / a&gt;'&lt;br /&gt;I marked the modification I did in bold..this is a slight modification to avoid matching the ellipsis that occurs after the actual URL text. For example original regex was matching the ellipsis occuring after the following URL http://wearmyhat.blogspot.com... This was not really acceptable to my application.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Modified Regex:&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;text = text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:&lt;span style="font-weight:bold;"&gt;(?:[^\s()&lt;&gt;.]+[.]?)+&lt;/span&gt;|\((?:[^\s()&lt;&gt;]+|(?:\([^\s()&lt;&gt;]+\)))*\))+(?:\((?:[^\s()&lt;&gt;]+|(?:\([^\s()&lt;&gt;]+\)))*\)|[^\s`!()\[\]{};:'".,&lt;&gt;?«»“”‘’]))/gi, "&amp;lt;a target=_blank href=$1&gt;$1&amp;lt;/a&gt;");&lt;/blockquote&gt;&lt;br /&gt;What I am going to do is take the main constructs that are used in this regex in order and explain them one by one.&lt;br /&gt;1. \b Matches character between word and non-word character..in other words matches starting or ending character of a word.&lt;br /&gt;2. () Capturing group [whatever is inside is captured by the matcher in entirety]. The above regex has only one outer capturing group with multiple non-capturing groups placed inside. These groups are the only groups that can be backreferenced.&lt;br /&gt;3. (?:) Non-capturing group [whatever is inside is not captured by the matcher in entirety]. This also means that these groups are not available for backreferencing purpose. Any number of capturing groups inside a non-capturing group are treated as capturing groups by the Regex engine (which is actually non-intuitive).&lt;br /&gt;4. [\w] matches a word character.&lt;br /&gt;5. [^\s] matches a non-space character, [a-z] matches any character between a to z.&lt;br /&gt;6. /{1,3} forward slash 1-3 times, \d{0,3} a digit 0-3 times, [a-z]{2-4} any character between a to z can occur 2-4 times.&lt;br /&gt;7. My change : ([^\s()&lt;&gt;.]+[.]?)+ and the corresponding group in original regex is [^\s()&lt;&gt;]+ &lt;br /&gt;Here I force '.' to occur only once at a time in the input text.&lt;br /&gt;8. $1 This is needed to backreference a captured group which is needed to construct the anchor tag properly.&lt;br /&gt;9. + means preceding expression can once or more, ? means preceding expression can occur 0 or 1 times, * means preceding expression can occur 0 or more times. These are called the quantifiers.&lt;br /&gt;10. g and i in the end indicate the javascript syntax to match globally and in a case insensitive manner.&lt;br /&gt;11. The second parameter of the replace function is the string that will replace the match found by the regex engine. We replace every url with an anchor tag pointing to that url.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-1813101017732612446?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/1813101017732612446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=1813101017732612446' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/1813101017732612446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/1813101017732612446'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2011/02/regular-expressions.html' title='Regular Expressions'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-8698423449612330506</id><published>2008-07-01T11:57:00.000-07:00</published><updated>2011-02-25T02:44:14.479-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='philosophy'/><title type='text'>On the nature of things (By Lucretius 94-55BC)</title><content type='html'>Lovely it is, when the winds are churning up the waves on the great sea, to gaze out from the land on the great efforts of someone else; not because it's an enjoyable pleasure that somebody is in difficulties, but it's lovely to realize what troubles you are yourself spared..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-8698423449612330506?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/8698423449612330506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=8698423449612330506' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/8698423449612330506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/8698423449612330506'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/07/on-nature-of-things-by-lucretius-94.html' title='On the nature of things (By Lucretius 94-55BC)'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-5234817844148519374</id><published>2008-06-18T21:37:00.000-07:00</published><updated>2011-02-25T02:44:14.480-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='philosophy'/><title type='text'>A nice haiku from FightClub</title><content type='html'>worker bees can leave&lt;br /&gt;even drones can fly away&lt;br /&gt;the queen is their slave&lt;br /&gt;                - Fight Club&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-5234817844148519374?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/5234817844148519374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=5234817844148519374' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/5234817844148519374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/5234817844148519374'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/06/nice-haiku-from-fightclub.html' title='A nice haiku from FightClub'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-4283212860826868848</id><published>2008-06-18T21:14:00.001-07:00</published><updated>2011-03-11T21:30:38.196-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='philosophy'/><title type='text'>Completeness in Incompleteness</title><content type='html'>Everyday reminds me of my Incompleteness.&lt;br /&gt;The more I try to complete it, the more incomplete it gets.&lt;br /&gt;But I try and try and try,&lt;br /&gt;Only to realize that the Incompleteness is just a part of my Completeness.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-4283212860826868848?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/4283212860826868848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=4283212860826868848' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/4283212860826868848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/4283212860826868848'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/06/completeness-in-incompleteness.html' title='Completeness in Incompleteness'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-7096130092609623936</id><published>2008-06-10T09:23:00.000-07:00</published><updated>2011-02-23T21:44:34.688-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Forward Referencing</title><content type='html'>The following notes are taken from Java Language Specification in reference to forward referencing of variables. &lt;br/&gt;&lt;br /&gt;The declaration of a member needs to appear before it is used only if the member is an instance (respectively static) field of a class or interface C and all of the following conditions hold:&lt;br /&gt;1. The usage occurs in an instance (respectively static) variable initializer of C &lt;br /&gt;   or in an instance (respectively static) initializer of C. &lt;br /&gt;2. The usage is not on the left hand side of an assignment. &lt;br /&gt;3. C is the innermost class or interface enclosing the usage. &lt;br /&gt;Example where it needs to be taken care of&lt;br /&gt;&lt;br /&gt;public class ForwardReference&lt;br /&gt;{&lt;br /&gt;    int j = i;&lt;br /&gt;    int i = 10;&lt;br /&gt;}&lt;br /&gt;Here in this example all the above three conditions are met because i is used in the instance variable initializer, i is not on the left hand side of the assignment and the usage of i belongs to the ForwardRef which is the innermost class holding the variable i.&lt;br /&gt;&lt;br /&gt;Examples where it need not be taken care of:&lt;br /&gt;&lt;br /&gt;Example1:&lt;br /&gt;public class ForwardRef&lt;br /&gt;{&lt;br /&gt;    int j;&lt;br /&gt;    &lt;br /&gt;    ForwardReference()&lt;br /&gt;    {&lt;br /&gt;        j = i;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    int i = 5;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Here the usage is in the constructor and not in instance varialble initializer or instance initializer so the first rule is violated.&lt;br /&gt;&lt;br /&gt;Example2:&lt;br /&gt;public class ForwardReference&lt;br /&gt;{&lt;br /&gt;    {&lt;br /&gt;        i = 9;&lt;br /&gt;    }&lt;br /&gt;    int i = 8;&lt;br /&gt;}&lt;br /&gt;Here second rule specified in JLS is violated, so we need not worry about it appearing before it is defined. We should be worried if i is used on the right hand side of the assignment.&lt;br /&gt;&lt;br /&gt;Example3:&lt;br /&gt;public class ForwardReference&lt;br /&gt;{&lt;br /&gt;    class InnerForwardRef&lt;br /&gt;    {&lt;br /&gt;        int j = i;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    int i = 5;&lt;br /&gt;}&lt;br /&gt;Here the usage of i is in a inner class so the third rule is violated, so the compiler will not create a problem for this.&lt;br /&gt;&lt;br /&gt;Now we come to a very strange example where forward referencing is allowed..&lt;br /&gt;public class X&lt;br /&gt;{&lt;br /&gt;  private static int x = getValue();&lt;br /&gt;  private static int y = 5;&lt;br /&gt;  &lt;br /&gt;  private static int getValue()&lt;br /&gt;  {&lt;br /&gt;     return y;&lt;br /&gt;  }&lt;br /&gt;  public static void main(String args [])&lt;br /&gt;  {&lt;br /&gt;    System.out.print(x);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The code above prints..zero which is quite weird in fact. Here the compiler is tricked making it think that it is a valid forward reference.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-7096130092609623936?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/7096130092609623936/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=7096130092609623936' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/7096130092609623936'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/7096130092609623936'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/06/forward-referencing.html' title='Forward Referencing'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-1468379125036761164</id><published>2008-05-26T10:36:00.000-07:00</published><updated>2011-04-26T06:24:57.097-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Daemon threads in Java</title><content type='html'>Threads that work in the background to support the runtime environment are called daemon threads. For example, the clock handler thread, the idle thread, the screen updater thread, and the garbage collector thread are all daemon threads. The virtual machine exits whenever all non-daemon threads have completed.&lt;br /&gt;&lt;br /&gt;  public final void    setDaemon(boolean isDaemon)&lt;br /&gt;  public final boolean isDaemon()&lt;br /&gt;&lt;br /&gt;By default a thread you create is not a daemon thread. All the user applications are generally started off as non-daemon threads. However you can use the setDaemon(true) method to turn it into one.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-1468379125036761164?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/1468379125036761164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=1468379125036761164' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/1468379125036761164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/1468379125036761164'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/05/daemon-threads.html' title='Daemon threads in Java'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-1411556693834103477</id><published>2008-05-22T09:05:00.000-07:00</published><updated>2010-01-17T12:21:01.804-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Covariant return type</title><content type='html'>A covariant return type means changing a method's return type when overriding it in a subclass. Covariant return types were allowed in the Java language since the release of JDK5.0. I will try to illustrate the use of covariant return type using the following example.&lt;br /&gt;&lt;br /&gt;class A&lt;br /&gt;{&lt;br /&gt;public List test()&lt;br /&gt;{&lt;br /&gt;return null;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class B extends A&lt;br /&gt;{&lt;br /&gt;public ArrayList test()&lt;br /&gt;{&lt;br /&gt;return new ArrayList();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Here we can see that the return type of the method test() in subclass B is the subclass of the return type of method test() in the superclass A.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-1411556693834103477?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/1411556693834103477/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=1411556693834103477' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/1411556693834103477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/1411556693834103477'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/05/covariant-return-type.html' title='Covariant return type'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-283184730162119285</id><published>2008-05-21T22:00:00.000-07:00</published><updated>2011-02-23T22:13:17.976-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Contract between the subclass and superclass</title><content type='html'>The following is an excerpt from the book 'The Java FAQ' .. "An API (application programming interface) establishes a contract of intent, not just of form or interpretation. To borrow terminology from linguistics and philosophy, an API contract involves both extension and intension: the boundaries of the current state of the world (extension) as well as the intended boundaries for other possible states of the world (intension: possible future implementations). In object-oriented programming, a common source of "possible future implementations" is subclassing from an existing class in an API.&lt;br /&gt;     A method defines a contract for any subclass method that would override it; it constrains possible implementations that a subclass could provide. In Java, the bare minimum contract for a method's inputs and outputs is the following:&lt;br /&gt;&lt;br /&gt;    * A method's parameter list is fixed; an overriding method in a subclass must declare precisely the same number and types of arguments.&lt;br /&gt;    * A method's return type is fixed; an overriding method in a subclass must declare precisely the same return type.&lt;br /&gt;    * The set of checked exceptions a method can throw (the method's declared exception classes and all their subclasses) establishes an upper bound. An overriding method in a subclass cannot throw any checked exceptions outside of that; it can, however, throw fewer exception types, or even none at all.&lt;br /&gt;&lt;br /&gt;Note that the contract on exceptions concerns only checked exceptions; errors and runtime exceptions (that is, Error, RuntimeException, and their subclasses) are always permitted.&lt;br /&gt;     If a method, such as Object's toString method, is declared as throwing no checked exceptions, any overriding method you define must live within those bounds. You cannot define your own subclass of Exception and have your toString method throw that. In such a case, if you really need some exception to be thrown, you can resort to a subclass of RuntimeException, which is not checked or constrained by the compiler."&lt;br /&gt;&lt;br /&gt;This description basically covers all the rules that a subclass must follow when overriding a method from superclass.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-283184730162119285?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/283184730162119285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=283184730162119285' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/283184730162119285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/283184730162119285'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/05/contract-between-subclass-and.html' title='Contract between the subclass and superclass'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-3690893864770050246</id><published>2008-05-20T11:40:00.000-07:00</published><updated>2010-01-17T12:21:01.842-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Constructor'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Class Hierarchy'/><title type='text'>What does a constructor do?</title><content type='html'>The constructor helps initializing the state of the object. So initially the implicit or the defined no-argument constructor of the super class is called so that the parent gets initialized in a proper manner.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;One more restriction that is being imposed when a constructor is being defined is that call to any explicit super class constructor must be the first statement of all the constructors. So this might sound like a weird restriction at first but this rule guarantees the parent object to be in a valid state before the child object gets operational. This would help in avoiding the situations like this :&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;class Date{&lt;br /&gt;public Date(){ date = setDate... }&lt;br /&gt;String date;&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;// what if?&lt;br /&gt;class DateViewer extends Date{&lt;br /&gt;public DateViewer(){&lt;br /&gt;System.out.println("The Date: " + date);&lt;br /&gt;super();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Another thing that must be kept in mind while dealing with the constructors is that once you define a non-default constructor with non-zero arguments then and there the implicit constructor's definition inserted is removed from the code. So now if you have two classes X and Y such that &lt;br /&gt;class Y &lt;br /&gt;{&lt;br /&gt;Y(int x,int y)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class X extends Y&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now this will result in a compilation error in the class X..Because the JVM tries to call the super() method while initializing the child object but since there is not implicit constructor for the parent class, this results in a error. Also see this amusing thread on sun forum:&lt;br/&gt;&lt;br /&gt;http://forum.java.sun.com/thread.jspa?threadID=731805&amp;start=0&amp;tstart=0&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-3690893864770050246?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/3690893864770050246/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=3690893864770050246' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/3690893864770050246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/3690893864770050246'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/05/what-does-constructor-do.html' title='What does a constructor do?'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-3642207456978181681</id><published>2008-05-13T19:05:00.000-07:00</published><updated>2011-03-11T21:32:00.450-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>About null in Java</title><content type='html'>In Java(tm), "null" is not a keyword, but a special literal of the null type. It can be cast to any reference type, but not to any primitive type such as int or boolean. The null literal doesn't necessarily have value zero. And it is impossible to cast to the null type or declare a variable of this type.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-3642207456978181681?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/3642207456978181681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=3642207456978181681' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/3642207456978181681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/3642207456978181681'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/05/about-null-in-java.html' title='About null in Java'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-2752731849971410008</id><published>2008-05-09T23:25:00.000-07:00</published><updated>2011-07-08T12:43:42.705-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Multithreaded'/><category scheme='http://www.blogger.com/atom/ns#' term='Singleton'/><title type='text'>Implementation of a multithreaded singleton in Java</title><content type='html'>&lt;pre&gt;&lt;br /&gt;package yn.graph;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @author ny&lt;br /&gt; * &lt;br /&gt; */&lt;br /&gt;public class MultithreadedSingleton {&lt;br /&gt; private static final MultithreadedSingleton singleton = new MultithreadedSingleton();&lt;br /&gt; &lt;br /&gt; private MultithreadedSingleton() {&lt;br /&gt;  synchronized (MultithreadedSingleton.class) {&lt;br /&gt;   //initialize the variables   &lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static MultithreadedSingleton getSingleton() {&lt;br /&gt;  return singleton;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private static class TestMultithreadedSingleton implements Runnable {&lt;br /&gt;  @Override&lt;br /&gt;  public void run() {&lt;br /&gt;   MultithreadedSingleton sgt = getSingleton();&lt;br /&gt;   System.out.println(sgt);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  */&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  new Thread(new TestMultithreadedSingleton()).start();&lt;br /&gt;  new Thread(new TestMultithreadedSingleton()).start();&lt;br /&gt;  new Thread(new TestMultithreadedSingleton()).start();&lt;br /&gt;  new Thread(new TestMultithreadedSingleton()).start();&lt;br /&gt;  new Thread(new TestMultithreadedSingleton()).start();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-2752731849971410008?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/2752731849971410008/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=2752731849971410008' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/2752731849971410008'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/2752731849971410008'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/05/implementation-of-multithreaded.html' title='Implementation of a multithreaded singleton in Java'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-4058309292992108041</id><published>2008-04-21T13:22:00.000-07:00</published><updated>2010-01-17T12:21:01.828-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Does Java pass by reference or pass by value?</title><content type='html'>A compact answer to this question will be &lt;br/&gt;&lt;br /&gt;&lt;b&gt;"Java passes the reference of the object by value"&lt;/b&gt;.&lt;br /&gt;So what does it mean to pass the reference of the object by value.&lt;br /&gt;It means that if an object is passed to a method, then the object itself can be altered but not its reference. Because the reference of the object is passed by value. For example consider a object O and let the reference of the object O be x. Now when you pass the object O to a method, the VM internally makes a copy of x, that means there is another reference y which points to the same location as x does. &lt;br/&gt;But x &gt;&lt; y. Now this means whenever you pass a object to a method, the object has atleast two references. Thus objects in java can be altered by passing to a method but they cannot be swapped with another object or assigned to some other object or something like that.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-4058309292992108041?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/4058309292992108041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=4058309292992108041' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/4058309292992108041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/4058309292992108041'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/04/does-java-pass-by-reference-or-pass-by.html' title='Does Java pass by reference or pass by value?'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-3980619269829623735</id><published>2008-04-03T16:13:00.000-07:00</published><updated>2011-03-11T21:26:59.757-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Addons'/><category scheme='http://www.blogger.com/atom/ns#' term='Firefox'/><title type='text'>Useful Firefox Addons</title><content type='html'>Here I would like to mention some of the Addons to Firefox that I find very useful.&lt;br /&gt;1. Many of the people would like to restore their browser session once they boot their personal computer. So that they need not open each and every tab once they start their browser. There are session restoring features in Firefox but they are not upto the mark. So the best session restoring addon according to me is Tab Mix Plus and it can be found at the &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/1122"&gt;Tab Mix Plus&lt;/a&gt;&lt;br /&gt;2. For those who are into web development there are two addons that I wud like to suggest. The first and the most notable addon being firebug. This addon is available at the &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/1843"&gt;Firebug&lt;/a&gt;&lt;br /&gt;This addon has a long list of features. But I would like to point out my favorite features. First being the inspect element feature that will enable you to see the html source of any element that you want to locate. For this you need to right click on the element and select the Inspect Element option. Now many people want to look at the contents of the response that has come back and also check whether the request made is proper or not. For this you need to select the Net tab of firebug and then inspect the contents of request and response. One can also view the contents of the XHRs that are being made. Viewing the contents of XHR is a pretty nifty feature of Firebug.&lt;br /&gt;The second addon that is not very popular being Web Developer. This is at the &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/60"&gt;Web Developer&lt;/a&gt;. The feature of this addon which is not present as it is in Fire Bug being the View Layout option. This option enables one to view the layout of the page properly. Fire Bug also has this option but not as sophisticated as Web Developer.&lt;br /&gt;3. The third addon being the stumble upon addon which is my favorite addon. Now this addon not only allows you to stumble but also record any pages that you want to record. This is much more useful for me because I visit certain pages and I dont want to loose their pointer at any cost. So as soon as I find any page that needs to be stored I wud mark it as thumbs up. Then later in time I can retrieve the list of pages that I liked and I can easily search for the wanted pages. This addon however is present in the stumble upon home page from where one can obtain and install stumble upon add on.&lt;br /&gt;&lt;br /&gt;   I will be adding to this list as soon as I find any new and useful addons..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-3980619269829623735?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/3980619269829623735/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=3980619269829623735' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/3980619269829623735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/3980619269829623735'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/04/useful-mozilla-addons.html' title='Useful Firefox Addons'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420322864018902279.post-1086144644173164859</id><published>2008-04-01T22:07:00.000-07:00</published><updated>2010-01-17T12:21:01.760-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Information Retrieval'/><title type='text'>Precision Vs Recall</title><content type='html'>In all the applications involving Information Retrieval one of the main concerns would be to balance Precision and Recall parameters. The general application involves a scenario where a query is submitted by the user and the documents that match the query in the corpus are retrieved using some information retrieval model. Well known information retrieval models include &lt;span style="font-style: italic;"&gt;Vector Space model, Latent Semantic Indexing and &lt;/span&gt;several other &lt;span style="font-style: italic;"&gt;Probabilistic &lt;/span&gt;models.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Precision&lt;/span&gt; refers to the ratio --&gt; Number of relevant documents retrieved / Total number of                                                                 retrieved documents.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Recall&lt;/span&gt; refers to the ratio --&gt; Number of relevant documents retrieved / Total number of relevant documents.&lt;br /&gt;&lt;br /&gt;  Now one can observe that Recall will be 1 if one returns all the documents in the corpus but the whole application's performance will be in jeopardy if one returns all the documents in the corpus thus rendering the application useless. On the other extreme is when we return no documents, then the Precision is infinity. But even then the application is unusable because no documents are rendered to the user.&lt;br /&gt;So the balance between precision and recall has to be established in the applications involving the Information Retrieval. Due to the ambiguities in the natural language many irrelevant documents are returned resulting in a text search applications with low precision. One of the main reasons that Google has established its ground as a giant is due to its Page rank algorithm which increases the precision a lot. So while developing the applications one can improve the performance by giving the proper weights to precision and recall as required by the specifications of a particular application.&lt;br /&gt;For example there might be some applications where all the relevant documents need to be displayed irrespective of the total number of the retrieved documents. In this case one needs to give a high weight to the recall parameter while designing the search query.  Commercial search engines require a high degree of precision because the number of web pages (each web page can be viewed as a document and the set of all web pages is the corpus) is in zillions. There are several measures like F1 measure in which precision and recall are evenly weighted.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420322864018902279-1086144644173164859?l=wearmyhat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wearmyhat.blogspot.com/feeds/1086144644173164859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6420322864018902279&amp;postID=1086144644173164859' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/1086144644173164859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420322864018902279/posts/default/1086144644173164859'/><link rel='alternate' type='text/html' href='http://wearmyhat.blogspot.com/2008/04/precision-vs-recall.html' title='Precision Vs Recall'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13825113432615801297</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/-62PAt67wab4/TWX5k43xZKI/AAAAAAAABsM/523IMBrvBHM/s220/133031_468018767333_677227333_5929769_5431149_o.jpg'/></author><thr:total>0</thr:total></entry></feed>
