<?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-29990844</id><updated>2012-02-10T08:53:39.123-08:00</updated><title type='text'>Technicalitee</title><subtitle type='html'>Just a repository of useful technical info i have learnt and learning</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-29990844.post-7201469723296407010</id><published>2012-02-02T09:55:00.001-08:00</published><updated>2012-02-02T10:29:27.584-08:00</updated><title type='text'>sizeof for Java developers...</title><content type='html'>It is a famous interview question, which has been asked to me and i have asked to others. How do you find the size of an Object in Java? I have come across 2 methods earlier, one is the naive method using a List of 1000000 objects and measuring the heap size with Runtime.java and dividing the delta by number of Objects, second way is using &lt;a href="http://marxsoftware.blogspot.in/2011/12/estimating-java-object-sizes-with.html"&gt;instrumentation&lt;/a&gt;. I recently came across a new method of determining object size, it is used internally by Twitter and open sourced under their commons project on &lt;a href="https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/objectsize/ObjectSizeCalculator.java"&gt;Github&lt;/a&gt;. The class provides full functionality for Hotspot VMs which we mostly use in our application systems and without -XX:{+|-}UseCompressedOops option enabled which i suppose most of us dont know it exists before watching &lt;a href="http://www.infoq.com/presentations/JVM-Performance-Tuning-twitter"&gt;this&lt;/a&gt; talk. The talk is given by the same person who wrote this code. It is wonderful talk which details many memory related stuff and is a must watch for all Java developers. Even though we might not face problems like Twitter it is always good to know them. The calculator implementation returns the size of object in bytes and uses reflection based logic combined with visitor pattern to calculate the size of an object. Cyclic reference check is also handled with the help of a IdentityHashMap. I wrote a small test class to see how it works.&lt;script src="https://gist.github.com/1724774.js?file=ObjectSizeCalcTest.java"&gt;&lt;/script&gt;&lt;pre&gt;&lt;br /&gt;Output : &lt;br /&gt;E1 size -&gt; 96&lt;br /&gt;E2 size -&gt; 72&lt;br /&gt;E3 size -&gt; 80&lt;br /&gt;Default list size with e1 and e2 -&gt; 248&lt;br /&gt;Default list size with 2 e1 and 1 e2 -&gt; 248&lt;br /&gt;Default list size with 2 e1,1 e2 and 1 e3 -&gt; 328&lt;br /&gt;Predefined sized list size with 1 e1,1 e2 and 1 e3 -&gt; 304&lt;br /&gt;&lt;/pre&gt;Compared to the naive method which can be inaccurate and hell of configuring instrumentation with preMain() etc. stuff, using this class is dead simple and easy if you have Google Guava in your classpath which i think is mandatory :-). it works only with Guava 11.0.1 and above since the code uses a self loading cache implementation available with Guava. It is available under Apache license and should be reliable since Twitter uses it. If in future i have to crack some memory issue this would definitely be useful...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-7201469723296407010?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/7201469723296407010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=7201469723296407010' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/7201469723296407010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/7201469723296407010'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2012/02/sizeof-for-java-developers.html' title='sizeof for Java developers...'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-9176544838763743937</id><published>2011-12-23T00:54:00.000-08:00</published><updated>2011-12-23T00:55:58.861-08:00</updated><title type='text'>Guava sweetness!</title><content type='html'>If you search for Google Guava in Google you could get a huge number of articles as to why Guava is sweet and the benefits of using it in a Java project irrespective of the problem domain we trying to address. I am not going to reiterate those. Last week i had my own reason to feel happy for using Guava in my project. Rather than a specific problem domain it was a problem of domains. In our application we had a problem of extracting the topmost domain name from a URL host i.e. if the host name is webcache.google.com then i have to extract the top most domain name which is google.com&lt;br&gt;&lt;br&gt;Being a smart-fast developer i am (notice the sarcasm ;-)) i quickly jumped into eclipse to write an awesome algorithm by using split method to separate the hosts as [webcache,google,com] and join the last 2 to get google.com. I did it all in minutes, wrote few unit tests with other .com hosts and checked in the source and lived happily ever after for the next 10 minutes. My colleague came to my place and asked about webcache.google.co.in. I realized that my code would return co.in as the top domain instead of google.co.in. Both of us discussed and came up with the solution of removing the first segment by default so that [webcache,google,co,in] will return google.co.in and dispersed. When i sat to change the code i realized that [google,co,in] as input would return co.in again. Searching through the internet for any predfined algorithms lead me to &lt;a href="http://publicsuffix.org/list/"&gt;this&lt;/a&gt; list of public suffixes maintained by Mozilla which can be used to filter out the topmost domain excluding the public suffix from host string.&lt;br&gt;&lt;br&gt;I decided to write an automated parser which will periodically hit the public list from internet and update the list of suffixes. Suddenly it struck me that this is a general problem and writing a custom solution is not worth it. Since i have already been using Guava for general purpose in my project i started searching Guava for any such functionality of public suffix filtering and found the awesome class &lt;a href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/net/InternetDomainName.html"&gt;InternetDomainName&lt;/a&gt;, this has a method topPrivateDomain() which does what i want i.e. return the top most private domain one level beneath the public suffix. 2 days of my effort saved! And i cannot be sure whether i would have handled all scenarios given the 2 days time. The method looks up an immutable set maintained by &lt;a href="http://guava-libraries.googlecode.com/svn-history/r42/trunk/src/com/google/common/net/TldPatterns.java"&gt;TldPatterns.java&lt;/a&gt; which is class that is auto generated regularly based on latest public suffix with each new release. &lt;br&gt;&lt;br&gt;However there is one downside to the approach that if the public suffix list gets updated this may not reflect immediately. Thought of contributing a patch to guava which would automatically update the patterns, fortunately (for them ;-)) it has already done by &lt;a href="http://code.google.com/p/guava-libraries/issues/detail?id=475&amp;colspec=ID%20Type%20Status%20Package%20Milestone%20Summary"&gt;someone&lt;/a&gt; and has been accepted as an enhancement. I always have my option of decorating InternetDomainName.java with my own class in case if required before this gets into the official release. Yet another reason to smile for having added Guava in a Java project. Wish google releases a separate JDK with Guava integrated. And the lesson learned here is "If you feel you are solving a generic problem look into Guava before jumping to code".......&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-9176544838763743937?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/9176544838763743937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=9176544838763743937' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/9176544838763743937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/9176544838763743937'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/12/guava-sweetness.html' title='Guava sweetness!'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-83514969519021612</id><published>2011-11-10T08:13:00.000-08:00</published><updated>2011-11-10T08:48:24.583-08:00</updated><title type='text'>My programming principles</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;A collection of few best practices and programming principles for Java i have learnt from my experience&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;Use final modifier for almost all variables, especially for instance variables&amp;nbsp;&lt;/li&gt;&lt;li&gt;Never use a instance variable for data passing between two functions, use arguments instead&lt;/li&gt;&lt;li&gt;Follow Single Responsibility Principle for functions i.e. any function should do only task, if it does more than one then break it into multiple functions&amp;nbsp;&lt;/li&gt;&lt;li&gt;If you want to return more than one value from a function use Tuples&amp;nbsp;&lt;/li&gt;&lt;li&gt;Avoid creating custom checked exceptions, all custom exceptions should extend RuntimeException&amp;nbsp;&lt;/li&gt;&lt;li&gt;Wrap checked exceptions that arise from classes that are not in our control within a RuntimeException or its subclass&amp;nbsp;&lt;/li&gt;&lt;li&gt;Instead of creating a Java bean with getter/setters use immutable i.e. final data members with public accesse.g. &lt;pre&gt;public class Pair{&lt;br /&gt;  public final String key;&lt;br /&gt;  public final String value;&lt;br /&gt;&lt;br /&gt;  public Pair(String k, String v){&lt;br /&gt;     key = k;&lt;br /&gt;     value = v&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;is better than&lt;pre&gt;public class Pair{&lt;br /&gt;   private String key;&lt;br /&gt;   private String value;&lt;br /&gt;&lt;br /&gt;   public void setKey(String k){&lt;br /&gt;      key = k;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void setValue(String v){&lt;br /&gt;      value = v;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public String getKey(){&lt;br /&gt;      return key;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public String getValue(){&lt;br /&gt;      return value;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;Use factory methods over constructors e.g.&lt;pre&gt;private Pair(String k, String v){&lt;br /&gt;     key = k;&lt;br /&gt;     value = v&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static Pair of(String k, String v){&lt;br /&gt;   return new Pair(k,v);&lt;br /&gt;}&lt;br /&gt;Usage:-&lt;br /&gt;Pair.of("A","B");&lt;br /&gt;&lt;/pre&gt;is more concise&lt;/li&gt;&lt;li&gt;A method should not have more than 15 lines of code&lt;/li&gt;&lt;li&gt;Decompose the problem into functions rather than classes to the most atomic level, i.e. a function cannot be decomposed further&lt;/li&gt;&lt;li&gt;Good code does not require any comments, code should convey the intent&lt;/li&gt;&lt;li&gt;Premature optimization is the root of all evil - Donlad Knuth. But if you are 100% sure of the performance benefit you can write it at first shot&lt;/li&gt;&lt;li&gt;Always use slf4j for logging instead of Log4j or something else&lt;/li&gt;&lt;li&gt;Search in your classpath jars before writing any generic utility functions, many frameworks already would have them&lt;/li&gt;&lt;li&gt;Use generic utility APIs like Google Guava, Apache commons instead of writing own code&lt;/li&gt;&lt;li&gt;Programming is not about typing, it is about thinking - Rich Hickey, code written after spending sometime thinking about it rather than something written in haste will be beneficial at longer run&lt;/li&gt;&lt;li&gt;Read&lt;a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882"&gt; Clean code&lt;/a&gt; by Uncle Bob&lt;/li&gt;&lt;li&gt;Don't write Unit test cases before writing actual code, those should be used only at later point of time to check any changes does not break the functionality instead of having to test the whole functionality. TDD is not that great!&lt;/li&gt;&lt;li&gt;Watch &lt;a href="http://www.infoq.com/presentations/Simple-Made-Easy"&gt;this &lt;/a&gt;presentation on writing simple systems by Rich Hickey&lt;/li&gt;&lt;li&gt;Do not use static imports for anything else except constants, especially not for methods&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;Disclaimer: These are my personal opinion and does not mean all are correct and also cannot be followed in all situations, this is just an attempt to remind myself of my learnings in the past and for future reference&lt;/b&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-83514969519021612?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/83514969519021612/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=83514969519021612' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/83514969519021612'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/83514969519021612'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/11/my-programming-principles.html' title='My programming principles'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-4005065529898052144</id><published>2011-10-28T07:28:00.000-07:00</published><updated>2011-10-28T07:58:06.435-07:00</updated><title type='text'>Curse of the iframe!</title><content type='html'>Not sure how many of us developers have used iframes in their applications, i am one of the unfortunate few (may be many). I have been working on an application for a social networking site which depends on hidden iframe based ping to our server from the social site. Browsers are worst at handling iframes consistently. Each browser makes their own implementation of the iframe be it security or rendering. &lt;br /&gt;&lt;br /&gt;How would we feel if different vendors implement different JVMs but choose to make the collections behavior different, felt the same while working on iframes. We already had an issue with MS browsers on handling the iframe since the internal ping did not happen due to security settings , i.e. the topmost site was a https while our internal iframe contacted our server in http. This works on all browsers even in Safari but not in IE8+ since MS thinks displaying http content with https is bad which is valid. To fix the issue we placed a patch that will by default ping to our server via https. It worked, we were all happy and deployed the code to production. Soon after we deployed it the issue started reappearing for few users irrespective of the browser. The issue changed its pattern from browser based to user id based like an evolving virus. &lt;br /&gt;&lt;br /&gt;On digging deeper using firebug after 1 day i found that the social networking site has dropped a bomb, yes a new header named &lt;span style="font-weight:bold;"&gt;X-Frame-Options&lt;/span&gt; started appearing for few user ids in the response when we pinged through iframe. The roll out of this header is happening in phased manner and soon all users will face the issue. The request doesn't directly contact out URL but through a proxy url provided by the social networking site. We finally decided to get rid of the scum named iframe completely so that we need not handle all this complications. On reading about &lt;span style="font-weight:bold;"&gt;X-Frame-Options&lt;/span&gt; it is found that it is a new header proposed by MS and implemented by other browsers. If you don't like your site's code to be displayed within a frame then you can send this  header in your response and modern browsers like IE8+, Mozilla 4+ etc. will  not render the content. This might be useful in multiple scenarios when we want our site content not to be displayed in some third party site. I don't want to explain the technical details of this header since it has been done already by the experts.&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;&lt;br /&gt;&lt;a href="https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header"&gt;Mozilla&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blogs.msdn.com/b/ie/archive/2009/01/27/ie8-security-part-vii-clickjacking-defenses.aspx"&gt;MSDN&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.webmasterworld.com/webmaster/4022867.htm"&gt;Webmasterworld&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Two important things i learned from this issue is: &lt;br /&gt;&lt;br /&gt;1. Social networks don't give a shit about their 3rd party developers and apps, they just keep pushing whatever they want without prior information, it is our duty to continuously monitor and adapt accordingly!&lt;br /&gt;&lt;br /&gt;2. There is a need for a separate body to govern browser implementations and regulate the behavior of browsers towards iframe, CSS etc. handling to be consistent&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-4005065529898052144?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/4005065529898052144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=4005065529898052144' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4005065529898052144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4005065529898052144'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/10/curse-of-iframe.html' title='Curse of the iframe!'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-3941464971511742071</id><published>2011-10-03T08:33:00.000-07:00</published><updated>2011-10-03T09:00:25.808-07:00</updated><title type='text'>Caution while using 3rd party Object keys!</title><content type='html'>I am developing a multithreaded application which requires downloading content from multiple websites. The system requires a very high performance characteristic and already runs in 30+ threads. While solving a silly code bug which reduced the performance earlier, I noticed that the threads in the pool are in blocking state for a considerable time while only one thread from the pool is in runnable state. On inspecting the thread dump it lead me to something unexpected since it was waiting on the hashCode() method of URL.java. I had used it as a performance optimization to cache the visited CSS/JS links of a particular site to avoid duplicates. &lt;br /&gt;I didnt care to read the documentation or look into the implementation, all that i saw was whether an equals() and hashCode() was implemented by URL.java and felt happy to use the URL object itself as key to avoid unwanted toString(). &lt;br /&gt;&lt;script src="https://gist.github.com/1259419.js?file=url_hashcode.java"&gt;&lt;/script&gt;&lt;br /&gt;Later after discovering the blockage i went through the hashCode() method of URL.java. It is delegated to java.net.URLStreamHandler.java which calls InetAddress.getByName(host) &lt;br /&gt;&lt;script src="https://gist.github.com/1259427.js?file=handler_hash.java"&gt;&lt;/script&gt;&lt;br /&gt;on tracing to the depth i found that InetAddress is a static class and the getByName method internally calls another method which locks (synchronizes) on a static HashMap i.e. lookup table containing IP addresses. &lt;br /&gt;&lt;script src="https://gist.github.com/1259434.js?file=lookup_table.java"&gt;&lt;/script&gt;&lt;br /&gt;On a multi threaded high performant application this matters very much even if the hashCode is cached. Since the method locks this table and if it takes time due to some reason all the remaining threads in the pool which were to generate a hashCode() to the call for contains() method for performance were waiting for this lookup table. If i had read the documentation which clearly says it is a blocking method i would have avoided this.&lt;br /&gt;I am sure that many of my IT colleagues would do the same mistake as me! Lesson learnt is that when we use a 3rd party API object (even if its a part of java.net it is not written by me so it is a 3rd party :0D) as a key in a hash based collection, it is better to check the hashCode() and equals() implementation before going ahead as they might have some hidden performance implications like this. Finally i had to revert back to the String representation of the URL instead of having the URL object itself since that level of check is enough in my case ;-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-3941464971511742071?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/3941464971511742071/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=3941464971511742071' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/3941464971511742071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/3941464971511742071'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/10/caution-while-using-3rd-party-object.html' title='Caution while using 3rd party Object keys!'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-4179964760662957180</id><published>2011-09-06T08:18:00.000-07:00</published><updated>2011-09-06T08:39:39.138-07:00</updated><title type='text'>Servlet vs JSP!</title><content type='html'>No this is not another post detailing the key differences between these 2. There are plenty of good sites which give great explanation on this. I was stuck up in a silly issue for 1+ days. The gist of the issue is that i am developing a facebook app with iframe canvas. For the first time when the user logs in i have to check whether user has authorized this app and redirect the user to facebook page requesting for necessary permissions. Since it is a Java servlet based application initially i tried using response.sendRedirect() the url. Since the canvas i.e. my application screen was within an iframe the redirected page was displayed within facebook to give a facebook within facebook effect. While learning about frame busting redirect with javascript i tried to embed this code in my redirect method.&lt;br /&gt;&lt;script src="https://gist.github.com/1197860.js?file=redirect.java"&gt;&lt;/script&gt;&lt;br /&gt;The code worked in IE, but firefox and chrome displayed the text as-is. I was puzzled initially and thought it was an iframe behavior difference between IE and others. I compared my redirect code with another PHP application for facebook. To my surprise he also had written the same javascript code from PHP server and it was working like a charm in all browsers. After 1.5 days of struggle i decided to check the headers with curl. Then i found out that my websites content was "text/plain" whereas the PHP site's content was "text/html". This made be recollect the minute difference i studied long ago. &lt;br /&gt;Servlet's default content type for response is "text/plain" whereas for a JSP it is "text/html". I added the line &lt;pre&gt; response.setContentType("text/html"); &lt;/pre&gt; and then it worked like a charm in all browsers. FF and Chrome does not recognize the content as HTML code unless specified but IE somehow recognizes it. A small concept on which i had struggled for 1.5 days made me laugh at myself. In future if someone asks me the difference between JSP and Servlet then this would definitely be in my list. This is what they call learning the hard way!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-4179964760662957180?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/4179964760662957180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=4179964760662957180' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4179964760662957180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4179964760662957180'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/09/servlet-vs-jsp.html' title='Servlet vs JSP!'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-8343824723753223987</id><published>2011-07-24T09:03:00.000-07:00</published><updated>2011-07-24T09:17:53.340-07:00</updated><title type='text'>Project Euler problems 8,10,11 in Clojure</title><content type='html'>I have been working on the other problems of Project Euler now, it is interesting to solve it myself and look into Clojure solutions from experts to understand how elegant the problems can be solved with minimal LoC and many inbuilt but unknown features in Clojure. Each problem is a learning experience both mathematically as well as programatically.&lt;br /&gt;&lt;br /&gt;This is &lt;a href="http://projecteuler.net/index.php?section=problems&amp;id=8"&gt;problem 8&lt;/a&gt; and my solution is below:&lt;br /&gt;&lt;script src="https://gist.github.com/1102774.js?file=euler-p8.clj"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;And for &lt;a href="http://projecteuler.net/index.php?section=problems&amp;id=10"&gt;Problem 10&lt;/a&gt; my solution was faster than some others, i used a sieve to generate all primes less than a given number and added the same.&lt;br /&gt;&lt;script src="https://gist.github.com/1102776.js?file=euler-p10.clj"&gt;&lt;/script&gt; &lt;br /&gt;&lt;br /&gt;And &lt;a href="http://projecteuler.net/index.php?section=problems&amp;id=11"&gt;Problem 11&lt;/a&gt;&lt;br /&gt;i wrote a very bad version of the code first to solve the problem, then revisited each expression to arrive at a better solution as below:&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1102779.js?file=euler-p11.clj"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;Looking forward to solve as much as i can for the betterment of myself as a programmer...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-8343824723753223987?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/8343824723753223987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=8343824723753223987' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/8343824723753223987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/8343824723753223987'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/07/project-euler-problems-81011-in-clojure.html' title='Project Euler problems 8,10,11 in Clojure'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-3813476424498379857</id><published>2011-07-21T19:45:00.000-07:00</published><updated>2011-07-21T20:25:42.116-07:00</updated><title type='text'>Project Euler - Problem 9 in Clojure</title><content type='html'>I have been following this &lt;a href="http://analgorithmaday.blogspot.com/2011/07/pythagorean-triplet.html"&gt;Blog&lt;/a&gt; for quite sometime now the current post is about the pythagorean triplets i.e. the numbers (a,b,c) which obeys the principle of a^2 + b^2 = c^2 i.e. the Pythagoras theorem. The site also says about the Euclid's formula with two variables m and n where m &lt; n which can be used to determine the Pythagorean triplets as shown below:&lt;br /&gt;&lt;br /&gt;a = n*n – m*m &lt;br /&gt;b = 2*n*m &lt;br /&gt;c = n*n + m*m &lt;br /&gt;&lt;br /&gt;The problem is to find out the triplet whose sum will be 1000. i.e. a + b + c = 1000. I thought of solving this in Clojure and swore to myself to avoid loops :-). I have to find the value of 3 variables a,b,c with the equation above. I thought of reducing the variables to 2 instead of 3, i did this by substituting the Euclids formula in the expression i.e.&lt;br /&gt;&lt;br /&gt;n*n – m*m + 2*n*m + n*n + m*m = 1000 &lt;br /&gt;After some high school maths the equation deduced to &lt;br /&gt;n * (n +m) = 1000/2 i.e. 500 &lt;br /&gt;My idea was to solve this equation to calculate n and m using brute force of incrementing them by 1 while maintaining the condition that m &lt; n and then calculate a,b,c based on the Euclid's formula instead of brute force attack with m and n starting from 1. I wrote the Clojure code as below:&lt;br /&gt;&lt;br /&gt;&lt;script src="http://pastebin.com/embed_js.php?i=gfDxmLTe"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;which gave me this output: &lt;br /&gt;&lt;br /&gt;375+200+425=1000&lt;br /&gt;&lt;br /&gt;"Elapsed time: 0.797227 msecs" &lt;br /&gt;&lt;br /&gt;The values 375,200,425 obey the formula of pythagoras theorem with 375^2 + 200^2 = 425^2. &lt;br /&gt;&lt;br /&gt;Then i searched the net for fellow human beings who would ve solved this problem in Clojure, i found this &lt;a href="http://clojure.roboloco.net/?p=133"&gt;page&lt;/a&gt; which contained 2 solutions, both of them were smaller and nicer than mine especially the second one which was too concise. But i found that both of them involved finding the 3 variables a,b,c with incrementing m and n. So i measured the time taken of their solutions with mine for this problem. It turned out that my code executed in 0.7 - 0.9 ms whereas the other solutions took 700-800 ms (due to difference in algorithm).&lt;br /&gt;&lt;br /&gt;Eventhough the whole purpose of this exercise was to learn Clojure which i did only from the other solutions quoted in the above link I was happy that my code performed well inspite of the fact that it was clumsy and i did not use loops and used recursion instead and my solution was different from the others.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;DISCLAIMER:&lt;/span&gt; I tried the code for multiple inputs like 2000, 4000 etc and found it was working fine. But i am not sure whether my solution is fool proof in all cases. The guys quoted with alternative solutions are Clojure experts and i dont claim that my code is better. Somehow the performance was good due to a different algorithm.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-3813476424498379857?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/3813476424498379857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=3813476424498379857' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/3813476424498379857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/3813476424498379857'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/07/project-problem-9-in-clojure.html' title='Project Euler - Problem 9 in Clojure'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-4157526658124518157</id><published>2011-07-19T09:29:00.000-07:00</published><updated>2011-07-19T09:57:44.976-07:00</updated><title type='text'>Why Clojure matters?</title><content type='html'>I got fed up with Java for a year now and been searching for a new language that would make my life interesting. First I played with Scala which is an awesome language and makes life far easier. I read an &lt;a href="http://java.dzone.com/articles/clojure-language-thought"&gt;article &lt;/a&gt;on Javalobby by Mark Needham the author says that a new language that we learn should change the way think of Programming. Scala did it to some extent but I ended up writing Java sans boiler plate code in Scala and naming methods like operators. Since it allows OO i was still caught in the OO design principles cage which I have been living for 7 years now.&lt;br /&gt;&lt;br /&gt;I thought I should give Clojure a try. But learning ((((lojure was not as simple as Scala. When I first looked into a Clojure code I thought WTF is this? A debris of parentheses spread across my screen which makes no sense to a coder. Then I googled and found out this &lt;a href="http://www.learningclojure.com/2011/02/advice-to-newbie.html"&gt;link&lt;/a&gt; the author says that i have to speak Lisp if i had to learn Clojure. All that i know about Lisp was it is an ancient language invented in the Pre C era i.e. 1960s. Pacifying myself i proceeded to google for Lisp. I landed at a site by Paul Graham which contained few essays that increased my interest in Lisp.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://paulgraham.com/rootsoflisp.html"&gt;Roots of Lisp&lt;/a&gt; &lt;br /&gt;&lt;a href="http://paulgraham.com/icad.html"&gt;Revenge of Nerds&lt;/a&gt; &lt;br /&gt;&lt;a href="http://paulgraham.com/power.html"&gt;Power of Lisp&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After reading these articles i prepared my mind to learn Lisp through Scheme (a dialect of Lisp invented in MIT) accompanied by &lt;a href="http://mitpress.mit.edu/sicp/full-text/book/book.html"&gt;SICP &lt;/a&gt;book touted as the bible for a good programmer. I downloaded the PDF and saw few lectures of the creators. It started normally, as i entered the 3rd chapter i had a feeling of reading Electro Magnetic Field theory in my college 3rd sem which is by far the most driest subject i have studied. I felt that i am too old to read this theory as i am not from a Comp Sci background. By this time i have tried few programs in Scheme with SICP exercises and was flabbergasted on how a language can exist without looping constructs and be so powerful. The book said while and for are bad which i felt as an insult to the programming i have done for years. But later understood the truth.&lt;br /&gt;&lt;br /&gt;I was able to implement the standard functions of filter, map and reduce in Scala or any other functional language with few lines of code and recursion which eliminated the necessity for loops. I struggled(ing) a lot to change from 1 + 1 to (+ 1 1 )paradigm. Lisp was written with just 7 basic functions i.e.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;quote, atom, eq, cons, car, cdr, cond &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;as mentioned in the &lt;a href="http://lib.store.yahoo.net/lib/paulgraham/jmc.lisp"&gt;link&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I could not stop myself from comparing these 7 functions to the 7 swaras in Carnatic music from which great composers like Thyagaraja, Oothukadu, Ilayaraja etc. who churned out amazing compositions. Lisp is just a composition of these 7 functions to write code that can do amazing things e.g. macros.&lt;br /&gt;&lt;br /&gt;I learned some basics of Lisp with Scheme and took the dive into Clojure accompanied by some books and simple exercises. The first reason as to why Clojure matters is because it is a Lisp. Experts like Paul Graham have already explained the benefits of using Lisp in the aforementioned links. In addition to the above Clojure matters because it is a dynamic language, i don't need to worry about language constraints like data types and keywords like static, volatile and stuff. Second it removes the restrictive mindset of using Object Oriented design which Scala did to an extent. Writing multi threaded code in Clojure is far more easier than Java since there is no need to worry about low level concepts like synchronization and locking in Clojure. With Clojure i am easily able to decompose my problems into small functions which can be composed to resolve the problem statement which is the essence of functional programming.&lt;br /&gt;&lt;br /&gt;Dynamic languages in JVM have the disadvantage of performance overhead involved in using reflection. Clojure also has the same. To confirm this i wrote a small program to generate the first N prime numbers as a series with N as the input. The algorithm that i used may not be the fastest, but i implemented the same algorithm in Clojure and Java and found out Clojure code took 8-10X more time than Java. I was sceptical about sacrificing performance by 10 folds for conciseness and reduced lines of code in favour of Lisp dialect. I googled and found out a good link on language performances in Ubuntu with quad core and single core processors. Although Clojure is nowhere near to Java or Scala (obviously due to the dynamic typing) it faired well enough compared to other popular languages used for Web development like Python and (J)Ruby.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&amp;lang=clojure&amp;lang2=jruby"&gt;Clojure vs JRuby&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&amp;lang=clojure&amp;lang2=yarv "&gt;Clojure vs Ruby&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&amp;lang=clojure&amp;lang2=python3 "&gt;Clojure vs Python&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Since i am primarily a web developer and if Clojure is faster than these languages which is popular next to Java with Rails and Django frameworks i feel it can be used for web development without any hassles. I see the future of JVM development with a team using Clojure (or Scala) for implementing primary dev tasks with a specialised micro team of core Java developers who write performance intensive code and provide Clojure (or Scala) wrappers for the same to the rest of team to use it. This prediction may never become true or may not happen atleast for next 10-15 years but i would love to watch this becoming a reality.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I had the photos of my son taken through the last few months in my system on a single folder, i wanted to organise the files into folders based on date of the picture taken and keep the photos inside the folders named on date. I thought of writing a program in Clojure to do this and wrote it as below:&lt;br /&gt;&lt;br /&gt;&lt;script src="http://pastebin.com/embed_js.php?i=JR6JkmNt"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;Note: I suppose the clojure code above can be written in a much more concise manner considering that i am just 2 weeks old in Lisp and 1 week old in Clojure.&lt;br /&gt;&lt;br /&gt;I wrote the same logic in Java as below: &lt;br /&gt;&lt;br /&gt;&lt;script src="http://pastebin.com/embed_js.php?i=pjsAD2Hb"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;At first glance the Clojure code may look obscure and Java code might look elegant. But once we read the basic philosphies of Lisp and understand why it is written that way we will be able to appreciate the code. Clojure does not have a complex type system like Scala. I feel clojure is closer to Java than Scala not syntactically but the way it is implemented.&lt;br /&gt;&lt;br /&gt;I may never get a chance to use Clojure in my professional career, but i will use the same in my personal projects and may be if i reach a point in my career where i am able to drive the technical path of an organisation i will definitely use Clojure for all its merits.....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-4157526658124518157?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/4157526658124518157/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=4157526658124518157' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4157526658124518157'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4157526658124518157'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/07/why-clojure-matters.html' title='Why Clojure matters?'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-6863290002491146106</id><published>2011-03-04T09:37:00.000-08:00</published><updated>2011-03-04T09:51:28.059-08:00</updated><title type='text'>Fedora on my VAIO EA 46!</title><content type='html'>Finally got it installed with all drivers in my VAIO. Thanks to &lt;a href="http://sourceforge.net/projects/mac4lin/"&gt;Mac4Llin&lt;/a&gt; , &lt;a href="http://glx-dock.org/"&gt;Cairo dock&lt;/a&gt; and the fedora community!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-rMYxhMcN7sM/TXEle5TtwCI/AAAAAAAACoM/ohgf9GMK9jQ/s1600/Screenshot-1.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 225px;" src="http://4.bp.blogspot.com/-rMYxhMcN7sM/TXEle5TtwCI/AAAAAAAACoM/ohgf9GMK9jQ/s400/Screenshot-1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5580282625998569506" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-nG87juvS-aU/TXEkvWXTCWI/AAAAAAAACoE/LkiwT3CaOq0/s1600/Screenshot.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 225px;" src="http://4.bp.blogspot.com/-nG87juvS-aU/TXEkvWXTCWI/AAAAAAAACoE/LkiwT3CaOq0/s400/Screenshot.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5580281809164503394" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-6863290002491146106?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/6863290002491146106/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=6863290002491146106' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/6863290002491146106'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/6863290002491146106'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/03/fedora-on-my-vaio-ea-46.html' title='Fedora on my VAIO EA 46!'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-rMYxhMcN7sM/TXEle5TtwCI/AAAAAAAACoM/ohgf9GMK9jQ/s72-c/Screenshot-1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-8825090255375052346</id><published>2011-01-28T10:07:00.000-08:00</published><updated>2011-01-28T10:19:54.883-08:00</updated><title type='text'>Using Scala with MIgLayout</title><content type='html'>Most of us would have faced the hell of GridBagLayout and other crappy layout managers available with Swing. I found &lt;a href="http://www.miglayout.com/"&gt;MigLayout&lt;/a&gt; sometime ago which is a savior, it is very much easy to use with string constraints and saves us from the wrath of default layouts. Since i have been learning Scala i though of venturing into Scala swing which is a thin wrapper around Java Swing APIs in Scala for use in Scala style. Scala Swing contains nice Scala wrappers for FlowLayout, BorderLayout etc. in the form of &lt;a href="http://www.scala-lang.org/api/current/scala/swing/FlowPanel.html"&gt;FlowPanel&lt;/a&gt;, &lt;a href="http://www.scala-lang.org/api/current/scala/swing/BorderPanel.html"&gt;BorderPanel&lt;/a&gt; respectively. Unfortunately the package does not have a similar panel for MigLayout. So after browsing through the code for these panels and layout container implementations i wrote my own &lt;a href="http://code.google.com/p/scala-samples/source/browse/trunk/simplecalculator/src/main/scala/MigPanel.scala"&gt;MigPanel&lt;/a&gt; which will enable adding of components to a JPanel with MigLayout and constraints. Since i wanted to learn event handling as well i tried a small simple calculator program &lt;a href="http://code.google.com/p/scala-samples/source/browse/trunk/simplecalculator/src/main/scala/Calculator.scala"&gt;Calculator&lt;/a&gt; using MigPanel. The nice part is that i used partially applied functions for calculation part. Learnt lots of syntactical stuff in this exercise. It looks like below:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_3bcE5AeOtZ0/TUMIonOntrI/AAAAAAAACn4/3sc3E4yD-mA/s1600/screenshot.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 291px; height: 162px;" src="http://3.bp.blogspot.com/_3bcE5AeOtZ0/TUMIonOntrI/AAAAAAAACn4/3sc3E4yD-mA/s400/screenshot.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5567303058178160306" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-8825090255375052346?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/8825090255375052346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=8825090255375052346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/8825090255375052346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/8825090255375052346'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/01/using-scala-with-miglayout.html' title='Using Scala with MIgLayout'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_3bcE5AeOtZ0/TUMIonOntrI/AAAAAAAACn4/3sc3E4yD-mA/s72-c/screenshot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-4223533616700495591</id><published>2011-01-22T01:41:00.000-08:00</published><updated>2011-01-22T01:43:31.941-08:00</updated><title type='text'>Ensime + SBT + Emacs + Scala + Vibrant Ink</title><content type='html'>finally was successful in integrating the above mentioned to create a comprehensive development environment for Scala....&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_3bcE5AeOtZ0/TTqms5ECjcI/AAAAAAAACnw/oCZHRj3noTY/s1600/Screenshot.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 250px;" src="http://2.bp.blogspot.com/_3bcE5AeOtZ0/TTqms5ECjcI/AAAAAAAACnw/oCZHRj3noTY/s400/Screenshot.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5564943579731889602" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-4223533616700495591?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/4223533616700495591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=4223533616700495591' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4223533616700495591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4223533616700495591'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/01/ensime-sbt-emacs-scala-vibrant-ink.html' title='Ensime + SBT + Emacs + Scala + Vibrant Ink'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_3bcE5AeOtZ0/TTqms5ECjcI/AAAAAAAACnw/oCZHRj3noTY/s72-c/Screenshot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-8833442539360731095</id><published>2011-01-14T22:31:00.000-08:00</published><updated>2011-01-14T23:35:44.484-08:00</updated><title type='text'>My first Android App with Scala (or any other language)</title><content type='html'>After a long struggle with the help of this &lt;a href="http://lamp.epfl.ch/~michelou/android/scala-to-android.html"&gt;post&lt;/a&gt; managed to develop my first application for the Android platform using Scala. Faced a few challenges initially in getting a simple Hello World up and running. Proguard removed my action handler methods since it is invoked thru reflection. I found it after too much struggle.Later i had to change the configuration file for Proguard. The application &lt;a href="http://pastie.org/1462743"&gt;code&lt;/a&gt; and the layout &lt;a href="http://pastie.org/1462709"&gt;XML&lt;/a&gt;, i used &lt;a href="http://developer.android.com/resources/tutorials/views/hello-tablelayout.html"&gt;TableLayout&lt;/a&gt; within &lt;a href="http://developer.android.com/resources/tutorials/views/hello-linearlayout.html"&gt;LinearLayout&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This is how it looks on the phone, the logic is based on the hashcode value of the names, and the nice part is that i did not use the android eclipse plugin and did this entire development using command line tools and emulators. The emulator makes it very easy to test applications. The android team has done an awesome job in providing developer tools, kudos to them......&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_3bcE5AeOtZ0/TTFNaNz6IFI/AAAAAAAACno/JU8G3D1iH1I/s1600/scr.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 267px; height: 400px;" src="http://2.bp.blogspot.com/_3bcE5AeOtZ0/TTFNaNz6IFI/AAAAAAAACno/JU8G3D1iH1I/s400/scr.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5562312127558590546" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_3bcE5AeOtZ0/TTFHWHLP-TI/AAAAAAAACng/NkyhC2cNOz8/s1600/scr.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 267px; height: 400px;" src="http://3.bp.blogspot.com/_3bcE5AeOtZ0/TTFHWHLP-TI/AAAAAAAACng/NkyhC2cNOz8/s400/scr.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5562305459988199730" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-8833442539360731095?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/8833442539360731095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=8833442539360731095' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/8833442539360731095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/8833442539360731095'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/01/my-first-android-app-with-scala-or-any.html' title='My first Android App with Scala (or any other language)'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_3bcE5AeOtZ0/TTFNaNz6IFI/AAAAAAAACno/JU8G3D1iH1I/s72-c/scr.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-9177329002980591191</id><published>2011-01-13T07:33:00.000-08:00</published><updated>2011-01-13T07:35:42.402-08:00</updated><title type='text'>Desktop Tweak</title><content type='html'>I have been using Fedora 13 for quite sometime now and tried to imitate a Mac look and feel using various themes etc. I installed Gnome Do which provides a Dock similar to Mac OS. And now my desktop looks like..........&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_3bcE5AeOtZ0/TS8bouCp88I/AAAAAAAACnY/KLFaUqhflKM/s1600/myscreen.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 480px; height: 300px;" src="http://1.bp.blogspot.com/_3bcE5AeOtZ0/TS8bouCp88I/AAAAAAAACnY/KLFaUqhflKM/s320/myscreen.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5561694451193738178" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-9177329002980591191?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/9177329002980591191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=9177329002980591191' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/9177329002980591191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/9177329002980591191'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/01/desktop-tweak.html' title='Desktop Tweak'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_3bcE5AeOtZ0/TS8bouCp88I/AAAAAAAACnY/KLFaUqhflKM/s72-c/myscreen.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-3893725914053457048</id><published>2011-01-10T06:29:00.000-08:00</published><updated>2011-01-10T06:51:26.430-08:00</updated><title type='text'>Scala with gedit</title><content type='html'>This post is an extension to an existing &lt;a href="http://lousycoder.com/blog/index.php?/archives/81-gEdit-and-Scala.html"&gt;post&lt;/a&gt; by Lousycoder. I always thought GEdit was a Linux alternative to notepad. Later i discovered how wrong i was. GEdit can be used as a full fledged code editor with just some plugins and syntax highlights. There are lots of &lt;a href="http://live.gnome.org/Gedit/Plugins"&gt;plugins&lt;/a&gt; available for Gedit. I installed the below mentioned:&lt;br /&gt;1. Bracket Completion&lt;br /&gt;2. Embedded Terminal&lt;br /&gt;3. File Browser Pane&lt;br /&gt;4. Session Saver&lt;br /&gt;5. Snippets (very useful to create code templates like Eclipse)&lt;br /&gt;Slightly tweaked version of the scala language specification for GEdit is available &lt;a href="http://snipt.org/wklmi"&gt;here&lt;/a&gt;. This has to be copied into /usr/share/gtksourceview-2.0/language-specs. I downloaded the darkmacs.xml GEdit theme from &lt;a href="https://github.com/stephank/gedit-themes"&gt;here&lt;/a&gt; and tweaked a few things to create a new colour scheme for GEdit which is available &lt;a href="http://snipt.org/wklmj"&gt;here&lt;/a&gt;. This XML has to be imported into the GEdit using Edit -&gt; Preferences -&gt; Font &amp; Colors -&gt; Add option pointing to the XML. Once all the above is done Gedit looks something like this&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_3bcE5AeOtZ0/TSsbeEAeg6I/AAAAAAAACnQ/M3D3IQ-M71g/s1600/Screenshot.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 200px;" src="http://4.bp.blogspot.com/_3bcE5AeOtZ0/TSsbeEAeg6I/AAAAAAAACnQ/M3D3IQ-M71g/s320/Screenshot.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5560568368204776354" /&gt;&lt;/a&gt;&lt;br /&gt;I use Maven currently to compile the scala files and run them outside on a separate terminal. I also use some &lt;a href="http://snipt.org/wklmk"&gt;snippets&lt;/a&gt; which can be imported using the Snippets plugin in GEdit for faster coding.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-3893725914053457048?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/3893725914053457048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=3893725914053457048' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/3893725914053457048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/3893725914053457048'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/01/scala-with-gedit.html' title='Scala with gedit'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_3bcE5AeOtZ0/TSsbeEAeg6I/AAAAAAAACnQ/M3D3IQ-M71g/s72-c/Screenshot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-4823564989057699176</id><published>2011-01-03T07:34:00.000-08:00</published><updated>2011-01-03T07:39:39.020-08:00</updated><title type='text'>Disjoint Sets....</title><content type='html'>27th problem in Scala is about generating disjoint sets of specified sizes from a set of N elements. i.e. In how many ways can a group of 9 people work in 3 disjoint subgroups of 2, 3 and 4 persons? &lt;br /&gt;Wrote a program that uses recursion with the help of combination generator i used previously. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;object DisjointSets {&lt;br /&gt;&lt;br /&gt; def generateCombinations[A](l: List[A], k: Int): List[List[A]] = {&lt;br /&gt;  l match {&lt;br /&gt;    case Nil =&gt; Nil&lt;br /&gt;    case _ =&gt; {&lt;br /&gt;      if (k &gt; 1)&lt;br /&gt;        (0 to l.size).flatMap({ i =&gt; &lt;br /&gt;    generateCombinations(l.drop(i + 1), k - 1).map({ tmp =&gt; (l(i) :: tmp) }) }).toList&lt;br /&gt;      else&lt;br /&gt;        l.map(List(_))&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; def group[A](specList : List[Int], dataList : List[A]) : List[List[List[A]]] = {&lt;br /&gt;  specList.size match {&lt;br /&gt;   case 1 =&gt;  List(List(dataList))&lt;br /&gt;   case _ =&gt; generateCombinations(dataList,specList.head).flatMap({ tmpList =&gt;&lt;br /&gt;     group(specList.drop(1),dataList.filterNot({tmpList.contains(_)})).map({i =&gt; tmpList :: i})&lt;br /&gt;    })&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; def main(args: Array[String]) {&lt;br /&gt;  val sizeList = args(0).split(",").map(_.toInt).toList&lt;br /&gt;  val dataList = args(1).split(",").toList&lt;br /&gt;  val groups = group(sizeList,dataList)&lt;br /&gt;  groups.foreach({k =&gt; k.foreach(l =&gt;print("["+l.mkString(",")+"] "));println()})&lt;br /&gt;  println("No. of groups : "+groups.size)&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And the output::&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[raam@localhost scala-learning]$ scala DisjointSets 2,2,1 Red,Black,Green,Yellow,Blue&lt;br /&gt;[Red,Black] [Green,Yellow] [Blue] &lt;br /&gt;[Red,Black] [Green,Blue] [Yellow] &lt;br /&gt;[Red,Black] [Yellow,Blue] [Green] &lt;br /&gt;[Red,Green] [Black,Yellow] [Blue] &lt;br /&gt;[Red,Green] [Black,Blue] [Yellow] &lt;br /&gt;[Red,Green] [Yellow,Blue] [Black] &lt;br /&gt;[Red,Yellow] [Black,Green] [Blue] &lt;br /&gt;[Red,Yellow] [Black,Blue] [Green] &lt;br /&gt;[Red,Yellow] [Green,Blue] [Black] &lt;br /&gt;[Red,Blue] [Black,Green] [Yellow] &lt;br /&gt;[Red,Blue] [Black,Yellow] [Green] &lt;br /&gt;[Red,Blue] [Green,Yellow] [Black] &lt;br /&gt;[Black,Green] [Red,Yellow] [Blue] &lt;br /&gt;[Black,Green] [Red,Blue] [Yellow] &lt;br /&gt;[Black,Green] [Yellow,Blue] [Red] &lt;br /&gt;[Black,Yellow] [Red,Green] [Blue] &lt;br /&gt;[Black,Yellow] [Red,Blue] [Green] &lt;br /&gt;[Black,Yellow] [Green,Blue] [Red] &lt;br /&gt;[Black,Blue] [Red,Green] [Yellow] &lt;br /&gt;[Black,Blue] [Red,Yellow] [Green] &lt;br /&gt;[Black,Blue] [Green,Yellow] [Red] &lt;br /&gt;[Green,Yellow] [Red,Black] [Blue] &lt;br /&gt;[Green,Yellow] [Red,Blue] [Black] &lt;br /&gt;[Green,Yellow] [Black,Blue] [Red] &lt;br /&gt;[Green,Blue] [Red,Black] [Yellow] &lt;br /&gt;[Green,Blue] [Red,Yellow] [Black] &lt;br /&gt;[Green,Blue] [Black,Yellow] [Red] &lt;br /&gt;[Yellow,Blue] [Red,Black] [Green] &lt;br /&gt;[Yellow,Blue] [Red,Green] [Black] &lt;br /&gt;[Yellow,Blue] [Black,Green] [Red] &lt;br /&gt;No. of groups : 30&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I managed to complete this in 1 hour.... :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-4823564989057699176?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/4823564989057699176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=4823564989057699176' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4823564989057699176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4823564989057699176'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2011/01/disjoint-sets.html' title='Disjoint Sets....'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-4061746443442820045</id><published>2010-12-28T23:55:00.000-08:00</published><updated>2010-12-29T00:20:21.702-08:00</updated><title type='text'>Pascal's Triangle in Scala</title><content type='html'>Might be the Nth post on this topic in Scala where N &gt; 10000000 but for this is the first time am coding Pascal's Triangle. I tried implementing this using the formula nCr and also using recursion (Scala way ;-)) as shown below:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  //Based on calculation using nCr formula without recursion - less efficient&lt;br /&gt;  def genTriangle(numRows: Int) = {&lt;br /&gt;    def fact(i: Long): Long = if (i &lt;= 1) 1 else i * fact(i - 1)&lt;br /&gt;    def getValue(row: Int, col: Int) = if (row == 1) 1 else fact(row) / (fact(col) * fact(row - col))&lt;br /&gt;    (0 to (numRows - 1)).foreach(rIdx =&gt; println((0 to rIdx).map(getValue(rIdx, _)).mkString(" ")))&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;//Based on recursion i.e. arriving at the current row based on previous row values - more efficient&lt;br /&gt;  def genTri(numRows: Int) = {&lt;br /&gt;    def genTriangle0(curRow: Int, arr: Seq[Int]): Unit = {&lt;br /&gt;      def genArray = for (i &lt;- 0 to curRow) yield if (i == 0 || i == curRow) 1 else arr(i - 1) + arr(i)&lt;br /&gt;      println(arr.mkString(" "))&lt;br /&gt;      if (curRow &lt; numRows) genTriangle0( curRow + 1, genArray)&lt;br /&gt;    }&lt;br /&gt;    genTriangle0(1, Array(1))&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And the output&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;scala&gt; genTriangle(8)&lt;br /&gt;1&lt;br /&gt;1 1&lt;br /&gt;1 2 1&lt;br /&gt;1 3 3 1&lt;br /&gt;1 4 6 4 1&lt;br /&gt;1 5 10 10 5 1&lt;br /&gt;1 6 15 20 15 6 1&lt;br /&gt;1 7 21 35 35 21 7 1&lt;br /&gt;&lt;br /&gt;scala&gt; genTri(8)&lt;br /&gt;1&lt;br /&gt;1 1&lt;br /&gt;1 2 1&lt;br /&gt;1 3 3 1&lt;br /&gt;1 4 6 4 1&lt;br /&gt;1 5 10 10 5 1&lt;br /&gt;1 6 15 20 15 6 1&lt;br /&gt;1 7 21 35 35 21 7 1&lt;br /&gt;&lt;br /&gt;scala&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Definitely this is elegant and lesser LoC than Java&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-4061746443442820045?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/4061746443442820045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=4061746443442820045' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4061746443442820045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4061746443442820045'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2010/12/pascals-triangle-in-scala.html' title='Pascal&apos;s Triangle in Scala'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-3964484216784352670</id><published>2010-12-25T04:12:00.000-08:00</published><updated>2010-12-25T04:52:32.523-08:00</updated><title type='text'>26th Problem in scala</title><content type='html'>Since i have been learning Scala and trying out few coding exercises from &lt;a href="http://aperiodic.net/phil/scala/s-99/"&gt;99 Problems in Scala&lt;/a&gt;. I tried to code the 26th problem which was to generate all the possible unordered combinations of K elements from a set containing N elements which is nCk. The site says the same should be coded in 30 minutes. I took almost 5 hours for me to get it right in Scala. &lt;br /&gt;I tried to implement the Revolving door algorithm by Knuth. It was somehow suitable for imperative programming since it involves variables. I managed to find an alternative algorithm using recursion in stackoverflow which suits the FP style. I tried very hard to be FP without mutable data structures. But finally implemented 2 versions of the algorithm one with mutable ListBuffer and a better version with immutables and vals. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package combinations&lt;br /&gt;&lt;br /&gt;import collection.mutable._&lt;br /&gt;&lt;br /&gt;object CombinationGenerator {&lt;br /&gt;//mutable implementation&lt;br /&gt;  def generateCombinations[A](l: List[A], k: Int): List[List[A]] = {&lt;br /&gt;    if (k &gt; 1) {&lt;br /&gt;      val lb = new ListBuffer[List[A]]()&lt;br /&gt;      (0 to l.size).foreach({ i =&gt; generateCombinations(l.drop(i + 1), k - 1).foreach({ tmp =&gt; lb += (l(i) :: tmp) }) })&lt;br /&gt;      lb.toList&lt;br /&gt;    } else&lt;br /&gt;      l.map(List(_))&lt;br /&gt;  }&lt;br /&gt;//immutable implementation&lt;br /&gt;  def generateCombinationsFP[A](l: List[A], k: Int): List[List[A]] = {&lt;br /&gt;    l match {&lt;br /&gt;      case Nil =&gt; Nil&lt;br /&gt;      case _ =&gt; {&lt;br /&gt;        if (k &gt; 1)&lt;br /&gt;          (0 to l.size).flatMap({ i =&gt; generateCombinations(l.drop(i + 1), k - 1).map({ tmp =&gt; (l(i) :: tmp) }) }).toList&lt;br /&gt;        else&lt;br /&gt;          l.map(List(_))&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  def main(args: Array[String]) {&lt;br /&gt;    //    val l = List("a", "b", "c", "d", "e", "f", "g", "h", "i")&lt;br /&gt;    val l = (1 to 8).toList&lt;br /&gt;    val k = 7&lt;br /&gt;    val c = generateCombinations(l, k)&lt;br /&gt;    println("===========================Dirty FP Version======================")&lt;br /&gt;    println("No. of combinations: " + l.size + " C " + k + " = " + c.size + " from set :: " + l)&lt;br /&gt;    c.foreach(println(_))&lt;br /&gt;    println("====================Partially PURE FP Version====================")&lt;br /&gt;    val fpc = generateCombinationsFP(l, k)&lt;br /&gt;    println("No. of combinations: " + l.size + " C " + k + " = " + c.size + " from set :: " + l)&lt;br /&gt;    c.foreach(println(_))&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The algorithm involves separating the first element i from the set and joining the same with all the combinations of retrieving k-1 elements generated recursively from the remaining i+1,1+2....n set. The output is as follows:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;===========================Dirty FP Version======================&lt;br /&gt;No. of combinations: 6 C 4 = 15 from set :: List(1, 2, 3, 4, 5, 6)&lt;br /&gt;List(1, 2, 3, 4)&lt;br /&gt;List(1, 2, 3, 5)&lt;br /&gt;List(1, 2, 3, 6)&lt;br /&gt;List(1, 2, 4, 5)&lt;br /&gt;List(1, 2, 4, 6)&lt;br /&gt;List(1, 2, 5, 6)&lt;br /&gt;List(1, 3, 4, 5)&lt;br /&gt;List(1, 3, 4, 6)&lt;br /&gt;List(1, 3, 5, 6)&lt;br /&gt;List(1, 4, 5, 6)&lt;br /&gt;List(2, 3, 4, 5)&lt;br /&gt;List(2, 3, 4, 6)&lt;br /&gt;List(2, 3, 5, 6)&lt;br /&gt;List(2, 4, 5, 6)&lt;br /&gt;List(3, 4, 5, 6)&lt;br /&gt;====================Partially PURE FP Version====================&lt;br /&gt;No. of combinations: 6 C 4 = 15 from set :: List(1, 2, 3, 4, 5, 6)&lt;br /&gt;List(1, 2, 3, 4)&lt;br /&gt;List(1, 2, 3, 5)&lt;br /&gt;List(1, 2, 3, 6)&lt;br /&gt;List(1, 2, 4, 5)&lt;br /&gt;List(1, 2, 4, 6)&lt;br /&gt;List(1, 2, 5, 6)&lt;br /&gt;List(1, 3, 4, 5)&lt;br /&gt;List(1, 3, 4, 6)&lt;br /&gt;List(1, 3, 5, 6)&lt;br /&gt;List(1, 4, 5, 6)&lt;br /&gt;List(2, 3, 4, 5)&lt;br /&gt;List(2, 3, 4, 6)&lt;br /&gt;List(2, 3, 5, 6)&lt;br /&gt;List(2, 4, 5, 6)&lt;br /&gt;List(3, 4, 5, 6)&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Even though i am not from a computer science background and these algorithms are new to me and i would have completed this faster in Java (apdinu sollika vendiyadhu thaan) still this shows my programming skills are bad and requires improvement, hope it happens before i complete the 99 problems......&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-3964484216784352670?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/3964484216784352670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=3964484216784352670' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/3964484216784352670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/3964484216784352670'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2010/12/26th-problem-in-scala.html' title='26th Problem in scala'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-2875050577337211684</id><published>2010-12-12T00:41:00.000-08:00</published><updated>2010-12-12T00:55:19.523-08:00</updated><title type='text'>Scala and FP!</title><content type='html'>Off late i have become bored with Java (not because i ve learnt everything in it, there is still lot to learn....) I am trying to learn Scala which is a mix of OO and Functional Programming (FP). I am so excited to learn FP since it is so easy to write code. I have always (for atleast 3 years) wanted to write a small utility code that organizes the MP3 files in my collection in a proper way i.e. sequential numbering of songs starting from 001 to 999 and remove unwanted strings from the song names i.e. tamilmp3world-&lt;song1&gt;.mp3 etc. &lt;br /&gt;Since i have been learning Scala for more than 2 weeks now i thought of writing the utility in Scala using the power of FP. I wrote the code below and was successful in organizing my files.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;object OrganizeFiles {&lt;br /&gt;&lt;br /&gt; val removables = List("copy of ", "tamilbeat.com - ", "ajraj-", " - tamilwire.com", "tamilmp3world.com - ", " mazhai - ",&lt;br /&gt;    "rehman - ", "baba__", "artist - track ", "may_maadham_[0-9]", "lagaan - ", "lagaan- ", "lagaan-", "lagaan -",&lt;br /&gt;    "roja_[0-9]", "roja_", "bombay_[0-9]", "guru - 0[0-9] ", "puthiya_mannarkal_[0-9]", "sok-", "0[0-9]-", "indra_[0-9]", "0[0-9]\\_", "divya\\_-\\_",&lt;br /&gt;    "- ", "0[0-9]", "ilayaraja ", "[0-9][0-9]\\.", "[0-9][0-9]\\. ", "\\. ", "vanna vanna pookal ", "bharathi ", "kaasi-",&lt;br /&gt;    "aranmanai kili ", "poonthalir-", "nilave mugam kaatu ", "--a, ", "--", "veera ", "thoongathe thambi thoongathe ",&lt;br /&gt;    "voice ", "--", "ilaiyaraj", "illayaraaj", "orkaidhiyidair", "radha\\_-\\_", "divya__", "tamiljoy.com-", "\\_smk", "tamilvibez.com\\_",&lt;br /&gt;    "[\\s]{2,}", " _ mella thirandhadu kadavu", "1\\.", "mouna\\_geetham\\_-\\_")&lt;br /&gt;&lt;br /&gt;  def removeUnwanted(s: String) = {&lt;br /&gt;    //form the regular expression string with mkString from above list to invoke replaceAll&lt;br /&gt;    s.toLowerCase.replaceAll(removables.mkString("|"), "").trim&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  def capitalize(str: String, i: Int) = {&lt;br /&gt; //split the folder names with file separator so that each folder name goes into a String array&lt;br /&gt;    val arr = str.split(java.io.File.separatorChar)&lt;br /&gt;    val fName = removeUnwanted(arr.last)&lt;br /&gt;    //pad required 0s in the start to generate 001, 011, 111 etc.&lt;br /&gt;    arr(arr.length - 1) = "0" * (3 - i.toString.length) + i + "-" + fName.charAt(0).toUpperCase + fName.substring(1)&lt;br /&gt;    //assemble the modified file name &lt;br /&gt;    arr.mkString(java.io.File.separator)&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  def changeFiles(f: java.io.File) {&lt;br /&gt; //filter the MP3 file alone from the folder and sort based on name&lt;br /&gt;    val s = f.listFiles().filter { i =&gt; i.getName.endsWith(".MP3") || i.getName.endsWith(".mp3") }.sortBy(_.getName)&lt;br /&gt;    for (i &lt;- 0 until s.length) {&lt;br /&gt;      val newName = capitalize(s(i).getAbsolutePath, i + 1)&lt;br /&gt;      println(newName)&lt;br /&gt;      //rename the file&lt;br /&gt;      s(i).renameTo(new java.io.File(newName))&lt;br /&gt;    }&lt;br /&gt;    //call the function recursively on all sub-directories&lt;br /&gt;    f.listFiles().filter { i =&gt; i.isDirectory }.foreach { changeFiles(_) }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def main(args: Array[String]) {&lt;br /&gt;    val f = new java.io.File(args(0))&lt;br /&gt;    //call it in each sub directory&lt;br /&gt;    f.listFiles.filter { _.isDirectory }.foreach(changeFiles(_))&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I was able to do what i wanted to in just 37 lines of code ignoring comments. Since Scala integrates well with Java i used the java.io.File api methods for this purpose. I did not write this in Java because i felt lazy since this would be tedious and cumbersome and consume atleast 100 lines of code....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-2875050577337211684?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/2875050577337211684/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=2875050577337211684' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/2875050577337211684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/2875050577337211684'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2010/12/scala-and-fp.html' title='Scala and FP!'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-2103792589925697454</id><published>2010-11-20T19:04:00.000-08:00</published><updated>2010-11-20T19:18:43.640-08:00</updated><title type='text'>Java Sine wave program</title><content type='html'>My sister has just joined her training with an IT company. Just went through some of her exercises. Once of them was to generate a sine wave. Had a look in to the formula from &lt;a href="http://en.wikipedia.org/wiki/Sine_wave"&gt;here&lt;/a&gt;. Spent some 2-3 hrs in coding a small utility program that can draw a sine wave based on the given input.&lt;div&gt;&lt;br /&gt;HTF did the guy invent this formula???&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.awt.Font;&lt;br /&gt;import java.awt.Graphics;&lt;br /&gt;import java.awt.Graphics2D;&lt;br /&gt;import java.awt.font.FontRenderContext;&lt;br /&gt;import java.awt.font.TextLayout;&lt;br /&gt;import java.awt.geom.Line2D;&lt;br /&gt;import java.awt.geom.Point2D;&lt;br /&gt;&lt;br /&gt;import javax.swing.JFrame;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * A simple utility class using Java swing to generate sine wave based on input params&lt;br /&gt; * @author raam&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class SineFrame extends JFrame{&lt;br /&gt;&lt;br /&gt; private static final long serialVersionUID = 1L;&lt;br /&gt; &lt;br /&gt; //1d array to store the amplitude data, time data is represented or derived from the index of array&lt;br /&gt; double[] amplitude;&lt;br /&gt; &lt;br /&gt; int center;&lt;br /&gt; &lt;br /&gt; double H_STEP_SIZE = 1d;&lt;br /&gt; &lt;br /&gt; int t,amp;&lt;br /&gt; &lt;br /&gt; float omega;&lt;br /&gt; &lt;br /&gt; /**&lt;br /&gt;  * Overloaded constructor&lt;br /&gt;  * @param t&lt;br /&gt;  *    Time part&lt;br /&gt;  * @param amp&lt;br /&gt;  *    Maximum amplitude of the generated sine wave&lt;br /&gt;  * @param omega&lt;br /&gt;  *    Frequency&lt;br /&gt;  * @param hSize&lt;br /&gt;  *    Horizontal size of the frame&lt;br /&gt;  * @param vSize&lt;br /&gt;  *    Vertical size of the frame&lt;br /&gt;  */&lt;br /&gt; public SineFrame(int t,int amp,float omega,int hSize,int vSize){&lt;br /&gt;  this.t = t;&lt;br /&gt;  this.amp = amp;&lt;br /&gt;  this.omega = omega;&lt;br /&gt;  //to check integer overflow when multiplied with horizontal step size&lt;br /&gt;  amplitude = new double[t*(int)H_STEP_SIZE &amp;lt; t?Integer.MAX_VALUE:t*(int)H_STEP_SIZE]; &lt;br /&gt;  setDefaultCloseOperation(EXIT_ON_CLOSE);&lt;br /&gt;  center = vSize/2;&lt;br /&gt;  setSize(hSize,vSize);&lt;br /&gt;  //calculate the co-ordinates based on input params to draw the wave&lt;br /&gt;  calculateCoords(t,amp,omega);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; private void calculateCoords(int t, int amp, float omega) {&lt;br /&gt;  for(int i=0;i&amp;lt;amplitude.length;i++)&lt;br /&gt;   amplitude[i] = amp * Math.sin(omega*(i/H_STEP_SIZE));  &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @Override&lt;br /&gt; public void paint(Graphics g){&lt;br /&gt;        Graphics2D g2 = (Graphics2D) g;&lt;br /&gt;        Point2D prev,cur;&lt;br /&gt;        double y;&lt;br /&gt;        Line2D lin;&lt;br /&gt;        Font font =  new Font("Times", Font.BOLD, 25);&lt;br /&gt;        FontRenderContext frc = g2.getFontRenderContext();&lt;br /&gt;        TextLayout layout = new TextLayout("A = "+amp+"; Omega = "+omega+"; t = "+t, font, frc);&lt;br /&gt;        layout.draw(g2, 10f, 50f);        &lt;br /&gt;        cur = new Point2D.Double(10,center);&lt;br /&gt;        //iterate thru' the calculated co-ordinates and draw lines between adjacent points&lt;br /&gt;        //to generate the sine wave&lt;br /&gt;        for(int i=0;i&amp;lt;amplitude.length;i++){&lt;br /&gt;         prev = cur;&lt;br /&gt;         y = getCoOrdsFromAmplitude(amplitude[i]);&lt;br /&gt;         cur = new Point2D.Double(10+(i/H_STEP_SIZE), y);&lt;br /&gt;         System.out.println("Co-ordinates--{x="+cur.getX()+"},{y="+cur.getY()+"}");&lt;br /&gt;         lin = new Line2D.Double(prev,cur);&lt;br /&gt;         g2.draw(lin);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt; }&lt;br /&gt;        &lt;br /&gt; private double getCoOrdsFromAmplitude(double amp){&lt;br /&gt;  return center + amp;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;        java.awt.EventQueue.invokeLater(new Runnable() {&lt;br /&gt;            public void run() {&lt;br /&gt;                new SineFrame(1000,200,.07f,1000,600).setVisible(true);&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;and the output&lt;/div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_3bcE5AeOtZ0/TOiPJCy3eBI/AAAAAAAACmw/KMWK_U8VIa0/s1600/sine.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 191px;" src="http://2.bp.blogspot.com/_3bcE5AeOtZ0/TOiPJCy3eBI/AAAAAAAACmw/KMWK_U8VIa0/s320/sine.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5541836727011211282" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-2103792589925697454?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/2103792589925697454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=2103792589925697454' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/2103792589925697454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/2103792589925697454'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2010/11/sine-wave.html' title='Java Sine wave program'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_3bcE5AeOtZ0/TOiPJCy3eBI/AAAAAAAACmw/KMWK_U8VIa0/s72-c/sine.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-2206748333688917784</id><published>2010-10-15T22:59:00.000-07:00</published><updated>2010-10-16T04:11:23.584-07:00</updated><title type='text'>Groovy vs Java</title><content type='html'>&lt;div style="text-align: justify;"&gt;I have been trying to learn Groovy for sometime now. Was wondering how the code compares with Java that i have been writing all these 6 years. I felt too happy that i am able to do wonderful collection operations with just few lines of code  in Groovy. Let us take an example programming problem statement which needs to be realized using Java and Groovy.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Statement:&lt;/b&gt; &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Consider the currency notes available in India and US as follows:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;India - 1000,500,100,50, 20, 10, 5, 2, 1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;US - 1000,100,50,25, 10, 5, 1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Given the amount as an Integer the output should be calculated denominations in the above mentioned notes based on the country. For e.g. if 55 is given with Country India the output should be 50 x 1, 2 x 2, 1x1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;I wrote a sample code GChange.groovy as shown below:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;def getChange(Integer amt, String ctry = 'in'){&lt;/div&gt;&lt;div style="text-align: justify;"&gt; def coins =  ['in':[1000,500,100,50, 20, 10, 5, 2, 1],'us':[1000,100,50,25, 10, 5, 1]]&lt;/div&gt;&lt;div style="text-align: justify;"&gt; change = [:]&lt;/div&gt;&lt;div style="text-align: justify;"&gt; //closure 1&lt;/div&gt;&lt;div style="text-align: justify;"&gt; coins[ctry].each {i -&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  while(amt &gt; 0){&lt;/div&gt;&lt;div style="text-align: justify;"&gt;   if((amt - i) &gt;= 0){&lt;/div&gt;&lt;div style="text-align: justify;"&gt;    amt -= i&lt;/div&gt;&lt;div style="text-align: justify;"&gt;    if(change[i]!=null)//increment the count if already exists&lt;/div&gt;&lt;div style="text-align: justify;"&gt;     change[i]++&lt;/div&gt;&lt;div style="text-align: justify;"&gt;    else//add to the map with count 1 if it does not exists&lt;/div&gt;&lt;div style="text-align: justify;"&gt;     change.put(i,1)&lt;/div&gt;&lt;div style="text-align: justify;"&gt;   }&lt;/div&gt;&lt;div style="text-align: justify;"&gt;   else&lt;/div&gt;&lt;div style="text-align: justify;"&gt;    break;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  }&lt;/div&gt;&lt;div style="text-align: justify;"&gt; }&lt;/div&gt;&lt;div style="text-align: justify;"&gt; println ctry.center(10,'-')&lt;/div&gt;&lt;div style="text-align: justify;"&gt; //closure 2&lt;/div&gt;&lt;div style="text-align: justify;"&gt; change.each {k,v -&gt; printf("%5s x %2s \n",k,v)}&lt;/div&gt;&lt;div style="text-align: justify;"&gt;}&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;getChange(1327)&lt;/div&gt;&lt;div style="text-align: justify;"&gt;getChange(1327,'us')&lt;/div&gt;&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This code produces an output as shown below:&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;----in----&lt;/div&gt;&lt;div style="text-align: justify;"&gt;1000 x  1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;100 x  3&lt;/div&gt;&lt;div style="text-align: justify;"&gt;20 x  1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;5 x  1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;2 x  1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;----us----&lt;/div&gt;&lt;div style="text-align: justify;"&gt;1000 x  1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;100 x  3&lt;/div&gt;&lt;div style="text-align: justify;"&gt;25 x  1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;1 x  2&lt;/div&gt;&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The same code in Java is shown below:&lt;/div&gt;&lt;pre&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;import java.util.Arrays;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;import java.util.LinkedHashMap;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;import java.util.List;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;import java.util.Map;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;public class Change {&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt; static Map&amp;lt;String,List&amp;lt;Integer&amp;gt;&amp;gt; coins = new LinkedHashMap&amp;lt;String,List&amp;lt;Integer&amp;gt;&amp;gt;();&lt;/div&gt;&lt;div style="text-align: justify;"&gt; &lt;/div&gt;&lt;div style="text-align: justify;"&gt; static{&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  Integer[] a = {1000,500,100,50, 20, 10, 5, 2, 1};&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  coins.put("in", Arrays.asList(a));&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  Integer[] b = {1000,100,50,25, 10, 5, 1};&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  coins.put("us", Arrays.asList(b));  &lt;/div&gt;&lt;div style="text-align: justify;"&gt; }&lt;/div&gt;&lt;div style="text-align: justify;"&gt; //additional method&lt;/div&gt;&lt;div style="text-align: justify;"&gt; public static void getChange(Integer amt){&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  getChange(amt, "in");&lt;/div&gt;&lt;div style="text-align: justify;"&gt; }&lt;/div&gt;&lt;div style="text-align: justify;"&gt; &lt;/div&gt;&lt;div style="text-align: justify;"&gt; public static void getChange(Integer amt,String ctry){&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  Map&amp;lt;Integer,Integer&amp;gt; change = new LinkedHashMap&amp;lt;Integer, Integer&amp;gt;();&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  for(Integer i:coins.get(ctry)){&lt;/div&gt;&lt;div style="text-align: justify;"&gt;   while(amt &amp;gt; 0){&lt;/div&gt;&lt;div style="text-align: justify;"&gt;    if((amt - i) &amp;gt;= 0){&lt;/div&gt;&lt;div style="text-align: justify;"&gt;     amt -= i;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;     if(change.get(i)!=null)//increment the count if already exists&lt;/div&gt;&lt;div style="text-align: justify;"&gt;      change.put(i, change.get(i)+1);&lt;/div&gt;&lt;div style="text-align: justify;"&gt;     else//add to the map with count 1 if it does not exists&lt;/div&gt;&lt;div style="text-align: justify;"&gt;      change.put(i,1);&lt;/div&gt;&lt;div style="text-align: justify;"&gt;    }&lt;/div&gt;&lt;div style="text-align: justify;"&gt;    else&lt;/div&gt;&lt;div style="text-align: justify;"&gt;     break;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;   }&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  }&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  System.out.println("----"+ctry+"----");&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  for(Map.Entry&amp;lt;Integer, Integer&amp;gt; e:change.entrySet()){&lt;/div&gt;&lt;div style="text-align: justify;"&gt;   System.out.printf("%5s x %2s \n", e.getKey(),e.getValue());&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  }&lt;/div&gt;&lt;div style="text-align: justify;"&gt; }&lt;/div&gt;&lt;div style="text-align: justify;"&gt; &lt;/div&gt;&lt;div style="text-align: justify;"&gt; public static void main(String[] args) {&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  getChange(1327);&lt;/div&gt;&lt;div style="text-align: justify;"&gt;  getChange(1327,"us");&lt;/div&gt;&lt;div style="text-align: justify;"&gt; }&lt;/div&gt;&lt;div style="text-align: justify;"&gt;}&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Even though the above program produces the same output, there are few things to be noted here:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;u&gt;a. Lines of Code:&lt;/u&gt; 46 lines of Java code is required to implement the solution, whereas Groovy requires just 22 lines which almost half&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;u&gt;b. Variable declarations:&lt;/u&gt; Java variable declarations are complex and require the generic types and collection implementations to be specified before hand. Also adding the list of Map has to be done separately in a static block. In Groovy the formation of the data structure containing country to currency notes mapping is possible in a single line and much more elegant than Java&lt;/div&gt;&lt;div style="text-align: justify;"&gt;without having to specify the type information before hand.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;u&gt;c. Iterations:&lt;/u&gt; Code within the iteration of collections is easy in Groovy using Closures. We have used 2 closures for calculation of denomination as well as for printing the contents of final result. In Java we need to iterate with enhanced for loops and Map.Entry variables which is not as simple as the Groovy way.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;u&gt;d. Unwanted additional methods:&lt;/u&gt; Since Groovy supports default method parameter values we can invoke the getChange() method in two ways i.e. getChange(amount) or getChange(amount,country). If the country is not provided then by default India is considered.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;To realize this in Java we need an additional method named getChange() with one argument that internally calls getChange() with two arguments with India as the second argument value.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;It is obvious from the above example that Groovy improves developer productivity with initial training investment even though it is all the same byte code running in the JVM.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;P.S: The above logic can be made simpler using a divisor and remainder method, but the purpose of this entry is to compare the syntax of Java and Groovy, hence i have not implemented the same.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-2206748333688917784?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/2206748333688917784/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=2206748333688917784' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/2206748333688917784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/2206748333688917784'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2010/10/i-have-been-trying-to-learn-groovy-for.html' title='Groovy vs Java'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-4920486295293467774</id><published>2009-11-15T04:58:00.000-08:00</published><updated>2009-11-15T05:03:12.662-08:00</updated><title type='text'>Unique values in List</title><content type='html'>The easiest way according to me to populate a list with unique values i.e. eliminate duplicates is&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;br /&gt;List&lt;String&gt; l;&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;LinkedHashSet&lt;String&gt; ls = new LinkedHashSet&lt;String&gt;(l);&lt;br /&gt;l = new ArrayList&lt;String&gt;(ls);&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The elements in the List should have proper overriding of equals() and hashCode() method&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-4920486295293467774?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/4920486295293467774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=4920486295293467774' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4920486295293467774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/4920486295293467774'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2009/11/unique-values-in-list.html' title='Unique values in List'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-7377060534025316330</id><published>2009-11-11T18:37:00.000-08:00</published><updated>2009-11-11T18:49:17.840-08:00</updated><title type='text'>Java sizeof .....</title><content type='html'>Previously i used to find out the approx size of a Java object using the naive method of creating N objects and measure the increase in heap size without doing a GC, but after some digging in the net i found a new way using Java Instrumentation APIs to get the size of an object. From the experiment done in a 32 bit Windows JVM it seems that the size of an Object i.e. class A{} is 8 bytes i think 4 bytes for the int hashCode and 4 bytes for the Class reference of this object. If we add one more byte variable to this class then the size expands by another 8 bytes. It remains the same for addition of another 7 bytes. Hence it is found that JVM expands the size in steps of 8 bytes. &lt;br /&gt;I found the answer to one of my long pending doubts, what is the size of a boolean variable in Java, yes it is a byte!&lt;br /&gt;I used the below mentioned code to test the same&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;import java.lang.instrument.Instrumentation;import java.util.HashMap; &lt;br /&gt;interface I{      } &lt;br /&gt;interface K{      } &lt;br /&gt;class C implements I,K{      &lt;br /&gt;String s =  new String("jkashdkjhsjkafsd");      } &lt;br /&gt;class D extends C{&lt;br /&gt;} &lt;br /&gt;class A{&lt;br /&gt;//    byte b1;&lt;br /&gt;//    byte b2;&lt;br /&gt;//    byte b3;&lt;br /&gt;//    byte b4;&lt;br /&gt;//    byte b5;&lt;br /&gt;//    byte b6;&lt;br /&gt;//    byte b7;&lt;br /&gt;//    byte b8;&lt;br /&gt;//    byte b9;&lt;br /&gt;//    byte b10;&lt;br /&gt;//    byte b11;&lt;br /&gt;//    byte b12;&lt;br /&gt;//    byte b13;&lt;br /&gt;//    byte b14;&lt;br /&gt;//    byte b15;&lt;br /&gt;//    byte b16;&lt;br /&gt;//    byte b17;&lt;br /&gt;//    int a;&lt;br /&gt;//    int b;&lt;br /&gt;//    boolean b2;&lt;br /&gt;//    boolean b3;&lt;br /&gt;//    boolean b4;&lt;br /&gt;//    boolean b5;&lt;br /&gt;//    boolean b6;&lt;br /&gt;//    boolean b7;&lt;br /&gt;//    boolean b8;&lt;br /&gt;//    boolean b9;&lt;br /&gt;//    boolean b10;&lt;br /&gt;//    boolean b11;&lt;br /&gt;//    boolean b12;&lt;br /&gt;//    boolean b13;&lt;br /&gt;//    boolean b14;&lt;br /&gt;//    boolean b15;&lt;br /&gt;} &lt;br /&gt;class B{      } &lt;br /&gt;public class SizeTester { &lt;br /&gt;      public static void premain(String agentArgs, Instrumentation inst){            System.out.println("A - "+inst.getObjectSize(new A()));            &lt;br /&gt;System.out.println("B - "+inst.getObjectSize(new B()));            &lt;br /&gt;System.out.println("I - "+inst.getObjectSize(new I(){}));            System.out.println("C - "+inst.getObjectSize(new C()));            &lt;br /&gt;System.out.println("D - "+inst.getObjectSize(new D()));            &lt;br /&gt;System.out.println("S1 - "+inst.getObjectSize(new String "jkashdkjhsjkafsd")));            &lt;br /&gt;System.out.println("S2 - "+inst.getObjectSize("jkashdkjhsjkafsd"));                  &lt;br /&gt;}            &lt;br /&gt;public static void main(String[] args) {                  &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The manifest file contains &lt;br /&gt;&lt;strong&gt;&lt;br /&gt;Manifest-Version: 1.0&lt;br /&gt;Premain-Class: SizeTester&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The jar file has to be given as VM argument javaagent:&lt;JAR FILE NAME&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-7377060534025316330?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/7377060534025316330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=7377060534025316330' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/7377060534025316330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/7377060534025316330'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2009/11/java-sizeof.html' title='Java sizeof .....'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-29990844.post-115081264359439633</id><published>2006-06-20T07:09:00.000-07:00</published><updated>2006-06-20T07:10:43.603-07:00</updated><title type='text'>My first post</title><content type='html'>Just wanted to consolidate all the information i learn day to day about Programming, Computers, Technology, database etc. in a useful manner which prompted me to create this blog. Will keep posting useful info.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29990844-115081264359439633?l=technicalitee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalitee.blogspot.com/feeds/115081264359439633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=29990844&amp;postID=115081264359439633' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/115081264359439633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29990844/posts/default/115081264359439633'/><link rel='alternate' type='text/html' href='http://technicalitee.blogspot.com/2006/06/my-first-post.html' title='My first post'/><author><name>Ram</name><uri>http://www.blogger.com/profile/17267982040360350563</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://photos1.blogger.com/blogger/2229/1448/1600/yin_yang_4.jpg'/></author><thr:total>3</thr:total></entry></feed>
