<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-4953895613784667233</atom:id><lastBuildDate>Sat, 30 Jul 2011 15:13:35 +0000</lastBuildDate><title>Cogito Ergo Sum</title><description>A blog about java,developer productivity,pragmatism ,groovy, collective intelligence, architecture, programming problems, neural nets.</description><link>http://maneeshchaturvedi.blogspot.com/</link><managingEditor>noreply@blogger.com (maneesh chaturvedi)</managingEditor><generator>Blogger</generator><openSearch:totalResults>41</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/maneeshchaturvedi" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="maneeshchaturvedi" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-8206341624794219517</guid><pubDate>Thu, 09 Jul 2009 05:37:00 +0000</pubDate><atom:updated>2009-07-09T11:14:13.142+05:30</atom:updated><title>JVM Internals Series -Part 1</title><description>A lot of java developers tend to be unaware about the basics of the internals of the JVM. This series aims to look at the internals of the JVM and explain in a simple way &lt;ul&gt; What is the Java Virtual Machine&lt;/ul&gt; &lt;ul&gt; How does the JVM function&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;&lt;br /&gt;What is the Java Virtual Machine ?&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;When you talk of the JVM there are three aspects which we speak of&lt;/p&gt; &lt;ol&gt;&lt;li&gt;Specification&lt;/li&gt;&lt;li&gt;Concrete Implementation&lt;/li&gt;&lt;li&gt;Runtime&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The specification is a concept, Concrete implementations which exist on different platforms and are available from different vendors like IBM, Sun etc are either all software or a mix of hardware and software. A Runtime instance hosts a single running java application.&lt;/p&gt; &lt;p&gt;A runtime instance has one function and that is to run one java application.  Whenever a java application runs, a runtime instance is born. Thus the number of runtime instances on a machine are equal to the number of applications which are running.  The JVM starts with the invocation of a main() method which needs to be public, static, void and takes a String array as an argument. The main method thus serves as the initial thread for the running application. This can in turn spawn other threads. Inside the VM, threads come in two flavors, daemon and non-daemon. A daemon thread is a thread which is normally used by the VM itself, like the thread which runs the garbage collection. However an application can mark any thread it creates as a daemon. A java application continues to execute until there are any non-daemon threads alive(parallely the VM runtime instance continues to exist). When all non-daemon threads of an application exit, the virtual machine instance exits.&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;JVM Architecture&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_EP7lRcluMNE/SlWC9NP_aqI/AAAAAAAAAbA/Efq5qBvAZoY/s1600-h/jvm-arch.jpeg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 191px;" src="http://3.bp.blogspot.com/_EP7lRcluMNE/SlWC9NP_aqI/AAAAAAAAAbA/Efq5qBvAZoY/s320/jvm-arch.jpeg" alt="" id="BLOGGER_PHOTO_ID_5356331319867435682" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The VM needs memory to store a lot of information, like the bytecode, program arguments, objects which have been instantiated etc. Some of the information stored in the memory is shared across all application threads, while other information may be unique to individual threads. &lt;/p&gt; &lt;p&gt;Each instance of a JVM has one method area and a heap. These areas are shared by all threads running within the instance.&lt;br /&gt;The information regarding the type is loaded from the class files when the JVM loads a class file. This information is stored in the method area. All the objects which are instantiated placed on the heap.&lt;br /&gt;As each new thread is created, it is assigned its own pc register(program counter) and java stack. If the thread is executing a java method (not a native method), the counter in the pc register points to the next instruction to execute. The java stack comprises of frames. A frame consists of the state of one method invocation. When a thread invokes a method, a new frame is pushed on the thread’s stack. On completion of the method execution, the VM pops and discards the frame. No other thread can access another threads pc register or java stack.&lt;/p&gt; &lt;p&gt;This gives a brief overview of the java virtual machine’s architecture. In the next post,I will cover data types and the class loading subsystem.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-8206341624794219517?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/07/lot-of-java-developers-tend-to-be.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_EP7lRcluMNE/SlWC9NP_aqI/AAAAAAAAAbA/Efq5qBvAZoY/s72-c/jvm-arch.jpeg" height="72" width="72" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-1507755089038692027</guid><pubDate>Wed, 08 Jul 2009 09:59:00 +0000</pubDate><atom:updated>2009-07-08T15:44:54.471+05:30</atom:updated><title>Groovy Class for Analyzing java code</title><description>&lt;span class="Apple-style-span"   style="  line-height: 19px; white-space: pre-wrap; font-family:'Lucida Grande';font-size:13px;"&gt;&lt;code&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span"   style="  ;font-family:'Lucida Grande';font-size:13px;"&gt;A lot of times when i sit down to review code, there are some basic things like the size of the class, the total lines, the maximum width of a line etc, which can help in figuring out bad smells in code. In order to automate the task i wrote a small groovy class which can be run on a directory to figure out these metrices. Although there are lots of tools available, the simplicity and the customization which can be done to a small utility class far outweigh the advantages.&lt;br /&gt;&lt;br /&gt;class CodeAnalyzer {&lt;br /&gt;        int lineCount&lt;br /&gt;    int maxLineWidth&lt;br /&gt;    int widestLineNumber&lt;br /&gt;    int totalChars&lt;br /&gt;    int lineSize&lt;br /&gt;    def List findJavaFiles(File parentDir){&lt;br /&gt;        def files=new ArrayList()&lt;br /&gt;        parentDir.eachFileRecurse{file -&gt;&lt;br /&gt;            if(file.isFile() &amp;amp;&amp;amp; file.name.endsWith(".java"))&lt;br /&gt;                files.add(file)&lt;br /&gt;        }&lt;br /&gt;        return files&lt;br /&gt;    }&lt;br /&gt;    def analyzeFile(File javaFile){&lt;br /&gt;        javaFile.eachLine{line -&gt;&lt;br /&gt;            measureLine(line)&lt;br /&gt;        }&lt;br /&gt;        println "fileName =" + javaFile.name&lt;br /&gt;        println "lineCount =" + lineCount&lt;br /&gt;        println "maxLineWidth ="+maxLineWidth&lt;br /&gt;        println "widestLineNumber ="+widestLineNumber&lt;br /&gt;        println "totalChars ="+totalChars&lt;br /&gt;    }&lt;br /&gt;    def measureLine(String line){&lt;br /&gt;        lineCount++&lt;br /&gt;        lineSize=line.length()&lt;br /&gt;        totalChars +=lineSize&lt;br /&gt;        recordWidestLine(lineSize)&lt;br /&gt;    }&lt;br /&gt;    def recordWidestLine(int lineSize){&lt;br /&gt;        if(lineSize &gt;maxLineWidth){&lt;br /&gt;            maxLineWidth =lineSize&lt;br /&gt;            widestLineNumber=lineCount&lt;br /&gt;        }&lt;br /&gt;     }&lt;br /&gt;     def getMeanLineWidth(){&lt;br /&gt;         return totalChars/lineCount&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt; The semantics of usage are pretty simple. I will show the groovy way of invoking it&lt;br /&gt; CodeAnalyzer codeAnalyzer=new CodeAnalyzer()&lt;br /&gt;codeAnalyzer.findJavaFiles(new File("D:/MCubeRTV2.0/Source/java/com/velozglobal/mcube/agents")).each{file -&gt;&lt;br /&gt;    codeAnalyzer.analyzeFile(file)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-1507755089038692027?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/07/lot-of-times-when-i-sit-down-to-review.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-7053430091252053595</guid><pubDate>Mon, 06 Jul 2009 14:04:00 +0000</pubDate><atom:updated>2009-07-06T19:39:05.859+05:30</atom:updated><title>Eclipse templates for auto code generation</title><description>&lt;span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; line-height: 19px; white-space: pre-wrap; "&gt;Working with an IDE tends to make life quiet simple. However we still do not leverage the full potential of using an IDE like Eclipse. During development, i have found creating a few templates really helps to speed up things. Here are the few most common ones i use which are not part of the standard templates. 1) Log4J Logging&lt;br /&gt; a) Create Logger&lt;br /&gt; ${:import(org.apache.log4j.Logger)}&lt;br /&gt; private static final Logger logger = Logger.getLogger(${enclosing_type}.class);&lt;br /&gt; b) LogInfo&lt;br /&gt; logger.info(${word_selection}${});${cursor}&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; line-height: 19px; white-space: pre-wrap; "&gt;c) LogError&lt;br /&gt; logger.error(${errorMessage}, ${e});&lt;br /&gt; d) LogDebug&lt;br /&gt; if(logger.isDebugEnabled())&lt;br /&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; line-height: 19px; white-space: pre-wrap; "&gt;     logger.debug(${word_selection}${});${cursor}&lt;br /&gt; 2) Constants&lt;br /&gt; a) Const&lt;br /&gt; private static final ${type} ${name} = new ${type} ${cursor};&lt;br /&gt; 3) Map Iteration&lt;br /&gt; a) MapIter&lt;br /&gt; for(Map.Entry entry :&lt;br /&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; line-height: 19px; white-space: pre-wrap; "&gt;                    ${map:var(java.util.Map)}.entrySet()) {&lt;br /&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; line-height: 19px; white-space: pre-wrap; "&gt;    ${key} key = entry.getKey();  &lt;br /&gt;     ${value} value = entry.getValue(); &lt;br /&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; line-height: 19px; white-space: pre-wrap; "&gt;    ${cursor}  &lt;br /&gt; }   &lt;br /&gt; 4) JUnit&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; line-height: 19px; white-space: pre-wrap; "&gt;a) Test Creation&lt;br /&gt; public void test${name}() throws Exception {&lt;br /&gt;  ${cursor} &lt;br /&gt; } &lt;br /&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; line-height: 19px; white-space: pre-wrap; "&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-7053430091252053595?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/07/eclipse-templates-for-auto-code.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-4395043586948815007</guid><pubDate>Tue, 30 Jun 2009 06:54:00 +0000</pubDate><atom:updated>2009-06-30T12:50:51.786+05:30</atom:updated><title>Automate Unit Test Execution</title><description>A lot of times, when doing TDD, we make small refactorings and then have to manually go ahead and run the tests to figure out whether the changes we made are consistent and have not broken the tests.  Wouldn't it be good if the tests were run on each Save to ascertain that we have not broken any of the tests. This also lets us know which changes are the culprit. Using eclipse we can automate running the unit tests on each change and save we make. Following are the steps needed in order to accomplish this. &lt;div&gt;&lt;ol&gt;&lt;li&gt;Create a main class &lt;/li&gt;&lt;/ol&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;import junit.framework.TestSuite;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;import junit.textui.TestRunner; &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; public class TestBootstrap&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; { &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; public static void main(String[] args) &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;{ &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; TestSuite testSuite=new TestSuite();&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; testSuite.addTestSuite(TestClass.class); &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; TestRunner.run(testSuite); &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;} &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;2.  Create an ant build file&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;project&amp;gt; &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; &amp;lt;target name="eclipse-test-runner"&amp;gt; &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;java classname="TestBootstrap" classpath="bin:libs/junit.jar"&amp;gt; &amp;lt;java&amp;gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&amp;lt;/target&amp;gt; &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&amp;lt;/project&amp;gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;3. Create a Builder in eclipse&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(34, 34, 34); font-size: 14px; line-height: 23px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"   style="font-size:130%;color:#000000;"&gt;&lt;span class="Apple-style-span" style="font-size: 16px; line-height: normal;"&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Open project properties: Right click project -&gt; Propertie. Create new ant builder step after the Java Builder in eclipse: Builders -&gt; new -&gt; Ant Builder. Give your builder a nice name. &lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(34, 34, 34); font-size: 14px; line-height: 23px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Main: Select the build file and the base directory &lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(34, 34, 34); font-size: 14px; line-height: 23px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Targets: Select your ANT target for: “After Clean”, “Manual Build”, and “Auto Build” (most important)                Build Options: Check “Specify working set” and select all of your source folders.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-size:130%;color:#222222;"&gt;&lt;span class="Apple-style-span" style="font-size: 14px; line-height: 23px;"&gt;And thats all, now every time you save a file, eclipse will run the ant target specified in your build file, which incidentally calls your TestBootstrap's main and invoked all the tests.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;/span&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-4395043586948815007?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/06/automate-unit-test-execution.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-5548950116996759546</guid><pubDate>Mon, 15 Jun 2009 11:43:00 +0000</pubDate><atom:updated>2009-06-15T17:15:49.352+05:30</atom:updated><title>Reading an RSS feed in groovy</title><description>&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Here's a small script to read RSS feeds from any site using groovy. You can customize it to read from multiple feeds by feeding the url's from a file etc.&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;def url='http://feeds.dzone.com/dzone/frontpage'&lt;/div&gt;&lt;div&gt;def channel=new XmlParser().parse(url).channel[0]&lt;/div&gt;&lt;div&gt;println channel.title.text()&lt;/div&gt;&lt;div&gt;println channel.link.text()&lt;/div&gt;&lt;div&gt;println channel.description.text()&lt;/div&gt;&lt;div&gt;println '\nStories:\n---------'&lt;/div&gt;&lt;div&gt;def items=channel.item&lt;/div&gt;&lt;div&gt;for(item in items){&lt;/div&gt;&lt;div&gt;    println item.title.text()&lt;/div&gt;&lt;div&gt;    println item.link.text()&lt;/div&gt;&lt;div&gt;    println item.description.text()&lt;/div&gt;&lt;div&gt;    println'-------'&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-5548950116996759546?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/06/reading-rss-feed-in-groovy.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-8325868745396104462</guid><pubDate>Thu, 11 Jun 2009 13:01:00 +0000</pubDate><atom:updated>2009-06-11T18:47:53.390+05:30</atom:updated><title>Google Wave - A First look</title><description>I took a look at the presentation of &lt;a href="http://wave.google.com/"&gt;Google Wave&lt;/a&gt;, conducted by Lars Rasmussen and his technical team. Although its still in sandbox, it appears to be a very interesting product. The capabilities of what can be achieved in a browser are mind blowing. A very interesting point about Wave is that it would be open sourced. Primarily i think Google would need a lot of contributions from the community to really leverage the power which Wave promises.  Wave brings the power of IM and email together and adds a different dimension to it. An early release of the wave API's are available .So go ahead and get your hands dirty. The API's available are the extension API's for building wave gadgets, robots and the Embed API's.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-8325868745396104462?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/06/google-wave-first-look.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-5833986536308312789</guid><pubDate>Thu, 11 Jun 2009 12:45:00 +0000</pubDate><atom:updated>2009-06-11T18:30:10.506+05:30</atom:updated><title>Fan -- Another New Java</title><description>Fan has recently been doing the rounds and i spent some time looking at it. It appears to be pretty much in the same space as Scala in most aspects. A deeper look at Fan reveals some interesting points. Similarity with Scala is it runs on the vm, has both dynamic and static typing, closures, mixins are built in etc etc. However a few interesting features in Fan over and above these are&lt;br /&gt;1) Core support for the JVM, CLR and Javascript in the browser.&lt;br /&gt;2) No support for global variables&lt;br /&gt;3) Almost Erlang like concurrency semantics&lt;br /&gt;4) Types are non nullable by default&lt;br /&gt;5) Simpler namespaces and less verbose API's&lt;br /&gt;6) JSON like serialization&lt;br /&gt;On the while it appears has a groovy like simplicity with all the power of scala.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-5833986536308312789?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/06/fan-another-new-java.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-6067014861582414968</guid><pubDate>Wed, 03 Jun 2009 09:22:00 +0000</pubDate><atom:updated>2009-06-03T15:26:13.066+05:30</atom:updated><title>Proejct Euler Problem 1</title><description>Got to know about &lt;a href="http://projecteuler.net/"&gt;Project Eular.&lt;/a&gt;&lt;br /&gt;So thought about posting a few solutions using groovy. For the 1st problem, the solution is pretty simple&lt;br /&gt;&lt;br /&gt;def series3=0;&lt;br /&gt;def series5=0;&lt;br /&gt;def series15=0;&lt;br /&gt;0.step(1000,3){series3+=it}&lt;br /&gt;0.step(1000,5){series5+=it}&lt;br /&gt;0.step(1000,15){series15+=it}&lt;br /&gt;def result=series3 +series5 - series15&lt;br /&gt;&lt;br /&gt;&lt;a href="http://projecteuler.net/"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-6067014861582414968?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/06/proejct-euler-problem-1.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-7377030692523560485</guid><pubDate>Wed, 03 Jun 2009 06:03:00 +0000</pubDate><atom:updated>2009-06-03T11:46:33.990+05:30</atom:updated><title>Export Data from Flat files to database:The Groovy way</title><description>Recently i was supposed to port a lot of data from flat files into a database. Looking at alternatives i thought it would be neat to accomplish the same using a small groovy script. Here's the crux of the script&lt;br /&gt;&lt;br /&gt;def sql = groovy.sql.Sql.newInstance('jdbc:mysql://localhost:3306/test' ,&lt;br /&gt;'root', ' ', 'com.mysql.jdbc.Driver' )&lt;br /&gt;new File("C:/data/").eachFile{file-&gt;&lt;br /&gt;    file.eachLine{line-&gt;&lt;br /&gt;        def col1&lt;br /&gt;        def col2&lt;br /&gt;        def col3&lt;br /&gt;        def args=line.split(",")&lt;br /&gt;        if(args.length==3){&lt;br /&gt;            col1=args[0]&lt;br /&gt;            col2=args[1]&lt;br /&gt;            col3=args[2]&lt;br /&gt;            sql.execute"""&lt;br /&gt;                INSERT INTO table (col1, col2, col3)&lt;br /&gt;                VALUES (${col1}, ${col2}, ${col3});&lt;br /&gt;            """&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;input id="gwProxy" type="hidden"&gt;&lt;!--Session data--&gt;&lt;input onclick="jsCall();" id="jsProxy" type="hidden"&gt;&lt;div id="refHTML"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-7377030692523560485?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/06/export-data-from-flat-files-to.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-1419364311133394929</guid><pubDate>Wed, 22 Apr 2009 12:47:00 +0000</pubDate><atom:updated>2009-04-22T18:46:33.961+05:30</atom:updated><title>Unit Testing Recipes</title><description>A lot of times i tend to come across unit tests where the developer has to create a List and compare the equality of a returned List with some expected List. As an example consider the following test Case&lt;br /&gt;&lt;br /&gt;public void testResultsHasSameElements(){&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: justify;"&gt; List&lt;string&gt;()expectedResults=new ArrayList&lt;string&gt;();&lt;/string&gt;&lt;/string&gt;&lt;br /&gt;&lt;string&gt;&lt;string&gt; expectedResults.add("James");&lt;/string&gt;&lt;/string&gt;&lt;br /&gt;&lt;string&gt;&lt;string&gt; expectedResults.add("Jack"); &lt;/string&gt;&lt;/string&gt;&lt;br /&gt;&lt;/div&gt;&lt;string&gt;&lt;string&gt;&lt;/string&gt;&lt;/string&gt;&lt;/div&gt;&lt;string&gt;&lt;string&gt; List&lt;string&gt; customerNames=CustomerDTO.getCustomerNames();&lt;br /&gt;for(String name:customerNames){&lt;br /&gt;assertEquals(name,expectedResult.get(0));&lt;br /&gt;assertEquals(name,expectedResult.get(1));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If we look at the above testcase, it involves a lot of typing. We can simplify the above test using the fact that 2 Lists are equal if they contain the same objects at the same index. Another optimization which can be used is the Arrays.toList method to create the expectedResults list&lt;br /&gt;The improved version of the test would look like&lt;br /&gt;&lt;br /&gt;&lt;/string&gt;&lt;/string&gt;&lt;/string&gt;public void testResultsHasSameElements(){&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: justify;"&gt; List&lt;string&gt;()expectedResults=&lt;string&gt;Arrays.asList(&lt;br /&gt;new String[]{"James","Jack"}&lt;br /&gt;);&lt;/string&gt;&lt;/string&gt;&lt;br /&gt;&lt;string&gt;&lt;string&gt;&lt;/string&gt;&lt;/string&gt;&lt;/div&gt;&lt;/div&gt; customerNames=CustomerDTO.getCustomerNames();&lt;br /&gt;assertEquals(customerNames,expectedResult);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-1419364311133394929?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2009/04/unit-testing-recipes.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-2509470754715371638</guid><pubDate>Tue, 30 Sep 2008 05:24:00 +0000</pubDate><atom:updated>2008-09-30T11:37:40.297+05:30</atom:updated><title>Getting teams started quickly on projects</title><description>The ability to get teams started on a project is something that takes a lot of time and resources. A few ways to mitigate that and get teams to speed fast are&lt;br /&gt;1) Use Buildix(http://buildix.thoughtworks.com/) for setting up the infrastructure for the project like version control, continuous integration, agile project management and wiki and bug tracker. Buildix is open sourced under the apache license and automates setting up the basic infrastructure required fro the project. &lt;br /&gt;2) Use Panopticode(http://www.panopticode.org/) to setup tools for gathering code metrics. Panopticode provides customized build scripts to integrate tools like Emma, CheckStyle, JDepend,JavaNCSS, Simian etc. &lt;br /&gt;3) Use a VMWare mirror image to setup a developer box so as to remove any discrepancies across developer environments.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-2509470754715371638?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/09/getting-teams-started-quickly-on.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-8561252650728077152</guid><pubDate>Sun, 28 Sep 2008 06:23:00 +0000</pubDate><atom:updated>2008-09-28T12:28:52.570+05:30</atom:updated><title>Windows Shortcuts and useful tools for developers</title><description>Here are a list of windows shortcuts and tools which every developer should know to work effectively. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Firefox Shortcuts&lt;/span&gt;&lt;br /&gt;CTRL + number -- can be used to navigate between tabs in firefox. For example CTRL+1 gives the first tab,CTRL+2 gives the second tab etc.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Explorer Shortcuts&lt;/span&gt;  &lt;br /&gt;Alt+D -- leads to the address bar. The address bar as auto-completion like the tab in shells. &lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Command Prompt&lt;/span&gt;&lt;br /&gt;F7 key--shows the command history&lt;br /&gt;F8 key can be used to navigate across the history. Type the first few characters of the command and use the F8 key for auto-completion&lt;br /&gt;Use pushd and popd. When inside a directory, pushd can be used to navigate to another directory and popd can be used to get back to the other directory. These commands work like a stack(LIFO), so prefer these over the simple cd.&lt;br /&gt;&lt;br /&gt;Tools &lt;br /&gt;CLCL -- a multi-clipboard utility&lt;br /&gt;Command Prompt Explorer bar -- A sticky exlplorer-command prompt utility&lt;br /&gt;PowerToys&lt;br /&gt;Tweak UI&lt;br /&gt;TaskSwitch&lt;br /&gt;Virtual Desktop Manager&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-8561252650728077152?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/09/windows-shortcuts-and-useful-tools-for.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-1723906925440351889</guid><pubDate>Thu, 28 Aug 2008 08:45:00 +0000</pubDate><atom:updated>2008-08-28T14:17:11.106+05:30</atom:updated><title>Software Architecture Structures</title><description>This post talks about the &lt;span style="font-weight:bold;"&gt;Software Architecture Structures&lt;/span&gt;, and how these structures relate in the creation of an architecture. Software Architecture Structures can be divided into 3 broad categories&lt;br /&gt;&lt;br /&gt;1) Modules&lt;br /&gt;&lt;br /&gt;2) Component and Connectors&lt;br /&gt;&lt;br /&gt;3) Allocations&lt;br /&gt;&lt;br /&gt;1) Modules -- These are the units of implementation. These represent code based views of the system. The intent here is not related to any runtime considerations. Module based structures can be further sub-divided into&lt;br /&gt;&lt;br /&gt;   1. Decomposition --The units addressed here are that of submodules of a particular module. The intent is to break modules into smaller units such that each unit can be understood. This normally is the starting point of high level design and subsequent low level design. It also incorporates things like implementations, test plans etc. In addition a decomposition can also address questions related to changes made to the system. The intent should be to keep the changes local to a few sub-modules.&lt;br /&gt;   2. Uses -- One unit uses another if the correctness of one depends on the existence of the correct version of another. The uses structure can be used to extend the capabilities of a system as well as extract subsets of functionality which can be used for incremental development&lt;br /&gt;   3. Layered -- When the Uses structure is carefully modeled, normally layers emerge. These layers are areas of common functionality. Layered structures can be used to assess the dependence of one layer on the other as well as ensuring that the interactions of one layers are only with the layers above or below this layer. In addition, a layer at n should only depend for services on the n-1 layer and none other.&lt;br /&gt;   4. Class or Generalization -- The units in this structure are classes. Classes can be used to reason about collection of similar behavior or capabilities. Class structures is used for assessing reuse and incremental addition of functionality.&lt;br /&gt;&lt;br /&gt;2) Components and Connectors --Component-and-connector structures help answer questions such as What are the major executing components and how do they interact? What are the major shared data stores? Which parts of the system are replicated? How does data flow through the system? What parts of the system can run in parallel? How can the system's structure change as it executes? These can be further sub-divided into&lt;br /&gt;&lt;br /&gt;   1. Processes --The process structure shows processes connected to each other through connectors, snychronizers,exclusions etc. This structure is important when looking at a systems performance and availibility.&lt;br /&gt;   2. Concurrency -- This structure allows for determining the areas where there can be a resource contention or where parallelism can be employed.&lt;br /&gt;   3. Shared data -- This comprises connectors and components that create,store or access shared persistent data. It shows how data is produced and consumed by the runtime components and can be used to ensure performance and data integrity.&lt;br /&gt;   4. Client -Server -- This structure shows the components as client server units and the connectors are the underlying protocols which are used for communication.&lt;br /&gt;&lt;br /&gt;3) Allocation Structures -- This structure shows the relation between the software elements and the environment in which the software executes. These can be classified as follows&lt;br /&gt;&lt;br /&gt;   1. Deployment -- The deployment structure shows how software is assigned to hardware-processing and communication elements. The elements are software, hardware entities and communication pathways. Relations are allocated-to, showing on which physical units the software elements reside. This view allows one to reason about performance, data integrity, availability, and security.&lt;br /&gt;   2. Implementation --This structure shows how usually modules are mapped to the file structure in the system's development, integration, or configuration environments. This is critical for the management of development activities and build processes&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-1723906925440351889?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/08/software-architecture-structures.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-227014183399049967</guid><pubDate>Wed, 23 Jul 2008 10:48:00 +0000</pubDate><atom:updated>2008-07-23T16:30:05.638+05:30</atom:updated><title>Kickstarting your day  and honing your development skills</title><description>As per various studies conducted, it has been shown that developers tend to take at least an hour or more to get into the zone, where they are most productive. There are various ways which have been suggested like writing unit tests at the start if the day,etc. to get into the zone. Being a pragmatic programmer, i have found something which has helped me kick-start my day and get into the zone in the minimum time possible. The following recipe has done wonders for me. &lt;br /&gt;At the start of the day, i take up a puzzle and spend 5-10 minutes in analyzing and solving it. Be aware the intent is not to come to a solution, but just to get the gray cells kicking. After this i normally try some programming problem, albeit a simple one using a new language which i am trying to acquire. I spend another 20-30 minutes in solving the problem. The problem could be as simple as trying to find a repeated integer in a list of otherwise unique sequential numbers. Getting these two activities at the start of the day has two-fold advantages. One it focuses the brain and secondly it helps me acquire a new skill. I have even tried using this after prolonged meetings just to get back into the zone. However a word of caution, the intent is not to get to perfection, but to time-box the effort. You can get back to the problems again the next day if you are stuck on something.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-227014183399049967?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/07/kickstarting-your-day-and-honing-your.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-5517877032580317975</guid><pubDate>Sun, 22 Jun 2008 15:06:00 +0000</pubDate><atom:updated>2008-06-22T21:53:42.370+05:30</atom:updated><title>Regular Expressions Part 2</title><description>This entry continues the discussion regarding regular expressions from the previous post(&lt;a href="http://indianopensource.blogspot.com/2008/06/regular-expressions-part-1.html"&gt;Regular Expression part 1&lt;/a&gt;). We continue with a discussion of the rich meta-characters available.  In this post i will take up some of the other meta-characters and discussion their usage. The pattern followed is the same as the previous post with some exercises thrown in for good measure.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Optional Items -- Suppose we wanted to search for the word June, which could be represented as either &lt;span style="font-style: italic;"&gt;June  &lt;/span&gt;or &lt;span style="font-style: italic;"&gt;Jun. &lt;/span&gt;The &lt;span style="font-style: italic;"&gt;? &lt;/span&gt;meta-character means optional. So the search could be accomplished using &lt;span style="font-style: italic;"&gt;June?&lt;/span&gt;. This can be interpreted as match &lt;span style="font-style: italic;"&gt;J, &lt;/span&gt;then &lt;span style="font-style: italic;"&gt;u then &lt;/span&gt;&lt;span style="font-style: italic;"&gt;n&lt;/span&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;followed by &lt;span style="font-style: italic;"&gt;e &lt;/span&gt;if its there. So the &lt;span style="font-style: italic;"&gt;? &lt;/span&gt;is placed after the character that is allowed to appear at that point in the regular expression, but the existence isn't required to consider it a successful match. Expanding on the same lets say we have to match &lt;span style="font-style: italic;"&gt;June 5th, &lt;/span&gt;which can occur as &lt;span style="font-style: italic;"&gt;Jun 5, June 5th, &lt;/span&gt;or &lt;span style="font-style: italic;"&gt;fifth. &lt;/span&gt;To match the following we can use &lt;span style="font-style: italic;"&gt;(June|Jun)&lt;/span&gt;.&lt;span style="font-style: italic;"&gt;(5|5th|fifth). &lt;/span&gt;The first expression can be simplified as &lt;span style="font-style: italic;"&gt;(June?) &lt;/span&gt;and the second one as &lt;span style="font-style: italic;"&gt;fifth|5(th)?.&lt;/span&gt; Hence the complete expression can be re-written as &lt;span style="font-style: italic;"&gt;June?.(fifth|5(th)?). &lt;/span&gt;One point here is that although there are different alternatives, choosing the right one needs some thought and introspection. &lt;/li&gt;&lt;li&gt;Repetition -- The &lt;span style="font-style: italic;"&gt;+ &lt;/span&gt;and * meta-characters are used for checking for repetition. &lt;span style="font-style: italic;"&gt;+&lt;/span&gt; implies one or more of the preceding character and * implies any number including none of the item. Thus + fails if there are none of the characters but succeeds for one or many, * on the other hand always succeeds. As an example, to match spaces, one can use &lt;span style="font-style: italic;"&gt;. ? &lt;/span&gt;which would match a single optional space, . + would match any number of spaces with at least one space and . * would match any number of spaces, if present. Lets take another example, where we have to search for the html tag &lt;span style="font-style: italic;"&gt;&amp;amp;lt;hr size="10"&amp;amp;gt;&lt;/span&gt;. To build the regular expression, we need to have&lt;, then &lt;span style="font-style: italic;"&gt;HR &lt;/span&gt;followed by one or more spaces(allowed as per the semantics of html), followed by zero or more spaces, followed by &lt;span style="font-style: italic;"&gt;= &lt;/span&gt;followed by zero or more spaces the number 10 , again zero or more spaces followed by &lt;span style="font-style: italic;"&gt;&gt;.  &lt;/span&gt;Based on our discussion so far, this should be simple, &lt;hr.&gt; Now lets try and generalise this to any size, not just 10, so the regular expression would look like &lt;hr.&gt;  For case insensitive search using egrep, we can use the -i option.&lt;br /&gt;&lt;/hr.&gt;&lt;/hr.&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-style: italic;"&gt;Exercise -- Write a regular expression for the same examplem as above, where the size attribute is optional e.i a simple &lt;hr /&gt; is a legal match.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;Back References -- Many tools provide the ability for parentheses to remember text matched by the sub-expression they invoke. So as an example, ([a-z])([0-9])\1\2, \1 refers to the text matched by [a-z] and \2 refers text matched by [0-9]. We will see examples of using back-referencing in following posts.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Escapting Meta-characters -- In order to escape meta-characters, we can use \ to escape the meta-character.  For example if we tried to match &lt;span style="font-style: italic;"&gt;att.com&lt;/span&gt;, it could end up matching something like &lt;span style="font-style: italic;"&gt;watt company. &lt;/span&gt;So we need to escape the meta-character . , this can be done using &lt;span style="font-style: italic;"&gt;att&lt;/span&gt;\.com. This escapes the meta-character and treats the meta-character . like a normal character&lt;/li&gt;&lt;/ul&gt; This covers some of the most important meta-characters. In future posts i would expand on these fundamentals and show how applying regular expressions makes life simpler.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-5517877032580317975?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/06/regular-expressions-part-2.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-3813463289262444093</guid><pubDate>Fri, 20 Jun 2008 10:46:00 +0000</pubDate><atom:updated>2008-06-20T17:18:30.928+05:30</atom:updated><title>Regular Expressions Part 1</title><description>I have been a great fan of using regular expressions for solving day to day tasks. I thought it was time to post a series for discussing the use and syntax of regular expressions. In this post i will talk  about some simple meta-characters and their uses with tools like egrep/grep.  In addition i will try and set some small exercises to practice the understanding of the readers.&lt;br /&gt;&lt;br /&gt;A regular expression is composed of a set of meta-characters like *, ^ etc and a set of literal characters like A-Z, a-z, 0-9  etc. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Some Simple Meta-characters&lt;br /&gt;&lt;/span&gt;Let us start with a some simple meta-characters and how we can apply these to various scenario's. The &lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;^ &lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;- The Caret/Anchor is one of the simplest meta-characters and represents the start of the line which is being checked. For example ^cat would match all lines which start with the literal cat like catalog&lt;br /&gt;&lt;/li&gt;&lt;li&gt;$ - The dollar meta-character represents the end of the line which is being checked. So cat$ would match all lines which end with the literal characters cat, for example scat.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;    These 2 meta-characters are unique in the sense that they match a  position rather than the actual literal characters themselves.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Exercise -- What would ^cat$, ^$ and ^ match ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Character Class -- The meta-character [...] called the character class lets you list the characters you want to allow at that point of match. For example &lt;span style="font-style: italic;"&gt;e &lt;/span&gt;matches just &lt;span style="font-style: italic;"&gt;e , a &lt;/span&gt;matches just &lt;span style="font-style: italic;"&gt;a&lt;/span&gt;, however [ea] would match both &lt;span style="font-style: italic;"&gt;e &lt;/span&gt;or &lt;span style="font-style: italic;"&gt;a. &lt;/span&gt;Thus the implied meaning is that of OR. Suppose you wanted to check whether you have spelt &lt;span style="font-style: italic;"&gt;grey &lt;/span&gt;or &lt;span style="font-style: italic;"&gt;gray&lt;/span&gt;. The following regular expression would match the occurance of both &lt;span style="font-style: italic;"&gt;gr[ea]y&lt;/span&gt;. This matches &lt;span style="font-style: italic;"&gt;g  &lt;/span&gt;follows by &lt;span style="font-style: italic;"&gt;r &lt;/span&gt;followed by either &lt;span style="font-style: italic;"&gt;e &lt;/span&gt;or &lt;span style="font-style: italic;"&gt;a&lt;/span&gt; followed by &lt;span style="font-style: italic;"&gt;y&lt;/span&gt;. The - operator within a character class matches a range, so [0-9A-Z] matches occurances of  numbers and capital letters. For example &lt;h[1-6]&gt;] would help you while searching headers in html documents. The - is special inside a character class, otherwise it is used as a normal character and not as a range.&lt;/li&gt;&lt;li&gt;Negated Character classes -- A ^ inside a character class negates the matches. For example [^a-z] would match any character which is not &lt;span style="font-style: italic;"&gt;a &lt;/span&gt;through &lt;span style="font-style: italic;"&gt;z&lt;/span&gt;.  Remember a negated character class means &lt;span style="font-weight: bold;"&gt;match a character thats not listed&lt;/span&gt; and not &lt;span style="font-weight: bold;"&gt;don't match whats listed&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;    Exercise -- Figure out all words in a dictionary which contain a &lt;span style="font-style: italic;"&gt;q  &lt;/span&gt;not followed by a &lt;span style="font-style: italic;"&gt;u&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;    Matching Any character with dot -- this is simpler to explain with an example. Suppose you want to find a date 26/02/1977, which can also be represented as 26-02-1977 or even 26.02.1977. Not the . character can be used to match any character. So seemingly, 26.02.1977 should return us the date however it be represented, maybe with a - or a /. However, the above would also match a random number like 12264023197734. This is because the dot character matches any character. The correct way to do so would be to use something like 26[-./]02[-./]1977 (Note, the - is this case would not be a meta-character, since it immediately follows the [, if the same was written as [.-/], then it would become the range meta-character, also the .  is not treated as a meta-character since it is inside the character class)&lt;/li&gt;&lt;li&gt;Matching any one of several sub-expressions -- The | (OR) operator lets you combine expressions into a single expression, that matches any of the individual ones. For example, based on the previous examples, we can rewrite &lt;span style="font-style: italic;"&gt;gr[ea]y&lt;/span&gt; as  &lt;span style="font-style: italic;"&gt;gr(e|a)y&lt;/span&gt;. (Note-- we cannot use something like &lt;span style="font-style: italic;"&gt;gr[e|a]y  &lt;/span&gt;as inside the character class, | is treated as a normal character). We need the parenthesis because &lt;span style="font-style: italic;"&gt;gre|ay &lt;/span&gt;would mean &lt;span style="font-style: italic;"&gt;gre &lt;/span&gt;or &lt;span style="font-style: italic;"&gt;ay.&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Exercises 1) How does &lt;span style="font-style: italic;"&gt;gr[ea]y &lt;/span&gt;differ from &lt;span style="font-style: italic;"&gt;gr(e|a)y ?&lt;br /&gt;                      &lt;/span&gt;2) What is the difference between &lt;span style="font-style: italic;"&gt;^:List|Of|Books: &lt;/span&gt;from &lt;span style="font-style: italic;"&gt;^(List|Of|Books): ?&lt;br /&gt;&lt;/span&gt;Note&lt;span style="font-style: italic;"&gt; -- &lt;/span&gt;Tools like egrep provide switches for case-insensitive searches. For egrep -i performs a case insensitive search.&lt;br /&gt;Example -- egrep -i '^(Subject|Predicate):'  myfile.txt&lt;br /&gt;This serves as a good groundwork for someone wanting to start using regular expressions. I will be following up the post with detailed topics. Till then, cheers and keep the faith.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-3813463289262444093?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/06/regular-expressions-part-1.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-3236494819349625370</guid><pubDate>Thu, 19 Jun 2008 06:28:00 +0000</pubDate><atom:updated>2008-06-19T14:01:36.866+05:30</atom:updated><title>The Art of analysis and problem solving</title><description>I have been wondering about the art of analysis and problem solving and decided to do a writeup using an example. A lot of developers tend to jump to writing code and never seem to bother about thinking out their solutions. For them if it works its fine. Moving away from this is a pre-requisite for anyone who wants to hone his development skills. In order to convey my point, i take up a seemingly simple example which displays how to analyze a solution before implementing it.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Problem&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;Statement&lt;br /&gt;&lt;br /&gt;Write a function which removes a set of characters from a given String. The signature of the function should be as follows&lt;br /&gt;&lt;br /&gt;public String removeCharsFromString(String source, String remove)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Problem Analysis&lt;br /&gt;&lt;/span&gt;The problem involves the following 2 steps&lt;br /&gt;1) For each character in source, determine whether it needs to be deleted&lt;br /&gt;2) Delete the character&lt;br /&gt;&lt;br /&gt;Lets start with the actual deletion process first.   You have to remove an element from an array. An array is a contiguous block of memory, so you cant remove an element from the middle as can be done with a linked list. So you have to rearrange the elements to maintain it as a contiguous block. For example if you need to remove &lt;span style="font-style: italic;"&gt;c  &lt;/span&gt;from an array containing &lt;span style="font-style: italic;"&gt;abcd &lt;/span&gt;, you have to rearrange the elements. So you can either shift &lt;span style="font-style: italic;"&gt;ab &lt;/span&gt;up or shift &lt;span style="font-style: italic;"&gt;d &lt;/span&gt;down.  In addition you need to decrease the size of the string by one.&lt;br /&gt;&lt;br /&gt;Now how would the proposed algorithm work if you had to delete all elements from the source string. If the String is n characters long, this would mean shifting the last element by n-1, the second last by n-2 and so on, giving the worst time ass O(n^2).&lt;br /&gt;&lt;br /&gt;How can we avoid this. What if you allocated a temporary string buffer and built your  modified string there instead of in place? Then you could simply copy the  characters you need to keep into the temporary string, skipping the characters  you want to delete. When you finish building the modified string, you can copy  it from the temporary buffer back into &lt;span class="fixed"&gt;str&lt;/span&gt;. This way,  you move each character at most twice, giving O(&lt;i class="emphasis"&gt;n&lt;/i&gt;)  deletion. However, you’ve incurred the memory overhead of a temporary buffer the  same size as the original string, and the time overhead of copying the modified  string back over the original string. Is there any way you could avoid these  penalties while retaining your O(&lt;i class="emphasis"&gt;n&lt;/i&gt;) algorithm? &lt;p class="para"&gt;To implement the O(&lt;i class="emphasis"&gt;n&lt;/i&gt;) algorithm just  described, you need to track a source position for the read location in the  original string and a destination position for the write position in the  temporary buffer. These positions both start at zero. The source position is  incremented every time you read, and the destination position is incremented  every time you write. In other words, when you copy a character you increment  both positions, but when you delete a character you increment only the source  position. This means the source position will always be the same as or ahead of  the destination position. Once you read a character from the original string  (that is, the source position has advanced past it), you no longer need that  character - in fact, you’re just going to copy the modified string over it.  Because the destination position in the original string is always a character  you don’t need anymore, you can write directly into the original string,  eliminating the temporary buffer entirely. This is still an O(&lt;i class="emphasis"&gt;n&lt;/i&gt;) algorithm, but without the memory and time overhead of the  earlier version.&lt;/p&gt;Now to the actual part of deciding  whether  a character needs to be deleted.  The easiest way is to compare all characters in the remove string with  all the characters in the source string. If the size of the source string is n and the size of the remove string is m, this entails a running time of O(nm).  How can we reduce this to a running time of O(m).&lt;br /&gt;&lt;br /&gt;If we construct an array or a hashtable which has a constant time lookup, we can reduce the running time to O(m).&lt;br /&gt; Lets construct an array containing all Booleans which is indexed by all the possible values of the characters in the source string. This enables you to determine whether a character is in remove by checking a single element.&lt;br /&gt;&lt;br /&gt;Now the function will have 3 parts&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Set all elements in the lookup array to false&lt;/li&gt;&lt;li&gt;Iterate through each element in remove, setting the corresponding value in the lookup array to true&lt;/li&gt;&lt;li&gt;Iterate through &lt;span class="fixed"&gt;str&lt;/span&gt; with a source and destination  index, copying each character only if its corresponding value in the lookup  array is &lt;span class="fixed"&gt;false&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;Now if we combine all the operations, the running time would be O(n+m) which is still linear.&lt;br /&gt;&lt;br /&gt;Now lets take a look at the code&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;public String removeCharOccurances(String source,String remove){&lt;br /&gt;        char[] sourceArr = source.toCharArray();&lt;br /&gt;        char[] removeArr = remove.toCharArray();&lt;br /&gt;        boolean[] flags = new boolean[128]; // assumes ASCII!&lt;br /&gt;        int    len = sourceArr.length;&lt;br /&gt;        int len1=removeArr.length;&lt;br /&gt;        int    src, dst;&lt;br /&gt;&lt;br /&gt;        // Set flags for characters to be removed&lt;br /&gt;        for( src = 0; src &lt; len1; ++src ){&lt;br /&gt;            flags[removeArr[src]] = true;&lt;br /&gt;        }&lt;br /&gt;        src = 0;&lt;br /&gt;        dst = 0;&lt;br /&gt;&lt;br /&gt;        // Now loop through all the characters,&lt;br /&gt;        // copying only if they aren't flagged&lt;br /&gt;        while( src &lt; len ){&lt;br /&gt;            if( !flags[ (int)sourceArr[src] ] ){&lt;br /&gt;                sourceArr[dst++] = sourceArr[src];&lt;br /&gt;            }&lt;br /&gt;            ++src;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return new String( sourceArr, 0, dst );&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-3236494819349625370?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/06/art-of-analysis-and-problem-solving.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-8950953221658970083</guid><pubDate>Wed, 18 Jun 2008 08:34:00 +0000</pubDate><atom:updated>2008-06-18T15:22:39.766+05:30</atom:updated><title>REST-ful services using JAX-WS 2.0</title><description>REST style services conform to a set of constraints and architectural principles&lt;br /&gt;&lt;ul&gt;&lt;li&gt;    RESTful services are stateless. Each request from a client to a server must contain  all the information necessary to understand the request and must not depend on any stored contextual information on the server.    &lt;/li&gt;&lt;li&gt;    REST-ful services have a uniform interface. For example for a RESTful HTTP service, the    operation supported are GET, POST, PUT and DELETE.&lt;/li&gt;&lt;li&gt;    REST based architectures are built from resources which are identified by unique URI's.&lt;/li&gt;&lt;li&gt;    REST components manipulate resources by exchanging representations of the resources. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;The fundamental differences between REST and RPC based services can be outlined as&lt;br /&gt;&lt;ul&gt;&lt;li&gt;     RPC services work by invoking a procedure on a server rather than by exchanging representations of a resource.&lt;/li&gt;&lt;li&gt;     In the RPC approach typically many  operations are invoked at the same URI,  which is fundamentally different from the  REST way where every resource has a  unique URI.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;table align="center" bgcolor="#e2f4fe" border="0" cellpadding="0" cellspacing="0" width="815"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;tr&gt;&lt;br /&gt; &lt;td align="center"&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;tbody&gt;&lt;tr&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;RESTful vs SOAP based services&lt;/span&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr style="color: rgb(51, 102, 255);"&gt;&lt;br /&gt;Message Format &lt;td&gt;XML&lt;/td&gt; &lt;td&gt;XML inside a SOAP envelope&lt;/td&gt;   &lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr style="color: rgb(51, 102, 255);"&gt;&lt;br /&gt;Interface Definition &lt;td&gt;none&lt;/td&gt; &lt;td&gt;WSDL&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr style="color: rgb(51, 102, 255);"&gt;&lt;br /&gt;Transport &lt;td&gt;HTTP&lt;/td&gt; &lt;td&gt;HTTP,FTP,MIME,JMS,SMTP etc &lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;In order to consume a RESFful service using JAX-WS 2.0, the majority of the work needs to be done using the javax.xml.ws.Dispatch&lt;t&gt; interface.  The javax.ws.xml.Service interface is the abstraction which provides the client interface to a web service. Since RESTful services do not have WSDL representations, the way to deal is a bit awkward, however that is the way JAX-WS has been designed. We use the Service interface to create an instance of the javax.xml.ws.Dispatch interface. Dispatch is a low level API which allows users to create messages by working directly with XML rather than using high level API's like JAXB etc.&lt;br /&gt;&lt;br /&gt;The following code displays the basics and is discussed below&lt;br /&gt;&lt;br /&gt;  QName svcQName = new QName("http://xyz", "svc");&lt;br /&gt;   QName portQName = new QName("http://xyz", "port");&lt;br /&gt;   Service svc = Service.create(svcQName);&lt;br /&gt;   svc.addPort(portQName, HTTPBinding.HTTP_BINDING, args[0]);&lt;br /&gt;   Dispatch&lt;source&gt; dis =&lt;br /&gt;     svc.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);&lt;br /&gt;   Map&lt;string,&gt; requestContext = dis.getRequestContext();&lt;br /&gt;   requestContext.put(MessageContext.HTTP_REQUEST_METHOD, "GET");&lt;br /&gt;   Source result = dis.invoke(null);&lt;br /&gt;   try {&lt;br /&gt;     TransformerFactory.newInstance().newTransformer()&lt;br /&gt;     .transform(result, new StreamResult(System.out));&lt;br /&gt;   } catch (Exception e) {&lt;br /&gt;     throw new IOException(e.getMessage());&lt;br /&gt;   }&lt;br /&gt;   The web service url is as a command line argument(arg[0])&lt;br /&gt;&lt;/string,&gt;&lt;/source&gt;&lt;/t&gt;&lt;ul&gt;&lt;li&gt;The client uses the Service.addPort() method to create a port within the Service instance that can be used to access the RESTful Web service.&lt;/li&gt;&lt;li&gt;Next, the Service.createDispatch() method is invoked to create an instance of Dispatch&lt;source&gt;—a Dispatch instance that enables you to work with XML request/response messages as instances of javax.xml.transform.Source.&lt;/source&gt;&lt;/li&gt;&lt;li&gt; The Dispatch.invoke() method then packages the XML request—per the JAX-WS 2.0 HTTP Binding—and sends it to the RESTful service. The invoke() method waits for the response before returning.&lt;/li&gt;&lt;li&gt;The service processes the HTTP GET and sends an HTTP response that includes the XML.&lt;/li&gt;&lt;li&gt;The invoke() method returns the response XML message as an instance of Source.&lt;/li&gt;&lt;/ul&gt;The addPort() method takes a URI parameter that defines the transport binding. The default is SOAP over HTTP but for RESTful services we use the HTTPBinding.HTTP_BINDING.  The type of payload is specified in the createDispatch() method. Generally when passing SOAP messages, Service.Mode.MESSAGE is used to indicate that you want to work with the complete SOAP envelope as opposed to just the SOAP body(PAYLOAD). In case of RESTful services since there is no enveloper, PAYLOAD mode is used.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-8950953221658970083?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/06/rest-ful-services.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-2901707908978521687</guid><pubDate>Thu, 12 Jun 2008 09:13:00 +0000</pubDate><atom:updated>2008-06-12T14:56:19.679+05:30</atom:updated><title>Pair Programming</title><description>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_EP7lRcluMNE/SFDp5t_fZ_I/AAAAAAAAALo/ZZ4FoEhx8fo/s1600-h/iphone+124.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_EP7lRcluMNE/SFDp5t_fZ_I/AAAAAAAAALo/ZZ4FoEhx8fo/s320/iphone+124.jpg" alt="" id="BLOGGER_PHOTO_ID_5210921946675374066" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;                                           Kick-start the day by writing a unit test, just to get the grey cells working&lt;br /&gt;     &lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_EP7lRcluMNE/SFDpCzOxjZI/AAAAAAAAALY/9mGXlb5e6Ag/s1600-h/iphone+084.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_EP7lRcluMNE/SFDpCzOxjZI/AAAAAAAAALY/9mGXlb5e6Ag/s320/iphone+084.jpg" alt="" id="BLOGGER_PHOTO_ID_5210921003188850066" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;   &lt;br /&gt;                                                                                                                                                                                                                             Getting down to serious stuff.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_EP7lRcluMNE/SFDqXsIaOJI/AAAAAAAAALw/KQ8BInq8WqI/s1600-h/iphone+087.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_EP7lRcluMNE/SFDqXsIaOJI/AAAAAAAAALw/KQ8BInq8WqI/s320/iphone+087.jpg" alt="" id="BLOGGER_PHOTO_ID_5210922461571987602" border="0" /&gt;&lt;/a&gt;                                                                                                                                                                This isnt making a lot of sense, is it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;             &lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_EP7lRcluMNE/SFDq3bn6TeI/AAAAAAAAAL4/lH8vPTYnRc0/s1600-h/iphone+102.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_EP7lRcluMNE/SFDq3bn6TeI/AAAAAAAAAL4/lH8vPTYnRc0/s320/iphone+102.jpg" alt="" id="BLOGGER_PHOTO_ID_5210923006896524770" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;                                                                                                   Getting some tips from the senior partner&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_EP7lRcluMNE/SFDrVh42l1I/AAAAAAAAAMA/otEhvneD1IE/s1600-h/iphone+119.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_EP7lRcluMNE/SFDrVh42l1I/AAAAAAAAAMA/otEhvneD1IE/s320/iphone+119.jpg" alt="" id="BLOGGER_PHOTO_ID_5210923523974272850" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;       See that wasn't so difficult was it.                   &lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-2901707908978521687?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/06/pair-programming.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_EP7lRcluMNE/SFDp5t_fZ_I/AAAAAAAAALo/ZZ4FoEhx8fo/s72-c/iphone+124.jpg" height="72" width="72" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-5561712966409331919</guid><pubDate>Tue, 03 Jun 2008 10:32:00 +0000</pubDate><atom:updated>2008-06-03T16:05:59.548+05:30</atom:updated><title>Light weight java game library</title><description>Being a server side guy, i decided it was time to do a bit of game programming as a challenge.  I  have started looking at LWJGL (Light Weight Java Game Library) which can interface  with libraries like OpenGL and OpenAL. Still need to come up with a concept to start using it for developing a prototype, but time i did something different.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-5561712966409331919?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/06/light-weight-java-game-library.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-8515188305961278764</guid><pubDate>Fri, 30 May 2008 09:58:00 +0000</pubDate><atom:updated>2008-05-30T16:12:53.846+05:30</atom:updated><title>new java puzzlers (As presented in Javapolis --2007)</title><description>Just to flex your java muscles here are some java puzzlers -- taken from the javapolis 2007 session by neal gafter and josh bloch&lt;br /&gt;&lt;br /&gt;1) Set of Shorts (hehehe)&lt;br /&gt;&lt;br /&gt;public class ShortSet {&lt;br /&gt;   public static void main(String[] args) {&lt;br /&gt;       Set&lt;short&gt;shortSet=new HashSet&lt;short&gt;();&lt;br /&gt;       for(short i=0;i&lt;100;i++){&lt;br /&gt;           shortSet.add(i);&lt;br /&gt;           shortSet.remove(i-1);&lt;br /&gt;       }&lt;br /&gt;       System.out.println("Size of Set =" + shortSet.size()) ;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;The choices are&lt;br /&gt;1)1&lt;br /&gt;2)100&lt;br /&gt;3) Throws an exception&lt;br /&gt;4) None of the above&lt;br /&gt;&lt;br /&gt;2)Racy little number&lt;br /&gt;&lt;br /&gt;public class Test extends TestCase {&lt;br /&gt;   int number;&lt;br /&gt;   public void test()throws InterruptedException{&lt;br /&gt;       number=0;&lt;br /&gt;       Thread t=new Thread(new Runnable(){&lt;br /&gt;           public void run(){&lt;br /&gt;               assertEquals(2, number);&lt;br /&gt;           }&lt;br /&gt;       });&lt;br /&gt;       number=1;&lt;br /&gt;       t.start();&lt;br /&gt;       number++;&lt;br /&gt;       t.join();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;What is the outcome of this test&lt;br /&gt;1) Passes Sometimes&lt;br /&gt;2)Fails Sometimes&lt;br /&gt;3)Always passes&lt;br /&gt;4) Always hangs&lt;/short&gt;&lt;/short&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-8515188305961278764?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/05/8-new-java-puzzlers-as-presented-in.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-2990860068056537778</guid><pubDate>Mon, 26 May 2008 05:27:00 +0000</pubDate><atom:updated>2008-05-26T11:12:23.042+05:30</atom:updated><title>How to derail your experts and ruin their performance</title><description>Its very simple, force them to follow rules. Experts draw a lot based on their experience and intuition as opposed to novices who need a set of rules which tells them what to do exactly to finish the task at hand, like filling your tax return forms(i never figured that out, just follow whats written there). Any corporate/methodology which follows iron clad rules for development tends to pull the experts down and drags their performance to a novice level. The industry tends to ruin experts often in this way. We can say that they are trying to herd racehorses, rather than racing them. Intuition is a tool to an expert, but organizations discount it saying its not scientific/repeatable etc. Conversely, we also tend to take novices and throw them in the&lt;br /&gt;deep end of the development pool—far over their heads. Here we’re trying to race sheep. A misguided sense of political correctness tends to treat all developers the same way, irrespective of the fact that there is a 20:1 to 40:1 in the productivity of the developers.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-2990860068056537778?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/05/how-to-derail-your-experts-and-ruin.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-2897943670245431235</guid><pubDate>Mon, 26 May 2008 05:16:00 +0000</pubDate><atom:updated>2008-05-26T10:49:59.258+05:30</atom:updated><title>Living out of the box</title><description>I managed to read the book from the Arbinger institute related to living out of the box(cant remember the name of the book). Seems a similar concept to the one proposed by psychologists Kruger and Dunning in their paper &lt;span style="font-style: italic;"&gt;Unskilled and Unaware of it:How difficulties in recognizing one's own incompetence leads to Inflated Self Assessment.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-2897943670245431235?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/05/living-out-of-box.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-5673356262328679237</guid><pubDate>Mon, 26 May 2008 05:00:00 +0000</pubDate><atom:updated>2008-05-26T10:35:17.374+05:30</atom:updated><title>The Dreyfus model</title><description>Developed by two brothers who were interested in AI, the Dreyfus model has been used successfully in different areas for developing skills and understanding how to transition from  novice to an expert. Rather than analyzing something as a whole, it treats things on a per skill level. For example, someone might be a novice cook but be great at playing tennis.  Interesting concept and worth reading, researching and applying.&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-5673356262328679237?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/05/dreyfus-model.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4953895613784667233.post-750728598094490833</guid><pubDate>Fri, 23 May 2008 09:56:00 +0000</pubDate><atom:updated>2008-05-23T15:42:41.994+05:30</atom:updated><title>The bane of java exceptional handling</title><description>&lt;span style="font-family: arial;"&gt;Exception handling should be fail safe. What it implies is that the last exception which is thrown should be propagated up the call stack. However taking a look at a simple example shows how complicated exceptional handling can be. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Lets take a scenario of the following block of code where we are trying to open a file&lt;/span&gt;&lt;br /&gt;&lt;pre style="font-family: arial;" class="codeBox"&gt;InputStream input = null;&lt;br /&gt;&lt;br /&gt; try{&lt;br /&gt;&lt;br /&gt;   input = new FileInputStream("myFile.txt");&lt;br /&gt;&lt;br /&gt;   //do something with the stream&lt;br /&gt;&lt;br /&gt; } catch(IOException e){&lt;br /&gt;   throw new WrapperException(e);&lt;br /&gt; } finally {&lt;br /&gt;   try{&lt;br /&gt;    input.close();&lt;br /&gt;   } catch(IOException e){&lt;br /&gt;      throw new WrapperException(e);&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;Now suppose that the file myFile.txt does not exist, so an FNFE(FileNotFoundException) would be&lt;br /&gt;thrown from the try block. The catch blocked would catch the FNFE , wrap the exception and rethrow it.&lt;br /&gt;Till now all seems well. When the call reaches the finally block, since input is null,&lt;br /&gt;a call to input.close() would result in a NullPointerException(NPE) being thrown. &lt;br /&gt;Now since the finally block never catches a NPE, it would propagate up the call stack.&lt;br /&gt;The WrappedException(WE) from the catch block simply disappears.&lt;br /&gt;&lt;br /&gt;The way to avoid this would be to check whether the resource in not null in the finally block.Right, makes&lt;br /&gt;complete sense, but lets take another scenario. Lets say the file myFile.txt is found but there is an&lt;br /&gt;IOException(IOE) thrown due to some other reason. What happens, the try block throws IOE, which is&lt;br /&gt;wrapped and rethrown. Now before the exception propagates up the call stack, the finally block is executed,&lt;br /&gt;if the call to input.close() fails, a new IOE would be thrown, but the original exception would still be lost.&lt;br /&gt;Damn Cute, aint it.&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-0859115606381197";
/* 180X160 created 2/24/08 */
google_ad_slot = "7249403400";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4953895613784667233-750728598094490833?l=maneeshchaturvedi.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://maneeshchaturvedi.blogspot.com/2008/05/bane-of-java-exceptional-handling.html</link><author>noreply@blogger.com (maneesh chaturvedi)</author></item></channel></rss>

