<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Sunilchaurha's Blog</title>
	<atom:link href="http://sunilchaurha.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sunilchaurha.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Fri, 11 Mar 2011 17:41:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sunilchaurha.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Sunilchaurha's Blog</title>
		<link>http://sunilchaurha.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sunilchaurha.wordpress.com/osd.xml" title="Sunilchaurha&#039;s Blog" />
	<atom:link rel='hub' href='http://sunilchaurha.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Preventing cloning of Object in while using singleton design pattern</title>
		<link>http://sunilchaurha.wordpress.com/2011/03/08/preventing-cloning-of-object-in-while-using-singleton-design-pattern/</link>
		<comments>http://sunilchaurha.wordpress.com/2011/03/08/preventing-cloning-of-object-in-while-using-singleton-design-pattern/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 13:12:41 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=56</guid>
		<description><![CDATA[Hi All, Using singleton design pattern is a best way to access a valuable resource. In this case we do use Singleton design pattern and stops clients classes to create multiple instances of the Class. But there is a loophole in this pattern and one can create instance of the Singleton class using object cloning. <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=56&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi All,</p>
<p>Using singleton design pattern is a best way to access a valuable resource. In this case we do use Singleton design pattern and stops clients classes to create multiple instances of the Class.</p>
<p>But there is a loophole in this pattern and one can create instance of the Singleton class using object cloning.</p>
<p>So we should prevent cloning of object in this class as well if required.</p>
<p>Code given below gives a brief idea of how to stop client class to clone an object.</p>
<p>package com.sun;</p>
<p>/** * @author Sunil Chauraha */</p>
<p>class Clone1 implements  Cloneable{</p>
<p>@Override	protected Object clone() throws CloneNotSupportedException</p>
<p>throw new CloneNotSupportedException(&#8220;Cloning of this class is not supported by me&#8230;&#8221;);</p>
<p>}<br />
public class CloneTest  {</p>
<p>public static void main(String[] args) {</p>
<p>try{</p>
<p>Clone1 clone1 = new Clone1();</p>
<p>Clone1  clone2 = (Clone1)clone1.clone();</p>
<p>}catch (CloneNotSupportedException e) {</p>
<p>System.err.println(e.getMessage()+&#8221;: &#8220;+e);</p>
<p>}</p>
<p>}</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=56&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2011/03/08/preventing-cloning-of-object-in-while-using-singleton-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>12.828958 88.593750</georss:point>
		<geo:lat>12.828958</geo:lat>
		<geo:long>88.593750</geo:long>
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>Interview questions</title>
		<link>http://sunilchaurha.wordpress.com/2011/03/08/java-interview-questions/</link>
		<comments>http://sunilchaurha.wordpress.com/2011/03/08/java-interview-questions/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 12:37:52 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=51</guid>
		<description><![CDATA[1. Define your profession and carrear skills. 2. What is the difference between struts and jsf. 3. What the scope of application and request. 4. What is AJAX. 5. Where will you rate yourself in SQL. 6. Do you know any design pattern? if yes describe. 7. What is value binding and component binding. 8. <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=51&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>1. Define your profession and carrear skills.<br />
2.  What is the difference between struts and jsf.<br />
3.  What the scope of application and request.<br />
4.  What is AJAX.<br />
5.  Where will you rate yourself in SQL.<br />
6.  Do you know any design pattern? if yes describe.<br />
7.  What is value binding and component binding.<br />
8.  Define lifecycle of richfaces.<br />
9.  How does a request completes?<br />
10. What is jsf components?<br />
11. What is component and events in jsf?<br />
12. What did you do for performance inprovement?<br />
13. What is IOC?<br />
14. What is transaction management?<br />
15. What is the life cycle of spring bean?<br />
16. How will you configure spring and hibernate?<br />
17. What is sessionfactory and session?<br />
18. What is generics?<br />
19. what is run time polymerphism?<br />
20. how will you integrate spring in jsf?<br />
21. what is hibernate?<br />
22. what is difference between load and get in hibernate?<br />
23. what is save, update and merge?<br />
24. what is factory pattern?<br />
25. what is spring mvc?<br />
26. how will you integrate hibernate with spring?<br />
27. what is aop?<br />
28. what is criteria?<br />
29. What is criteria and detached criteria?<br />
30. one sql query for group by operation.<br />
31. select second highest salary of an employee from emp table.<br />
32. What is difference between struts and spring.<br />
33 what is difference between jsp and servlet.<br />
34 what is the life cycle of jsp.<br />
35 what is the difference between requestForward method of servlet context and servlet config.</p>
<p>36. How we can instantiate a bean of abstract class having 2 subclasses.</p>
<p>37. How can we maintain a collection having the same order of insertion and unique values of object.</p>
<p>38. How can we use JPA in spring.</p>
<p>39. We have a singleton class and constructor is private, how can we create a bean in spring.</p>
<p>40. What is the mechanism used by Java for maintaining set and HashSet objects.</p>
<p>41. What is the significance of equals and hashCode methods in java and object comparison.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=51&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2011/03/08/java-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>12.828958 88.593750</georss:point>
		<geo:lat>12.828958</geo:lat>
		<geo:long>88.593750</geo:long>
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>Class loading and java reflection</title>
		<link>http://sunilchaurha.wordpress.com/2011/03/02/class-loading-and-java-reflection/</link>
		<comments>http://sunilchaurha.wordpress.com/2011/03/02/class-loading-and-java-reflection/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 18:23:15 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=47</guid>
		<description><![CDATA[Here is some simple example of class loading and java reflection. package com.sun; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import com.sun1.TestClass; public class MainClass { @SuppressWarnings(&#8220;unchecked&#8221;) public static void main(String[] args) { System.out.println(&#8220;Testing classloading&#8230;&#8221;); try{ Class clazz = Class.forName(&#8220;com.sun1.TestClass&#8221;); Method [] methods = clazz.getDeclaredMethods(); TestClass tc = new TestClass(); for (Method method : methods) { try{ method.invoke(tc, <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=47&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is some simple example of class loading and java reflection.</p>
<p>package com.sun;</p>
<p>import java.lang.reflect.InvocationTargetException;<br />
import java.lang.reflect.Method;<br />
import com.sun1.TestClass;<br />
public class MainClass {<br />
	@SuppressWarnings(&#8220;unchecked&#8221;)<br />
	public static void main(String[] args) {<br />
		System.out.println(&#8220;Testing classloading&#8230;&#8221;);<br />
		try{<br />
			Class clazz = Class.forName(&#8220;com.sun1.TestClass&#8221;);<br />
			Method [] methods = clazz.getDeclaredMethods();<br />
			TestClass tc = new TestClass();<br />
			for (Method method : methods) {<br />
				try{<br />
					method.invoke(tc, new Object[]{&#8220;Sunil Chauraha&#8221;});<br />
				}catch(InvocationTargetException e){<br />
					System.err.println(e.getMessage());<br />
				}catch (IllegalAccessException e) {<br />
					System.err.println(e.getMessage());<br />
				}<br />
			}<br />
		}catch(ClassNotFoundException cnf){<br />
			System.err.println(cnf.getMessage()+&#8221; : &#8220;+cnf);<br />
		}<br />
	}<br />
}</p>
<p>package com.sun1;<br />
public class TestClass {<br />
	public void pring(String value){<br />
		System.out.println(&#8220;The value passed is : &#8220;+value);<br />
	}<br />
}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=47&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2011/03/02/class-loading-and-java-reflection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>12.828958 88.593750</georss:point>
		<geo:lat>12.828958</geo:lat>
		<geo:long>88.593750</geo:long>
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>UML Diagram and Eclipse</title>
		<link>http://sunilchaurha.wordpress.com/2010/06/21/uml_diagram_and_eclipse/</link>
		<comments>http://sunilchaurha.wordpress.com/2010/06/21/uml_diagram_and_eclipse/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 05:25:01 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=36</guid>
		<description><![CDATA[Hello&#8230;&#8230;&#8230;&#8230;. Here are the links for uml plug in configuration with eclipse. http://www.seasar.org/en/tutorial/eclipse/uml_omondo/index.html http://www.vogella.de/articles/UML/article.html#umltools_diagram<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=36&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello&#8230;&#8230;&#8230;&#8230;.</p>
<p>Here are the links for uml plug in configuration with eclipse.</p>
<p><a class="wpGallery" title="Omando UML" href="http://www.seasar.org/en/tutorial/eclipse/uml_omondo/index.html" target="_blank">http://www.seasar.org/en/tutorial/eclipse/uml_omondo/index.html</a></p>
<p><a class="wpGallery" title="UML Learning " href="http://www.vogella.de/articles/UML/article.html#umltools_diagram" target="_blank">http://www.vogella.de/articles/UML/article.html#umltools_diagram</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=36&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2010/06/21/uml_diagram_and_eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>12.828958 88.593750</georss:point>
		<geo:lat>12.828958</geo:lat>
		<geo:long>88.593750</geo:long>
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>Global warming</title>
		<link>http://sunilchaurha.wordpress.com/2010/05/31/global-warming/</link>
		<comments>http://sunilchaurha.wordpress.com/2010/05/31/global-warming/#comments</comments>
		<pubDate>Mon, 31 May 2010 17:14:14 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mother earth.]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=31</guid>
		<description><![CDATA[When the word &#8220;Global warming&#8221; comes into mind or on voice or in ears. I start thinking who is responsible for this ever ending problem? I think, in fact i am sure that me, you and they all are responsible for this outcome. As a human being what we are doing or what we have <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=31&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When the word &#8220;<strong>Global warming</strong>&#8221; comes into mind or on voice or in ears. I start thinking who is responsible for this ever ending problem? I think, in fact i am sure that me, you and they all are responsible for this outcome. As a human being what we are doing or what we have done or what we are going to do. Some where that follows Einstein&#8217;s E=MC2 and produces unnecessary energy and the global warming increases by 0.000000001 % or more.</p>
<p>My dear friend please think something outstanding or wonderful thing that can decrease the rate of increase in temperature&#8230;&#8230;&#8230; <span id="more-31"></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=31&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2010/05/31/global-warming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>12.828958 88.593750</georss:point>
		<geo:lat>12.828958</geo:lat>
		<geo:long>88.593750</geo:long>
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>Singleton design pattern</title>
		<link>http://sunilchaurha.wordpress.com/2010/05/24/singleton-design-pattern/</link>
		<comments>http://sunilchaurha.wordpress.com/2010/05/24/singleton-design-pattern/#comments</comments>
		<pubDate>Mon, 24 May 2010 17:16:50 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[Designs]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=27</guid>
		<description><![CDATA[As the name says&#8230; Singleton -&#62; means just single. There are so many situations where we need to create many or one instance of our class.  Like we will have a single database connection manger. There are many ways to create a singleton design (i.e. Using User Defined exception class, using static class). rather there <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=27&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As the name says&#8230; Singleton -&gt; means just single.</p>
<p>There are so many situations where we need to create many or one instance of our class.  Like we will have a single database connection manger.</p>
<p>There are many ways to create a singleton design (i.e. Using User Defined exception class, using static class).</p>
<p>rather there is the most useful way that most programmer uses.  That is static method having a private default constructor.</p>
<div id="_mcePaste">public class IsSingle {</div>
<div id="_mcePaste">static boolean instanceFlag = false;</div>
<div id="_mcePaste">private IsSingle(){}</div>
<div id="_mcePaste">public static IsSingle getInstance(){</div>
<div id="_mcePaste">if(!instanceFlag){</div>
<div id="_mcePaste">instanceFlag = true;</div>
<div id="_mcePaste">return new IsSingle();</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">else{</div>
<div id="_mcePaste">return null;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">}</div>
<div>// finalize is needed here, because if object IsSingle is garbage collected then isInstance must be false to invoke new.</div>
<div id="_mcePaste">public void finalize(){</div>
<div id="_mcePaste">instanceFlag = false;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">}</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=27&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2010/05/24/singleton-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>12.828958 88.593750</georss:point>
		<geo:lat>12.828958</geo:lat>
		<geo:long>88.593750</geo:long>
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>Reading a Doc file using Java</title>
		<link>http://sunilchaurha.wordpress.com/2010/05/11/reading-a-doc-file-using-java/</link>
		<comments>http://sunilchaurha.wordpress.com/2010/05/11/reading-a-doc-file-using-java/#comments</comments>
		<pubDate>Tue, 11 May 2010 17:28:10 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[JAVA IO]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=24</guid>
		<description><![CDATA[Hi by using a simple java IO we can&#8217;t read contents of a doc file. Jakarta poi has some utilities to read contents of a file using its api. Every line of the doc file is considered as a paragraph. import java.io.FileInputStream; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class ReadandWrite { public static void <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=24&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;">Hi by using a simple java IO we can&#8217;t read contents of a doc file.</p>
<p style="text-align:left;">Jakarta poi has some utilities to read contents of a file using its api.</p>
<p style="text-align:left;">Every line of the doc file is considered as a paragraph.</p>
<p style="text-align:left;">
<p style="text-align:left;">
<div id="_mcePaste" style="text-align:left;">import java.io.FileInputStream;</div>
<div id="_mcePaste" style="text-align:left;">import org.apache.poi.hwpf.HWPFDocument;</div>
<div id="_mcePaste" style="text-align:left;">import org.apache.poi.hwpf.extractor.WordExtractor;</div>
<div id="_mcePaste" style="text-align:left;">import org.apache.poi.poifs.filesystem.POIFSFileSystem;</div>
<div id="_mcePaste" style="text-align:left;"></div>
<div style="text-align:left;">public class ReadandWrite {</div>
<div id="_mcePaste" style="text-align:left;">public static void readDocFile(String filePath) {</div>
<div id="_mcePaste" style="text-align:left;">POIFSFileSystem fs = null;</div>
<div id="_mcePaste" style="text-align:left;">try {</div>
<div id="_mcePaste" style="text-align:left;">fs = new POIFSFileSystem(new FileInputStream(filePath));</div>
<div id="_mcePaste" style="text-align:left;">HWPFDocument doc = new HWPFDocument(fs);</div>
<div id="_mcePaste" style="text-align:left;">WordExtractor we = new WordExtractor(doc);</div>
<div id="_mcePaste" style="text-align:left;">String[] paragraphs = we.getParagraphText();</div>
<div id="_mcePaste" style="text-align:left;">System.out.println(&#8220;Word Document has &#8221; + paragraphs.length+ &#8221; paragraphs&#8221;);</div>
<div id="_mcePaste" style="text-align:left;">for (int i = 0; i &lt; paragraphs.length; i++) {</div>
<div id="_mcePaste" style="text-align:left;">paragraphs[i] = paragraphs[i].replaceAll(&#8220;\\cM?&#8221;, &#8220;&#8221;);</div>
<div id="_mcePaste" style="text-align:left;">System.out.println(paragraphs[i]);</div>
<div id="_mcePaste" style="text-align:left;">}</div>
<div id="_mcePaste" style="text-align:left;">} catch (Exception e) {</div>
<div id="_mcePaste" style="text-align:left;"></div>
<div id="_mcePaste" style="text-align:left;">}</div>
<div id="_mcePaste" style="text-align:left;">}</div>
<div id="_mcePaste" style="text-align:left;">public static void main(String[] args) throws Throwable {</div>
<div id="_mcePaste" style="text-align:left;">readDocFile(&#8220;yourfile.doc&#8221;);</div>
<div id="_mcePaste" style="text-align:left;">}</div>
<div id="_mcePaste" style="text-align:left;">}</div>
<p style="text-align:left;">For this i used  poi-3.0-FINAL.jar.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=24&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2010/05/11/reading-a-doc-file-using-java/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<georss:point>12.828958 88.593750</georss:point>
		<geo:lat>12.828958</geo:lat>
		<geo:long>88.593750</geo:long>
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use Gmail as your SMTP server &#8211; JAVA</title>
		<link>http://sunilchaurha.wordpress.com/2010/04/02/how-to-use-gmail-as-smtp-server-java/</link>
		<comments>http://sunilchaurha.wordpress.com/2010/04/02/how-to-use-gmail-as-smtp-server-java/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 12:58:16 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[Java Mail Usage]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=17</guid>
		<description><![CDATA[Hi Here is an interesting code to send an email using gmail smtp server. This asks for the login and password of any gmail accound and uses gmail smtp to send emails&#8230; ************************************************************************************** package com.sunil.mail; import java.security.Security; import java.util.Properties; import javax.mail.Message; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import org.apache.log4j.Logger; public class <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=17&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi Here is an interesting code to send an email using gmail smtp server.</p>
<p>This asks for the login and password of any gmail accound and uses gmail smtp to send emails&#8230;</p>
<p>**************************************************************************************</p>
<p>package com.sunil.mail;<br />
import java.security.Security;<br />
import java.util.Properties;</p>
<p>import javax.mail.Message;<br />
import javax.mail.PasswordAuthentication;<br />
import javax.mail.Session;<br />
import javax.mail.Transport;<br />
import javax.mail.internet.InternetAddress;<br />
import javax.mail.internet.MimeMessage;</p>
<p>import org.apache.log4j.Logger;</p>
<p>public class SimpleJavaMail {</p>
<p>private Session mailSession;<br />
protected PasswordAuthentication authentication;<br />
private String user = null;<br />
private String password = null;<br />
private Properties props;</p>
<p>public SimpleJavaMail(){<br />
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());<br />
props = new Properties();<br />
props.setProperty(&#8220;mail.transport.protocol&#8221;, &#8220;smtp&#8221;);<br />
props.setProperty(&#8220;mail.host&#8221;, &#8220;smtp.gmail.com&#8221;);<br />
props.put(&#8220;mail.smtp.auth&#8221;, &#8220;true&#8221;);<br />
props.put(&#8220;mail.smtp.port&#8221;, &#8220;465&#8243;);<br />
props.put(&#8220;mail.smtp.socketFactory.port&#8221;, &#8220;465&#8243;);<br />
props.put(&#8220;mail.smtp.socketFactory.class&#8221;, &#8220;javax.net.ssl.SSLSocketFactory&#8221;);<br />
props.put(&#8220;mail.smtp.socketFactory.fallback&#8221;, &#8220;false&#8221;);<br />
props.put(&#8220;mail.user&#8221;, &#8220;xxxxxxx@gmail.com&#8221;);<br />
props.put(&#8220;mail.password&#8221;, &#8220;xxxxx&#8221;);<br />
props.setProperty(&#8220;mail.smtp.quitwait&#8221;, &#8220;false&#8221;);<br />
}</p>
<p>public void initMail(String user, String password) {<br />
this.user = user;<br />
this.password = password;<br />
mailSession = createMailSession();<br />
}</p>
<p>private Session createMailSession() {<br />
Session session = null;<br />
try {<br />
session = Session.getDefaultInstance(props,    new javax.mail.Authenticator(){<br />
protected PasswordAuthentication getPasswordAuthentication(){<br />
return new PasswordAuthentication(user,password);<br />
}<br />
});<br />
} catch (Exception e) {<br />
e.printStackTrace();<br />
}<br />
return session;<br />
}</p>
<p>public synchronized void sendMail(String subject, String body, String sender, String recipients)<br />
throws Exception{<br />
String host;<br />
String mailUserName = (String) getProps().get(&#8220;mail.user&#8221;);<br />
String mailPassword = (String) getProps().get(&#8220;mail.password&#8221;);<br />
host = (String) getProps().get(&#8220;mail.host&#8221;);<br />
host = host.toLowerCase();<br />
initMail(mailUserName, mailPassword);<br />
MimeMessage message = new MimeMessage(mailSession);<br />
message.setSender(new InternetAddress(sender));<br />
message.setSubject(subject);<br />
message.setContent(body, &#8220;text/plain&#8221;);<br />
if (recipients.indexOf(&#8216;,&#8217;) &gt; 0){<br />
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));<br />
}else{<br />
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));<br />
}<br />
Transport.send(message);<br />
}</p>
<p>public Properties getProps() {<br />
return props;<br />
}</p>
<p>public void setProps(Properties props) {<br />
this.props = props;<br />
}</p>
<p>public static void main(String[] args) {<br />
try{<br />
String subject = &#8220;Test mail&#8230;&#8221;;<br />
String body = &#8220;Hi Buddy&#8230;&#8221;;<br />
String sender = &#8220;noname@noname.com&#8221;;<br />
String recipients = &#8220;sunilxxxx@gmail.com&#8221;;<br />
SimpleJavaMail mailJava = new SimpleJavaMail();<br />
mailJava.sendMail(subject, body, sender, recipients);<br />
} catch (Exception e) {<br />
Logger.getLogger(SimpleJavaMail.class.getName()).error(e);<br />
e.printStackTrace();<br />
}<br />
System.out.println(&#8220;Mail sent!&#8221;);<br />
}</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=17&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2010/04/02/how-to-use-gmail-as-smtp-server-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>12.828958 88.593750</georss:point>
		<geo:lat>12.828958</geo:lat>
		<geo:long>88.593750</geo:long>
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>Running DOS command using java!</title>
		<link>http://sunilchaurha.wordpress.com/2010/02/18/running-dos-command-using-java/</link>
		<comments>http://sunilchaurha.wordpress.com/2010/02/18/running-dos-command-using-java/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 09:18:52 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=14</guid>
		<description><![CDATA[Hi&#8230; Here is a small example. We can use to run a dos command using java code. /***************Code ******************/ import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.InputStreamReader; class SunilCmd { static public void main(String args[]) { try { StringBuffer sb = new StringBuffer(); BufferedReader buff = new BufferedReader(new InputStreamReader(    Runtime.getRuntime().exec(&#8220;cmd.exe /C dir&#8221;).getInputStream())); /* Here Runtime.getRuntime <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=14&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi&#8230;</p>
<p>Here is a small example.</p>
<p>We can use to run a dos command using java code.</p>
<p>/***************Code ******************/</p>
<p>import java.io.BufferedReader;<br />
import java.io.File;<br />
import java.io.FileOutputStream;<br />
import java.io.InputStreamReader;</p>
<p>class SunilCmd {</p>
<p>static public void main(String args[]) {<br />
try {<br />
StringBuffer sb = new StringBuffer();<br />
BufferedReader buff = new BufferedReader(new InputStreamReader(    Runtime.getRuntime().exec(&#8220;cmd.exe /C dir&#8221;).getInputStream()));<br />
/* Here Runtime.getRuntime creates environment to run the command */<br />
/* .exec executes the parameters given inside the method */</p>
<p>/*<br />
* here &#8220;cmd.exe /C&#8221; will invoke the DOS in exclusive mode and &#8220;dir&#8221;<br />
* is a command that will be executed&#8230;..<br />
*/</p>
<p>String line = buff.readLine();<br />
while (line != null) {<br />
sb.append(line + &#8220;\n&#8221;);<br />
line = buff.readLine();<br />
}<br />
System.out.println(sb);<br />
File f = new File(&#8220;output.txt&#8221;);<br />
/**<br />
*All the output will be written into output.txt file<br />
*/<br />
FileOutputStream fos = new FileOutputStream(f);<br />
fos.write(sb.toString().getBytes());<br />
fos.close();<br />
} catch (Exception ex) {<br />
ex.printStackTrace();<br />
}<br />
}</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=14&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2010/02/18/running-dos-command-using-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
		<item>
		<title>how to access faces context and backing beans in a servlet filter</title>
		<link>http://sunilchaurha.wordpress.com/2010/01/21/how-to-access-faces-context-and-backing-beans-in-a-servlet-filter/</link>
		<comments>http://sunilchaurha.wordpress.com/2010/01/21/how-to-access-faces-context-and-backing-beans-in-a-servlet-filter/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 10:14:29 +0000</pubDate>
		<dc:creator>Sunil Chuaraha</dc:creator>
				<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://sunilchaurha.wordpress.com/?p=11</guid>
		<description><![CDATA[// You need an inner class to be able to call FacesContext.setCurrentInstance // since it's a protected method private abstract static class InnerFacesContext extends FacesContext { protected static void setFacesContextAsCurrentInstance(FacesContext facesContext) { FacesContext.setCurrentInstance(facesContext); } } private FacesContext getFacesContext(ServletRequest request, ServletResponse response) { // Try to get it first FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext != <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=11&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><code>// You need an inner class to be able to call FacesContext.setCurrentInstance<br />
// since it's a protected method<br />
private abstract static class InnerFacesContext extends FacesContext<br />
{<br />
protected static void setFacesContextAsCurrentInstance(FacesContext facesContext) {<br />
FacesContext.setCurrentInstance(facesContext);<br />
}<br />
}</code></p>
<p>private FacesContext getFacesContext(ServletRequest request, ServletResponse response) {<br />
// Try to get it first<br />
FacesContext facesContext = FacesContext.getCurrentInstance();<br />
if (facesContext != null) return facesContext;</p>
<p>FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);<br />
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);<br />
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);</p>
<p>// Either set a private member servletContext = filterConfig.getServletContext();<br />
// in you filter init() method or set it here like this:<br />
// ServletContext servletContext = ((HttpServletRequest)request).getSession().getServletContext();<br />
// Note that the above line would fail if you are using any other protocol than http</p>
<p>// Doesn&#8217;t set this instance as the current instance of FacesContext.getCurrentInstance<br />
facesContext = contextFactory.getFacesContext(servletContext, request, response, lifecycle);</p>
<p>// Set using our inner class<br />
InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);</p>
<p>// set a new viewRoot, otherwise context.getViewRoot returns null<br />
UIViewRoot view = facesContext.getApplication().getViewHandler().createView(facesContext, &#8220;yourOwnID&#8221;);<br />
facesContext.setViewRoot(view);</p>
<p>return facesContext;<br />
}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sunilchaurha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sunilchaurha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sunilchaurha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sunilchaurha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sunilchaurha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sunilchaurha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sunilchaurha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sunilchaurha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sunilchaurha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sunilchaurha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sunilchaurha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sunilchaurha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sunilchaurha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sunilchaurha.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sunilchaurha.wordpress.com&amp;blog=6509888&amp;post=11&amp;subd=sunilchaurha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sunilchaurha.wordpress.com/2010/01/21/how-to-access-faces-context-and-backing-beans-in-a-servlet-filter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/db0b4147556794c80dc2f5293bc70c89?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sunnu</media:title>
		</media:content>
	</item>
	</channel>
</rss>
