<?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>Jyotimishra&#039;s Blog</title>
	<atom:link href="http://jyotimishra.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jyotimishra.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sat, 03 Sep 2011 13:39:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jyotimishra.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Jyotimishra&#039;s Blog</title>
		<link>http://jyotimishra.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jyotimishra.wordpress.com/osd.xml" title="Jyotimishra&#039;s Blog" />
	<atom:link rel='hub' href='http://jyotimishra.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Let go of fearful thoughts</title>
		<link>http://jyotimishra.wordpress.com/2011/09/03/let-go-of-fearful-thoughts/</link>
		<comments>http://jyotimishra.wordpress.com/2011/09/03/let-go-of-fearful-thoughts/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 13:35:30 +0000</pubDate>
		<dc:creator>jyotimishra</dc:creator>
				<category><![CDATA[Gems of Wisdom]]></category>

		<guid isPermaLink="false">http://jyotimishra.wordpress.com/?p=96</guid>
		<description><![CDATA[If you gathered up all the fearful thoughts that exist in the mind of the average person, looked at them objectively, and tried to decide just how much good they provided that person, you would see that not some but all fearful thoughts are useless. They do no good. Zero. They interfere with dreams, hopes, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=96&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you gathered up all the fearful thoughts that exist in the mind of the average person, looked at them objectively, and tried to decide just how much good they provided that person, you would see that not some but all fearful thoughts are useless. They do no good. Zero. They interfere with dreams, hopes, desires, and progress.</p>
<p>Fearful thoughts take many different forms. Sometimes they sound reasonable: “I’m just being careful, so I’m taking my time.” Other times they are tied to your past: “I’ve tried that before and it didn’t work.” Occasionally, fears are cleverly disguised as being realistic: “Most people fail, so I want to be absolutely sure before I get started.” I could fill page after page with other examples. Yet when you take a close, honest look at every fearful thought, there are threads of similarity. All of them are explanations or rationalizations for why something shouldn’t or can’t work. They are usually justifications for quitting, or for not getting started.</p>
<p>Fearful thoughts hold you back, not some but all of the time.</p>
<p>A critic, especially a fearful one, will look at this advice and say it’s unrealistic, simplistic, and/or foolish. The problem with overcoming these objections is that, on the surface, they sound reasonable. Let me assure you that I’m not suggesting you ignore the facts and take unnecessary and/or foolish risks.</p>
<p>What I’m talking about here are the fears that clearly and directly interfere with your dreams – the fear of rejection, the fear of failure; thoughts like “What will everyone think of me? I might look foolish,” or “I don’t think I can do it, I don’t have the time, or the experience, or the confidence.” These common, ongoing fearful thoughts are the dream snatchers of our own making.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jyotimishra.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jyotimishra.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jyotimishra.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jyotimishra.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jyotimishra.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jyotimishra.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jyotimishra.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jyotimishra.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jyotimishra.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jyotimishra.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jyotimishra.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jyotimishra.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jyotimishra.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jyotimishra.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=96&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jyotimishra.wordpress.com/2011/09/03/let-go-of-fearful-thoughts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d1732956322c2ff2dd8b6900eff22e5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jyotimishra</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Servlet &#8211; servlet zip file download works in Firefox but not IE 6</title>
		<link>http://jyotimishra.wordpress.com/2010/02/18/java-servlet-servlet-zip-file-download-works-in-firefox-but-not-ie-6/</link>
		<comments>http://jyotimishra.wordpress.com/2010/02/18/java-servlet-servlet-zip-file-download-works-in-firefox-but-not-ie-6/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 13:55:01 +0000</pubDate>
		<dc:creator>jyotimishra</dc:creator>
				<category><![CDATA[Java Code Ie Download Issue]]></category>

		<guid isPermaLink="false">http://jyotimishra.wordpress.com/?p=84</guid>
		<description><![CDATA[HI, I encountered a beautiful problem last time, hence writing this post to help those who have the same problem. Problem: My task is to download files from the servers as a zip file format through Java Code. I created one zip file and added all files to that zip. Finally write that zip file [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=84&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>HI,</p>
<p>I encountered a beautiful problem last time, hence writing this post to help those who have the same problem.</p>
<p>Problem: My task is to download files from the servers as a zip file format through Java Code. I created one zip file and added all files to that zip. Finally write that zip file in servlet out put stream. But interesting thing is this works perfectly in Firefox/Mozila but failed in IE6/7,</p>
<p>Following is the code snippet for this:</p>
<p>String zipfilePath = (new StringBuilder(String.valueOf(getServlet().getServletContext().getRealPath(&#8220;/&#8221;)))).append(&#8220;upload&#8221;).append(&#8220;//&#8221;).append(&#8220;Allattachements.zip&#8221;).toString();</p>
<p>ZipOutputStream out = null;<br />
out = new ZipOutputStream(new FileOutputStream(zipfilePath));</p>
<p>//Code to add all files to zip goes here</p>
<p>//Start download code</p>
<p>File                f        = new File(zipfilePath);<br />
int                 length   = 0;<br />
ServletOutputStream op       = resp.getOutputStream();</p>
<p>resp.setContentLength( (int)f.length() );<br />
resp.setHeader( &#8220;Content-Disposition&#8221;, &#8220;attachment; filename=\&#8221;" +  some_filename + &#8220;\&#8221;" );<br />
resp.setContentType( (mimetype != null) ? mimetype : &#8220;application/octet-stream&#8221; );</p>
<p>byte[] bbuf = new byte[18024];<br />
DataInputStream in = new DataInputStream(new FileInputStream(f));</p>
<p>while ((in != null) &amp;&amp; ((length = in.read(bbuf)) != -1))<br />
{<br />
op.write(bbuf,0,length);<br />
}</p>
<p>in.close();<br />
op.flush();<br />
op.close();<br />
}</p>
<p>In IE what happen when we click on the download option is just cant imagine.</p>
<p>I am prompted for download option, but after downloading the file, i found another file inside the downloadzip with same name as of the downloadzip file , but with no extension, when i 7zip the file, all other files are there in side it.</p>
<p>I started some experiment, finally able to download the correct format.</p>
<p>Here is the solution:</p>
<p>Every thing will remain same just changed the content type:</p>
<p>resp.setContentLength( (int)f.length() );<br />
resp.setHeader( &#8220;Content-Disposition&#8221;, &#8220;attachment; filename=\&#8221;" +  original_filename + &#8220;\&#8221;" );<br />
resp.setContentType(&#8220;application/octet-stream&#8221; );<br />
resp.setHeader (&#8220;Pragma&#8221;, &#8220;public&#8221;);<br />
resp.setHeader(&#8220;Cache-control&#8221;, &#8220;must-revalidate&#8221;);</p>
<p>You need to set the Pragma to public. SO it will works for Ie. as well as set the  contentType to &#8220;application/octet-stream&#8221;</p>
<p>Thanks</p>
<p><!--Session data--></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jyotimishra.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jyotimishra.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jyotimishra.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jyotimishra.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jyotimishra.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jyotimishra.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jyotimishra.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jyotimishra.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jyotimishra.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jyotimishra.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jyotimishra.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jyotimishra.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jyotimishra.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jyotimishra.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=84&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jyotimishra.wordpress.com/2010/02/18/java-servlet-servlet-zip-file-download-works-in-firefox-but-not-ie-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d1732956322c2ff2dd8b6900eff22e5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jyotimishra</media:title>
		</media:content>
	</item>
		<item>
		<title>InterView Question Sites</title>
		<link>http://jyotimishra.wordpress.com/2009/07/25/interview-question-sites/</link>
		<comments>http://jyotimishra.wordpress.com/2009/07/25/interview-question-sites/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 14:49:48 +0000</pubDate>
		<dc:creator>jyotimishra</dc:creator>
				<category><![CDATA[Interview Question And Answer Sites]]></category>

		<guid isPermaLink="false">http://jyotimishra.wordpress.com/?p=47</guid>
		<description><![CDATA[Interview Question Answer Site http://www.developersbook.com/ PDF Search Engine http://www.pdf-search-engine.com/ Spring Framework Best Practice http://lijinjoseji.wordpress.com/2007/09/27/spring-framework-best-programming-practices/ Struts, Spring, Hibernate Tutorial =============================== http://www.vaannila.com<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=47&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Interview Question Answer Site</strong></p>
<p><a class="wp-caption" title="Jyoti favorite Interview Question Answer Sites" href="http://www.developersbook.com/" target="_blank"><strong>http://www.developersbook.com/</strong></a></p>
<p><strong>PDF Search Engine</strong></p>
<p><a class="aligncenter" title="PDF Search" href="http://www.pdf-search-engine.com/" target="_blank">http://www.pdf-search-engine.com/</a></p>
<p><strong>Spring Framework Best Practice</strong></p>
<p><strong><a class="aligncenter" title="Spring framework best practice" href="http://lijinjoseji.wordpress.com/2007/09/27/spring-framework-best-programming-practices/" target="_blank">http://lijinjoseji.wordpress.com/2007/09/27/spring-framework-best-programming-practices/</a></strong></p>
<p><strong>Struts, Spring, Hibernate Tutorial</strong></p>
<p><strong>===============================</strong></p>
<p><strong><a class="aligncenter" title="Tutorial" href="http://www.vaannila.com" target="_blank">http://www.vaannila.com</a></strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jyotimishra.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jyotimishra.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jyotimishra.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jyotimishra.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jyotimishra.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jyotimishra.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jyotimishra.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jyotimishra.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jyotimishra.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jyotimishra.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jyotimishra.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jyotimishra.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jyotimishra.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jyotimishra.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=47&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jyotimishra.wordpress.com/2009/07/25/interview-question-sites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d1732956322c2ff2dd8b6900eff22e5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jyotimishra</media:title>
		</media:content>
	</item>
		<item>
		<title>RelationShips In Hibernate</title>
		<link>http://jyotimishra.wordpress.com/2009/07/25/relationships-in-hibernate/</link>
		<comments>http://jyotimishra.wordpress.com/2009/07/25/relationships-in-hibernate/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 11:40:44 +0000</pubDate>
		<dc:creator>jyotimishra</dc:creator>
				<category><![CDATA[RelationShip In Hibernate]]></category>

		<guid isPermaLink="false">http://jyotimishra.wordpress.com/?p=43</guid>
		<description><![CDATA[ONE-TO-MANY Employee.java package jyoti; import java.util.Date; public class Emp { private int empno; private String ename; private String job; private int mgr; private Date hiredate; private float sal; private float comm; //private int deptno; private Dept dept; public Emp() { super(); // TODO Auto-generated constructor stub } public Emp(int empno, String ename, String job, int [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=43&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;"><span style="text-decoration:underline;"><strong>ONE-TO-MANY</strong></span></p>
<p><span style="text-decoration:underline;">Employee.java</span></p>
<p>package jyoti;<br />
import java.util.Date;<br />
public class Emp {</p>
<p>private int empno;<br />
private String ename;<br />
private String job;<br />
private int mgr;<br />
private Date hiredate;<br />
private float sal;<br />
private float comm;<br />
//private int deptno;<br />
private Dept dept;</p>
<p>public Emp() {<br />
super();<br />
// TODO Auto-generated constructor stub<br />
}</p>
<p>public Emp(int empno, String ename, String job, int mgr, Date hiredate, float sal, float comm, Dept dept) {<br />
super();<br />
this.empno = empno;<br />
this.ename = ename;<br />
this.job = job;<br />
this.mgr = mgr;<br />
this.hiredate = hiredate;<br />
this.sal = sal;<br />
this.comm = comm;<br />
this.dept = dept;<br />
}</p>
<p>public Emp(String ename, String job, float sal) {<br />
super();<br />
this.ename = ename;<br />
this.job = job;<br />
this.sal = sal;<br />
}</p>
<p>public int getEmpno() {<br />
return empno;<br />
}<br />
public void setEmpno(int empno) {<br />
this.empno = empno;<br />
}<br />
public String getEname() {<br />
return ename;<br />
}<br />
public void setEname(String ename) {<br />
this.ename = ename;<br />
}<br />
public String getJob() {<br />
return job;<br />
}<br />
public void setJob(String job) {<br />
this.job = job;<br />
}<br />
public int getMgr() {<br />
return mgr;<br />
}<br />
public void setMgr(int mgr) {<br />
this.mgr = mgr;<br />
}<br />
public Date getHiredate() {<br />
return hiredate;<br />
}<br />
public void setHiredate(Date hiredate) {<br />
this.hiredate = hiredate;<br />
}<br />
public float getSal() {<br />
return sal;<br />
}<br />
public void setSal(float sal) {<br />
this.sal = sal;<br />
}<br />
public float getComm() {<br />
return comm;<br />
}<br />
public void setComm(float comm) {<br />
this.comm = comm;<br />
}</p>
<p>public Dept getDept() {<br />
return dept;<br />
}<br />
public void setDept(Dept dept) {<br />
this.dept = dept;<br />
}</p>
<p>}</p>
<p><span style="text-decoration:underline;">employee.hbm.xml</span></p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;!DOCTYPE hibernate-mapping PUBLIC<br />
&#8220;-//Hibernate/Hibernate Mapping DTD 3.0//EN&#8221;<br />
&#8220;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&#8221;&gt;<br />
&lt;hibernate-mapping&gt;<br />
&lt;class name=&#8221;jyoti.Emp&#8221; table=&#8221;emp&#8221; lazy=&#8221;true&#8221;&gt;<br />
&lt;id name=&#8221;empno&#8221; type=&#8221;int&#8221; column=&#8221;empno&#8221; &gt;<br />
&lt;generator/&gt;<br />
&lt;/id&gt;<br />
&lt;property name=&#8221;ename&#8221;&gt;<br />
&lt;column name=&#8221;ename&#8221; /&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;job&#8221;&gt;<br />
&lt;column name=&#8221;job&#8221;/&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;mgr&#8221; not-null=&#8221;false&#8221;&gt;<br />
&lt;column name=&#8221;mgr&#8221;/&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;hiredate&#8221;&gt;<br />
&lt;column name=&#8221;hiredate&#8221; /&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;sal&#8221;&gt;<br />
&lt;column name=&#8221;sal&#8221;/&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;comm&#8221;&gt;<br />
&lt;column name=&#8221;comm&#8221;/&gt;<br />
&lt;/property&gt;</p>
<p>&lt;many-to-one name=&#8221;dept&#8221;  column=&#8221;deptno&#8221; not-null=&#8221;false&#8221;&gt;<br />
&lt;/many-to-one&gt;<br />
&lt;/class&gt;<br />
&lt;/hibernate-mapping&gt;</p>
<p><span style="text-decoration:underline;">Dept.java</span></p>
<p>package jyoti;</p>
<p>import java.util.Set;</p>
<p>public class Dept {</p>
<p>private int deptno;<br />
private String dname;<br />
private String loc;<br />
private Set employee;</p>
<p>public Dept() {<br />
super();<br />
// TODO Auto-generated constructor stub<br />
}<br />
public int getDeptno() {<br />
return deptno;<br />
}<br />
public void setDeptno(int deptno) {<br />
this.deptno = deptno;<br />
}<br />
public String getDname() {<br />
return dname;<br />
}<br />
public void setDname(String dname) {<br />
this.dname = dname;<br />
}<br />
public String getLoc() {<br />
return loc;<br />
}<br />
public void setLoc(String loc) {<br />
this.loc = loc;<br />
}<br />
public Set getEmployee() {<br />
return employee;<br />
}<br />
public void setEmployee(Set employee) {<br />
this.employee = employee;<br />
}<br />
}</p>
<p><span style="text-decoration:underline;">dept.hbm.xml</span></p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;!DOCTYPE hibernate-mapping PUBLIC<br />
&#8220;-//Hibernate/Hibernate Mapping DTD 3.0//EN&#8221;<br />
&#8220;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&#8221;&gt;<br />
&lt;hibernate-mapping&gt;<br />
&lt;class name=&#8221;jyoti.Dept&#8221; table=&#8221;dept&#8221; lazy=&#8221;true&#8221;&gt;<br />
&lt;id name=&#8221;deptno&#8221; type=&#8221;int&#8221; column=&#8221;deptno&#8221; &gt;<br />
&lt;generator/&gt;<br />
&lt;/id&gt;<br />
&lt;property name=&#8221;dname&#8221;&gt;<br />
&lt;column name=&#8221;dname&#8221; /&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;loc&#8221;&gt;<br />
&lt;column name=&#8221;loc&#8221;/&gt;<br />
&lt;/property&gt;<br />
&lt;set name=&#8221;employee&#8221; inverse=&#8221;true&#8221; cascade=&#8221;all&#8221; lazy=&#8221;true&#8221; batch-size=&#8221;9&#8243;&gt;<br />
&lt;key&gt;<br />
&lt;column name=&#8221;deptno&#8221;/&gt;<br />
&lt;/key&gt;<br />
&lt;one-to-many class=&#8221;jyoti.Emp&#8221;/&gt;<br />
&lt;/set&gt;<br />
&lt;/class&gt;<br />
&lt;/hibernate-mapping&gt;</p>
<p><span style="text-decoration:underline;">TestClass.java</span></p>
<p>public class FirstExample {<br />
public static void main(String[] args) {<br />
Session session = null;</p>
<p>try{</p>
<p>SessionFactory sessionFactory = new Configuration().configure(&#8220;/hibernate.cfg.xml&#8221;).buildSessionFactory();<br />
session =sessionFactory.openSession();<br />
session.setFlushMode(FlushMode.AUTO);<br />
org.hibernate.Transaction tx = session.beginTransaction();<br />
Set ofemp = new HashSet();<br />
System.out.println(&#8220;Inserting Record&#8221;);<br />
Emp emp = new Emp();<br />
//emp.setEmpno(19);</p>
<p>emp.setEname(&#8220;Jyoti&#8221;);<br />
emp.setJob(&#8220;Analyst&#8221;);<br />
emp.setMgr(4578);<br />
Date d= new Date();<br />
emp.setHiredate(d);<br />
ofemp.add(emp);<br />
Emp emp1 = new Emp();<br />
//emp.setEmpno(19);</p>
<p>emp1.setEname(&#8220;Jyoti&#8221;);<br />
emp1.setJob(&#8220;Analyst&#8221;);<br />
emp1.setMgr(4578);<br />
Date d2= new Date();<br />
emp1.setHiredate(d2);<br />
ofemp.add(emp1);<br />
//emp.setDept(10);<br />
Dept dept = new Dept();<br />
//ob.setDeptno(50);<br />
dept.setDname(&#8220;CTC&#8221;);<br />
dept.setLoc(&#8220;BBSR&#8221;);<br />
dept.setEmployee(ofemp);<br />
//session.save(emp);        /*If cascade attribute is set to &#8220;true&#8221; then no need of this code. Hibernate trys to persist all at a time*/<br />
//session.save(emp1);        /*if inverse=&#8221;true&#8221; set then  hibernate knows that there is a bidirectional association exist*/<br />
session.save(dept);<br />
tx.commit();<br />
System.out.println(&#8220;Done&#8221;);</p>
<p>}catch(Exception e){<br />
e.printStackTrace();<br />
System.out.println(&#8220;sorry jyoti &#8220;+e.getMessage());<br />
}finally{</p>
<p>try{<br />
session.flush();<br />
session.close();<br />
}catch(Exception ee){<br />
ee.printStackTrace();<br />
System.out.println(&#8220;jyoti&#8221;);}</p>
<p>}</p>
<p>}<br />
}</p>
<p><strong>FOR INHERITANCE MAPPING IN HIBERNATE SEE THE FOLLOWING LINK</strong></p>
<p>====================================================<a class="alignright" style="display:inline!important;" title="Inheritace Mapping in hibernate" href="http://simsonlive.wordpress.com/2008/03/09/how-inheritance-works-in-hibernate/" target="_blank">http://simsonlive.wordpress.com/2008/03/09/how-inheritance-works-in-hibernate/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jyotimishra.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jyotimishra.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jyotimishra.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jyotimishra.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jyotimishra.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jyotimishra.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jyotimishra.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jyotimishra.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jyotimishra.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jyotimishra.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jyotimishra.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jyotimishra.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jyotimishra.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jyotimishra.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=43&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jyotimishra.wordpress.com/2009/07/25/relationships-in-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d1732956322c2ff2dd8b6900eff22e5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jyotimishra</media:title>
		</media:content>
	</item>
		<item>
		<title>Interview Questions And Answers</title>
		<link>http://jyotimishra.wordpress.com/2009/07/23/interview-questions-and-answers/</link>
		<comments>http://jyotimishra.wordpress.com/2009/07/23/interview-questions-and-answers/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 15:02:28 +0000</pubDate>
		<dc:creator>jyotimishra</dc:creator>
				<category><![CDATA[Problems2Solutions]]></category>

		<guid isPermaLink="false">http://jyotimishra.wordpress.com/?p=14</guid>
		<description><![CDATA[Q.1. User-Defined Character Properties immutable/ How to create user defined Immutable class ? A.1. Making a class immutable Immutability must be familiar to every one when we talk about String &#38; StringBuffer classes in java. Strings are considered immutable because the values contained in the reference variable cannot be changed. Whereas String Buffer is considered [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=14&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Q.1. <strong>User-Defined Character Properties immutable/ How to create user defined Immutable class ?</strong></p>
<p><strong>A.1. </strong></p>
<p><strong>Making a class immutable</strong></p>
<p>Immutability must be familiar to every one when we talk about String &amp; StringBuffer classes in java. Strings are considered immutable because the values contained in the reference variable cannot be changed. Whereas String Buffer is considered mutable because the value in a string buffer can be changed (i.e. mutable).</p>
<p>However I always thought how to make our user defined classes as immutable though I am unaware as to why any one would need this.</p>
<p>The reason perhaps might be clear once we have a look at the code.</p>
<p>Now in order to make a class immutable we must restrict changing the state of the class object by any means. This in turn means avoiding an assignment to a variable. We can achieve this through a final modifier. To further restrict the access we can use a private access modifier. Above do not provide any method where we modify the instance variables.</p>
<p>Still done? No. How if some body creates a sub class from our up till now immutable class? Yes here lies the problem. The new subclass can contain methods, which over ride our base class (immutable class) methods. Here he can change the variable values.</p>
<p>Hence make the methods in the class also final. Or a better approach. Make the immutable class itself final. Hence cannot make any sub classes, so no question of over ridding.</p>
<p>The following code gives a way to make the class immutable.</p>
<p>/*<br />
Code Developed By Ashish Agarwal<br />
This code demonstrates the way to make a class immutable<br />
*/</p>
<p>// The immutable class which is made final<br />
final class MyImmutableClass<br />
{<br />
// instance var are made private &amp; final to restrict the access</p>
<p>private final int count;<br />
private final double value;</p>
<p>// Constructor where we can provide the constant value<br />
public MyImmutableClass(int paramCount,double paramValue)<br />
{<br />
count = paramCount;<br />
value = paramValue;<br />
}</p>
<p>// provide only methods which return the instance var<br />
// &amp; not change the values</p>
<p>public int getCount()<br />
{<br />
return count;<br />
}</p>
<p>public double getValue()<br />
{<br />
return value;<br />
}<br />
}</p>
<p>// class TestImmutable<br />
public class TestImmutable<br />
{<br />
public static void main(String[] args)<br />
{<br />
MyImmutableClass obj1 = new MyImmutableClass(3,5);</p>
<p>System.out.println(obj1.getCount());<br />
System.out.println(obj1.getValue());</p>
<p>// there is no way to change the values of count &amp; value-<br />
// no method to call besides getXX, no subclassing, no public access to var -&gt; Immutable<br />
}<br />
}</p>
<p>The possible use of immutable classes would be a class containing a price list represented for a set of products.<br />
Otherwise also this represents a good design.</p>
<p>2.Q <strong>What is a Marker Interface ?</strong></p>
<p><strong>Ans:</strong></p>
<p><strong> </strong>A marker interface is such an interface, by implementing which , your class object will get some special behavior.<strong> </strong></p>
<p>Example: By implementing java.io.Serializable your class Object becomes Serializable.</p>
<p>By implementing java.lang.Runnable your Class becomes thread Class.</p>
<p>By implementing java.lang.Cloneable your Class Object can be cloned.</p>
<p><strong>Q. 3: What is an invoker Servlet?</strong></p>
<p><strong>A: </strong></p>
<h1><a href="http://faq.javaranch.com/search?InvokerServlet">Invoker Servlet</a></h1>
<h2 id="section-InvokerServlet-InvokerServlet"><span class="searchword"> </span></h2>
<p>The <span class="searchword">Invoker</span> <span class="searchword">servlet</span> (or <strong><span class="searchword">Invoker</span><span class="searchword">Servlet</span></strong>) is a special <span class="searchword">servlet</span> provided with <a class="wikipage" href="http://wiki.metawerx.net/wiki/Tomcat">Tomcat</a>, which allows <span class="searchword">servlet</span>s to be called by simply using a /<span class="searchword">servlet</span> URL, without having to configure each <span class="searchword">servlet</span> individually in <a class="wikipage" href="http://wiki.metawerx.net/wiki/Web.xml">web.xml</a>. It is disabled by default in new <a class="wikipage" href="http://wiki.metawerx.net/wiki/Tomcat">Tomcat</a> installations and new <a class="external" href="http://www.metawerx.net/">Metawerx</a><img class="outlink" src="http://wiki.metawerx.net/images/out.png" alt="" /> hosting accounts.</p>
<p>For example:</p>
<pre>http://www.examplecompany.com/<span class="searchword">servlet</span>/My<span class="searchword">Servlet</span></pre>
<h4 id="section-InvokerServlet-WhyDoesItExist">Why does it exist?</h4>
<p>In older <span class="searchword">servlet</span> containers, before <a class="wikipage" href="http://wiki.metawerx.net/wiki/Web.xml">web.xml</a> was added to the specification, this was the default behaviour, so the <span class="searchword">Invoker</span> <span class="searchword">Servlet</span> was provided to avoid creating complex <a class="wikipage" href="http://wiki.metawerx.net/wiki/Web.xml">web.xml</a> files.</p>
<h4 id="section-InvokerServlet-WhyIsItDisabledByDefault">Why is it disabled by default?</h4>
<ul>
<li>The /<span class="searchword">servlet</span>/ URL extension allows any class in your classpath to be accessed, as long as the class is a valid <span class="searchword">servlet</span>. This is a security risk. Using <a class="wikipage" href="http://wiki.metawerx.net/wiki/Web.xml">web.xml</a> configuration, the deployer of the application can define specifically which URL&#8217;s can be used.</li>
<li>Secondly, the /<span class="searchword">servlet</span>/ approach forces the use of java class names in the URL. Using <a class="wikipage" href="http://wiki.metawerx.net/wiki/Web.xml">web.xml</a> configuration provides a way to define the URL instead, separating the class names from what the end-user sees in their browser&#8217;s URL bar.</li>
</ul>
<h4 id="section-InvokerServlet-EnablingTheInvoker">Enabling the <span class="searchword">Invoker</span></h4>
<ul>
<li>The <span class="searchword">Invoker</span> is disabled by default, so it is necessary to change either the server-wide <a class="wikipage" href="http://wiki.metawerx.net/wiki/Web.xml">web.xml</a> file, or add a small section to your applications <a class="wikipage" href="http://wiki.metawerx.net/wiki/Web.xml">web.xml</a> (preferred method). To see how to do this, see <a class="wikipage" href="http://wiki.metawerx.net/wiki/EnablingTheInvokerServlet">Enabling the <span class="searchword">Invoker</span> <span class="searchword">Servlet</span></a>.</li>
</ul>
<h4 id="section-InvokerServlet-UsageTips">Usage tips</h4>
<ul>
<li>The <span class="searchword">servlet</span> name in the URL is the same as the <span class="searchword">servlet</span> class name.</li>
<li>The <span class="searchword">servlet</span> should not be included in a package if you are planning on using it with the <span class="searchword">Invoker</span>.</li>
</ul>
<p><strong>Q.4:</strong> <strong>Is Jsp by default thread safe ?</strong></p>
<p>A: Short answer, no, JSPs by default are not automatically thread safe.</p>
<p>To make jsp as threadsafe we hav to make isThreadSafe=false<br />
,so it sends only one request for processing.it implicitly<br />
implement SingleThreadModel interface.</p>
<p>Just add the directive &lt;%@ page isThreadSafe=&#8221;false&#8221; %&gt; with the jsp page.</p>
<p><strong>Q. 5: How to get a read only collection ?</strong></p>
<div style="font-family:Arial,Helvetica,Sans-Serif;font-weight:bold;color:#ff6600;margin-left:10px;margin-top:10px;">Making a Collection Read-Only</div>
<div style="padding:10px;">The Collections class provides static APIs to generate a read-only or unmodifiable collection, list, set, or map from the specified entity. For instance, if you are sure that the ArrayList you&#8217;ve made should not be modified, you can generate a read-only list from it by using the following code:</div>
<pre><code>
  ArrayList list = new ArrayList();
  list.add(first);
  ...
  List readOnlyList = Collections.unmodifiableList(list);
</code></pre>
<div style="padding:10px;">It&#8217;s important to discard the previous reference to the modifiable object. Any attempt to modify such a read-only object would result in an UnsupportedOperationException.</div>
<div style="padding:10px;"><strong>Q. 6 What is the use of String letarals , if String Objects are there ? </strong></div>
<div style="padding:10px;">
<p>There are two ways to create a String object in Java:</p>
<ul>
<li>Using the <em>new</em> operator. For example,<br />
<code>String str = new String("Hello");</code>.</li>
<li>Using a <em>string literal</em> or <em>constant expression)</em>. For example,<br />
<code>String str="Hello";</code> (string literal) or<br />
<code>String str="Hel" + "lo";</code> (string constant expression).</li>
</ul>
<p>What is difference between these String&#8217;s creations? In Java, the <em>equals</em> method can be considered to perform a deep comparison of the value of an object, whereas the <em>==</em> operator performs a shallow comparison. The <em>equals</em> method compares the content of two objects rather than two objects&#8217; references. The <em>==</em> operator with reference types (i.e., Objects) evaluates as <em>true</em> if the references are identical &#8211; point to the same object. With value types (i.e., primitives) it evaluates as <em>true</em> if the value is identical. The <em>equals</em> method is to return <em>true</em> if two objects have identical content &#8211; however, the <em>equals</em> method in the java.lang.Object class &#8211; the default <em>equals</em> method if a class does not override it &#8211; returns <em>true</em> only if both references point to the same object.</p>
<p>Let&#8217;s use the following example to see what difference between these creations of string:</p>
<pre>public class DemoStringCreation {

  public static void main (String args[]) {
    String str1 = "Hello";
    String str2 = "Hello";
    System.out.println("str1 and str2 are created by using string literal.");
    System.out.println("    str1 == str2 is " + (str1 == str2));
    System.out.println("    str1.equals(str2) is " + str1.equals(str2));  

    String str3 = new String("Hello");
    String str4 = new String("Hello");
    System.out.println("str3 and str4 are created by using new operator.");
    System.out.println("    str3 == str4 is " + (str3 == str4));
    System.out.println("    str3.equals(str4) is " + str3.equals(str4));  

    String str5 = "Hel"+ "lo";
    String str6 = "He" + "llo";
    System.out.println("str5 and str6 are created by using string
constant expression.");
    System.out.println("    str5 == str6 is " + (str5 == str6));
    System.out.println("    str5.equals(str6) is " + str5.equals(str6));

    String s = "lo";
    String str7 = "Hel"+ s;
    String str8 = "He" + "llo";
    System.out.println("str7 is computed at runtime.");
    System.out.println("str8 is created by using string constant
expression.");
    System.out.println("    str7 == str8 is " + (str7 == str8));
    System.out.println("    str7.equals(str8) is " + str7.equals(str8));

  }
}</pre>
<p>The output result is:</p>
<pre>str1 and str2 are created by using string literal.
    str1 == str2 is true
    str1.equals(str2) is true
str3 and str4 are created by using new operator.
    str3 == str4 is false
    str3.equals(str4) is true
str5 and str6 are created by using string constant expression.
    str5 == str6 is true
    str5.equals(str6) is true
str7 is computed at runtime.
str8 is created by using string constant expression.
    str7 == str8 is false
    str7.equals(str8) is true</pre>
<p>The creation of two strings with the same sequence of letters without the use of the <em>new</em> keyword will create pointers to the same String in the Java String literal pool. The String literal pool is a way Java conserves resources.</p>
<h2>String Literal Pool</h2>
<p>String allocation, like all object allocation, proves costly in both time and memory. The JVM performs some trickery while instantiating <em><strong>string literals</strong></em> to increase performance and decrease memory overhead. To cut down the number of String objects created in the JVM, the String class keeps a pool of strings. Each time your code create a string literal, the JVM checks the string literal pool first. If the string already exists in the pool, a reference to the pooled instance returns. If the string does not exist in the pool, a new String object instantiates, then is placed in the pool. Java can make this optimization since strings are immutable and can be shared without fear of data corruption. For example</p>
<pre>public class Program
{
    public static void main(String[] args)
    {
       String str1 = "Hello";
       String str2 = "Hello";
       System.out.print(str1 == str2);
    }
}</pre>
<p>The result is</p>
<pre>true</pre>
<p>Unfortunately, when you use</p>
<pre>String a=new String("Hello");</pre>
<p>a <em>String</em> object is created out of the String literal pool, even if an equal string already exists in the pool. Considering all that, avoid new String unless you specifically know that you need it! For example</p>
<pre>public class Program
{
    public static void main(String[] args)
    {
       String str1 = "Hello";
       String str2 = new String("Hello");
       System.out.print(str1 == str2 + " ");
       System.out.print(str1.equals(str2));
    }
}</pre>
<p>The result is</p>
<pre>false true</pre>
<p>A JVM has a string pool where it keeps at most one object of any String. String literals always refer to an object in the string pool. String objects created with the new operator do not refer to objects in the string pool but can be made to using String&#8217;s intern() method. The <em>java.lang.String.intern()</em> returns an interned String, that is, one that has an entry in the global String pool. If the String is not already in the global String pool, then it will be added. For example</p>
<pre>public class Program
{
    public static void main(String[] args)
    {
        // Create three strings in three different ways.
        String s1 = "Hello";
        String s2 = new StringBuffer("He").append("llo").toString();
        String s3 = s2.intern();

        // Determine which strings are equivalent using the ==
        // operator
        System.out.println("s1 == s2? " + (s1 == s2));
        System.out.println("s1 == s3? " + (s1 == s3));
    }
}</pre>
<p>The output is</p>
<pre>s1 == s2? false
s1 == s3? true</pre>
<p>There is a table always maintaining <strong>a single reference</strong> to each unique String object in the global string literal pool ever created by an instance of the runtime in order to optimize space. That means that they always have a reference to String objects in string literal pool, therefore, the string objects in the string literal pool not eligible for garbage collection.</p>
<p><strong>7: How to achieve inheritance features without using OOPS Inheritance concept ?</strong></p>
<p><strong>A: </strong></p>
<p><strong><span style="font-family:arial;font-size:x-small;"><em>Delegation</em> is an alternative to inheritance.</span></strong></p>
<p>By defining an object of the other class as instance variable in the class, we will get all the features like we get in Inheritance.</p>
<p>But this will lead the difficulty to maintain the code.</p>
<p><strong>8. Which model will help in understanding user requirement?</strong></p>
<p>i. Use Case diagram</p>
<p>ii. Sequence Diagram</p>
<p>iii. Architecture Diagram</p>
<p>iv. Not Remember</p>
<p><strong>9. What is instance pooling?</strong></p>
<p><strong>10. What are the JDBC Transaction Levels?</strong></p>
<p><strong>11. Servlet Life cycle with diagram.</strong></p>
<p><strong>12. Http is stateless protocol. Suggest any scenario to hold data between multi request and response operations.</strong></p>
<p><strong>13. ear files structure.</strong></p>
<p><strong>14. Use of session facade model in software development life cycle.</strong></p>
<p><strong>15. What is optimistic locking?</strong></p>
<p><strong>16. Draw the structure of ejb stateless and statefull pulling.</strong></p>
<p><strong>17. An ejb component requires a transaction, what exception it will throw when it will enter in</strong></p>
<p><strong>to a non transactional area.</strong></p>
<p><strong>18. What is the use of Home and Remote interface in ejb?</strong></p>
<p><strong>19. Explain service() method.</strong></p>
<p><strong>20. Can a session be share between a jsp and an ejb? What will happen if i will modify the</strong></p>
<p><strong>value of a variable of session in the ejb?</strong></p>
<p><strong>21.</strong></p>
<p><img class="alignnone size-medium wp-image-30" title="image001" src="http://jyotimishra.files.wordpress.com/2009/07/image0011.png?w=669&#038;h=353" alt="image001" width="669" height="353" /></p>
<p><strong>22. What is ANT.? Write down an ant script.</strong></p>
<p><strong>23. What new in ejb 2.0 specification.</strong></p>
<p>Ans:</p>
<p>In brief, the EJB 2.0 specification introduces these new features:</p>
<ul>
<li>Message-driven beans</li>
<li>An improved architecture for container-managed persistence</li>
<li>Container-managed relationships for entity beans with container-managed persistence</li>
<li>Local interfaces</li>
<li>Enterprise JavaBeans Query Language</li>
</ul>
<p>http://java.sun.com/developer/technicalArticles/ebeans/ejb20/</p>
<p>. Message Driven Bean</p>
<p>ii. Not remember</p>
<p><strong>24. Write down the code to redirect from one servlet (servlet1) to other servlet (Servlet2).</strong></p>
<p><strong>25. What is log4J? How it is useful in your projects.</strong></p>
<p>Ans:</p>
<p>If something goes wrong, we can consult with the log to determine the cause of the problem.</p>
<p>A log will help us to debug the problem so that it won’t happen again.</p>
<p><strong>26. By default servlet’s service method is not thread safe. Suppose one application is there where you need to make the servlet thread safe. What you will prefer from the following:</strong></p>
<p>i. Implement SingleThreadModel</p>
<p>ii. Write down the critical section in a synchronized block.</p>
<p>iii. Not remember</p>
<p><strong>27. Write down the implicit objects available to a jsp page and its type.</strong></p>
<p><strong>28. How to compile a jsp page manually.</strong></p>
<p><strong>29. What is jsp custom tags and what are its benefits of it.</strong></p>
<p><strong>30. What is discriminator column and where it is used in hibernate ?</strong></p>
<p><strong>31. What is </strong><strong>table </strong><strong>per </strong><strong> </strong><strong>class </strong><strong>and table per </strong><strong>class feature of hibernate, explain ?</strong></p>
<p><strong>32. How to integrate Struts with Spring ?</strong></p>
<p><strong>33. What is the difference between struts dispatch and look up dispatch actions, where you are using these ?</strong></p>
<p><strong> </strong><br />
<strong>34. What is the return type of constructor ?</strong></p>
<p>A: Class Type<br />
<strong>35. What is a custom servlet ?</strong></p>
<p>A: The use defined servlet which extend either HttpServlet or GenericServlet is called custom servlet .</p>
<p><strong>36: What ere the advantages of hibernate ?</strong></p>
<p><strong>37: Tell us some cases where you need to use JDBC instead of Hibernate ?</strong></p>
<p><strong>38: int[] array = {12, 25, 4, 7, 89, 56, 42, 78, 95, 41, 2, 75};</strong></p>
<p><strong>Find out the second lowest without shorting the array ?</strong></p>
<p><strong>A: </strong></p>
<p><strong> </strong>public class Test {<br />
public static void main(String[] args) throws Exception {<br />
Test test = new Test();<br />
int[] array = {45, 78, 12, 56, 32, 74, 42, 85, 21, 31};<br />
int j = test.abc(array);<br />
System.out.println(&#8220;The Second Smallest Is: &#8220;+j);<br />
}</p>
<p>private int abc(int[] array) {<br />
int len = array.length;<br />
int sm1,sm2;<br />
if(array[0]&lt;array[1]){<br />
sm1 = array[0];<br />
sm2 = array[1];<br />
}else{<br />
sm1 = array[1];<br />
sm2 = array[0];<br />
}<br />
for(int i=2;i&lt;len;i++){<br />
if(array[i]&lt;sm1 ){<br />
sm2 = sm1;<br />
sm1 = array[i];<br />
}else if(array[i] &gt; sm1 &amp;&amp; array[i] &lt; sm2){<br />
sm2 = array[i];<br />
}<br />
}<br />
return sm2;</p>
<p>}</p>
<p>}</p>
<p><strong>39: Where you will find all the class Like java.lang.Object, java.lang.System, etc. in side Java installation folder ?</strong></p>
<p><strong>40: There are three threads named A, B, C. How to execute those threads so that C starts first, then B and then A. ?</strong></p>
<p><strong>41: Can i have a privet Servlet ?</strong></p>
<p>A: No, A servlet can be defined as either <strong>public</strong> or with <strong>default </strong>access specifier</p>
<p>and modifiers can be either <strong>abstract or final.</strong></p>
<p>But never <strong>private</strong>, <strong>protected</strong> or <strong>static</strong>.</p>
<p><strong>42: Can I have two main methods in a single Class ? If yes which will called first . </strong></p>
<p><strong>A: </strong>It is possible to have two main methods in a Single class, but those will be over loaded.</p>
<p>The main method with the following form will be called By Jvm</p>
<p><strong>public static void main(String[] args){</strong></p>
<p><strong>}</strong></p>
<p><strong>43: Explain the flow of Struts ?</strong></p>
<p><strong>44: Explain the flow of JSF ?</strong></p>
<p><strong>45: Which xml parser we will prefer to use if the xml file size is of 1 MB ?</strong></p>
<p><strong>A:       Sax will be preferred;</strong></p>
<h1>Java XML Parsing: SAX vs DOM</h1>
<p>The general rule of thumb, when processing XML, is to use DOM on document like files (e.g. html, feeds or settings files), and SAX on large files, XML dump files, or data streams, and such. But lately I have been quite curious on how much the performance difference would be between the two.</p>
<p>So I&#8217;ve created a small micro benchmarks; just default normal java XML processing. No fancy settings or anything. One implementation uses DOM, the other SAX. Both try to retrieve the main feed title from an atom feed, and both are implemented quite simplistic. Basically both are a &#8220;use the first title you find&#8221;, for as far as that maps to the respective APIs.</p>
<p>See the resulting graph:</p>
<p><strong><img class="alignnone" title="Sax vs Dom" src="http://tech.inhelsinki.nl/2007-08-29/graph-java-xml-performance.png" alt="" width="720" height="432" /></strong></p>
<p>Clearly, on small documents it hardly matters, but as soon as the XML document size increases SAX is a lot more efficient. To process a 1 Mb document, DOM has to allocate about 6 Mb of objects. (Notice though, that, probably, by the time you get to traverse the nodes, some of that 6 Mb has already turned into garbage, so total memory need is actually less then 6 Mb, more on that below.)</p>
<p>The difference is staggering, though somewhat expected: DOM takes twice the time, and 5 times the memory compared to SAX. Basically SAX scales better, as the rule of thumb predicts.</p>
<h3>Implementing</h3>
<p>Implementing a SAX parser, however, is of course cumbersome compared to a DOM parser. Because with DOM you can randomly walk the document at your own means, and you kan even keep the <code>Document</code> node around to reference whenever you need to.</p>
<p>Contrast that with SAX, where you pass through the document only ones, and you have be done when the document ends. So likely with SAX, you need to build your own set of objects representing the interesting information that was in the XML. The upside is that your own set of objects is easier and more efficient to reference and traverse, then all those DOM <code>Node</code>s and <code>NodeList</code>s.</p>
</div>
<div style="padding:10px;">Reference:  <a class="wp-caption" href="http://tech.inhelsinki.nl/2007-08-29/" target="_blank">http://tech.inhelsinki.nl/2007-08-29/</a></div>
<div style="padding:10px;"><span style="text-decoration:underline;"><strong>Yell Adworks Interview Questions</strong></span></div>
<div style="padding:10px;"><strong>1.  How to integrate struts with spring ?</strong></div>
<div style="padding:10px;">A :</div>
<div style="padding:10px;">Define your beans in springs applicationContext.xml file. Then provide this file as a context param to the springs &#8220;org.springframework.web.context.ContextLoaderServlet&#8221; as mentioned below. At the time of the container start up the xml file will be read and the corresponding beans will be initialized.</div>
<div style="padding:10px;">&lt;context-param&gt;<br />
&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br />
&lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;<br />
&lt;/context-param&gt;&lt;servlet&gt;<br />
&lt;servlet-name&gt;context&lt;/servlet-name&gt;<br />
&lt;servlet-class&gt;org.springframework.web.context.ContextLoaderServlet&lt;/servlet-class&gt;<br />
&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br />
&lt;/servlet&gt;</div>
<div style="padding:10px;">==============================================</div>
<div style="padding:10px;"><span style="text-decoration:underline;"><strong>Example Of  Spring Configuration File</strong></span></div>
<div style="padding:10px;">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;!DOCTYPE beans PUBLIC &#8220;-//SPRING//DTD BEAN//EN&#8221; &#8220;http://www.springframework.org/dtd/spring-beans.dtd&#8221;&gt;&lt;beans&gt;<br />
&lt;bean id=&#8221;myDataSource&#8221;<br />
class=&#8221;org.apache.commons.dbcp.BasicDataSource&#8221;<br />
destroy-method=&#8221;close&#8221;&gt;<br />
&lt;property name=&#8221;driverClassName&#8221;&gt;<br />
&lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;url&#8221;&gt;<br />
&lt;value&gt;jdbc:mysql://localhost:3306/automatednewsletter&lt;/value&gt;</p>
<p>&lt;/property&gt;<br />
&lt;property name=&#8221;username&#8221;&gt;<br />
&lt;value&gt;root&lt;/value&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;password&#8221;&gt;<br />
&lt;value&gt;&lt;/value&gt;<br />
&lt;/property&gt;<br />
&lt;/bean&gt;<br />
&lt;bean id=&#8221;mySessionFactory&#8221;<br />
class=&#8221;org.springframework.orm.hibernate3.LocalSessionFactoryBean&#8221;&gt;<br />
&lt;property name=&#8221;dataSource&#8221;&gt;<br />
&lt;ref bean=&#8221;myDataSource&#8221; /&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;hibernateProperties&#8221;&gt;<br />
&lt;props&gt;<br />
&lt;prop key=&#8221;hibernate.dialect&#8221;&gt;<br />
org.hibernate.dialect.MySQLDialect<br />
&lt;/prop&gt;<br />
&lt;prop key=&#8221;hibernate.show_sql&#8221;&gt;true&lt;/prop&gt;<br />
&lt;prop key=&#8221;hibernate.hbm2ddl.auto&#8221;&gt;update&lt;/prop&gt;<br />
&lt;/props&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;mappingResources&#8221;&gt;<br />
&lt;list&gt;<br />
&lt;!&#8211; maping resources &#8211;&gt;<br />
&lt;value&gt;/com/nr/ana/pojos/AnaAdhocSend.hbm.xml&lt;/value&gt;<br />
&lt;value&gt;/com/nr/ana/pojos/AnaAdminLogin.hbm.xml&lt;/value&gt;<br />
&lt;/list&gt;<br />
&lt;/property&gt;<br />
&lt;/bean&gt;<br />
&lt;!&#8211; User defined DAO Class that extends org.springframework.orm.hibernate3.support.HibernateDaoSupport &#8211;&gt;<br />
&lt;bean id=&#8221;userDAO&#8221;&gt;<br />
&lt;property name=&#8221;sessionFactory&#8221;&gt;<br />
&lt;ref bean=&#8221;mySessionFactory&#8221; /&gt;<br />
&lt;/property&gt;<br />
&lt;/bean&gt;</p>
</div>
<p>&lt;!&#8211; User defined Service Class  where we are having a DAO&#8217;s instant variable and a setter injection will occur with the following code &#8211;&gt;<br />
&lt;bean id=&#8221;userservices&#8221; class=&#8221;com.nr.ana.services.UserServices&#8221;&gt;<br />
&lt;property name=&#8221;userDAO&#8221;&gt;<br />
&lt;ref bean=&#8221;userDAO&#8221; /&gt;<br />
&lt;/property&gt;<br />
&lt;/bean&gt;<br />
&lt;/beans&gt;</p>
<div style="padding:10px;"><span style="text-decoration:underline;"><strong>A service finder class which will find the corresponding services in the action class</strong></span></div>
<div style="padding:10px;">import java.io.Serializable;import javax.servlet.http.HttpServletRequest;</p>
<p>import org.springframework.context.ApplicationContext;<br />
import org.springframework.web.context.support.WebApplicationContextUtils;</p>
<p>public class ServiceFinder implements Serializable{<br />
/**<br />
*<br />
*/<br />
private static final long serialVersionUID = 8642771451003852941L;</p>
<p>private static ApplicationContext applicationContext=null;<br />
public static ApplicationContext getContext(HttpServletRequest httpRequest) {<br />
return WebApplicationContextUtils.getRequiredWebApplicationContext(httpRequest.getSession().getServletContext());<br />
}</p>
<p>public static Object getBean(HttpServletRequest httpRequest,String beanName){<br />
if(applicationContext!=null){<br />
applicationContext = getContext(httpRequest);<br />
}<br />
return applicationContext.getBean(beanName);<br />
}<br />
}</p>
</div>
<div style="padding:10px;"><span style="text-decoration:underline;"><strong>Action Class Execute method where we will be getting the service class object reference</strong></span></div>
<div style="padding:10px;">public ActionForward execute(ActionMapping mapping, ActionForm form,<br />
HttpServletRequest request, HttpServletResponse response) {<br />
RegisterUserBO registerUser = (RegisterUserBO) form;// TODO Auto-generated method stub<br />
UserServices userServices = (UserServices) ServiceFinder.getContext(request).getBean(&#8220;userservices&#8221;);</div>
<div style="padding:10px;">// Rest of the code</div>
<div style="padding:10px;">}</div>
<div style="padding:10px;"><strong>Q: What are the advantage of Spring software ?</strong></div>
<div style="padding:10px;"><strong>Q: What is JAVA Reflection, how do you use it ?</strong></div>
<div style="padding:10px;"><strong>Q: What is the difference default and protected access specifier ?</strong></div>
<div style="padding:10px;"><strong>Q: What is compile time and run time polymorphism ?</strong></div>
<div style="padding:10px;"><strong>Q: How many types of beans are there in Spring ?</strong></div>
<div style="padding:10px;"><strong>Ans:</strong></div>
<div style="padding:10px;">
<ul>
<li><strong>Singleton beans and Prototype beans</strong></li>
</ul>
<p>By default all beans defined in spring are singleton. However you can ask spring to create unique instance of a particular bean setting “singleton” property of the bean to false. Such beans are called prototype. A new instance of a prototype bean will be created each time getBean() is invoked with the bean’s name. Prototype beans incur hit on performance during creation. It should be avoided completely or designed carefully if it uses resources such as database or network connections. They are useful for factory to create new bean instances.</p>
</div>
<div style="padding:10px;"><strong>Follow the link</strong></div>
<div style="padding:10px;"><a href="http://lijinjoseji.wordpress.com/2007/09/27/spring-framework-best-programming-practices-part-1/">http://lijinjoseji.wordpress.com/2007/09/27/spring-framework-best-programming-practices-part-1/</a></div>
<div style="padding:10px;"><strong>Q: How to make a lazy initialization of a bean in spring ?</strong></div>
<div style="padding:10px;"><strong> </strong></p>
<h2 style="font-size:15px;"><span style="font-weight:normal;"><strong>Lazy Initiation in Spring IOC</strong></span></h2>
<p><span style="font-weight:normal;"><strong>As we know </strong></span><span style="font-weight:normal;"><strong>Spring&#8217;s bean factory</strong></span><span style="font-weight:normal;"><strong> is pre-initiate all </strong></span><span style="text-decoration:underline;"><span style="font-weight:normal;"><strong>the beans</strong></span></span><span style="font-weight:normal;"><strong> when </strong></span><span style="text-decoration:underline;"><span style="font-weight:normal;"><strong>first time</strong></span></span><span style="font-weight:normal;"><strong> creating the facory. This is good practise because if there is any dependency error everything can be resolved at </strong></span><span style="text-decoration:underline;"><span style="font-weight:normal;"><strong>the time</strong></span></span><span style="font-weight:normal;"><strong> of </strong></span><span style="text-decoration:underline;"><span style="font-weight:normal;"><strong>startup</strong></span></span><span style="font-weight:normal;"><strong>. This is not case in all the application scnarios.</strong></span></p>
<p><span style="font-weight:normal;"><strong>The following are the few drawbacks in pre-initiating all </strong></span><span style="font-weight:normal;"><strong>the beans</strong></span><span style="font-weight:normal;"><strong> at </strong></span><span style="font-weight:normal;"><strong>startup</strong></span><span style="font-weight:normal;"><strong>:</strong></span></p>
<ul>
<li><span style="font-weight:normal;"><strong>Takes long time to start the application. Since </strong></span><span style="font-weight:normal;"><strong>BeanFactory</strong></span><span style="font-weight:normal;"><strong> has to initiate all </strong></span><span style="font-weight:normal;"><strong>the beans</strong></span><span style="font-weight:normal;"><strong> even if it is unnecessary.</strong></span></li>
<li><span style="font-weight:normal;"><strong>More memory for storing all </strong></span><span style="font-weight:normal;"><strong>the beans</strong></span><span style="font-weight:normal;"><strong>.</strong></span></li>
</ul>
<p><span style="font-weight:normal;"><strong>Based on the above impacts, some applications required beans to initiate only when they are required.</strong></span><span style="font-weight:normal;"><strong>Spring</strong></span><span style="font-weight:normal;"><strong> provides an attribute called </strong></span><span style="font-weight:normal;"><strong>lazy-init</strong></span><span style="font-weight:normal;"><strong> to inform the </strong></span><span style="text-decoration:underline;"><span style="font-weight:normal;"><strong>Spring</strong></span></span><span style="font-weight:normal;"><strong> IOC</strong></span><span style="font-weight:normal;"><strong> container for not creatinmg that bean at the </strong></span><span style="font-weight:normal;"><strong>startup</strong></span><span style="font-weight:normal;"><strong>. </strong></span><span style="font-weight:normal;"><strong>lazy-init</strong></span><span style="font-weight:normal;"><strong>will be set as </strong></span><span style="font-weight:normal;"><strong>true</strong></span><span style="font-weight:normal;"><strong> to indicate the container. </strong></span><span style="font-weight:normal;"><strong>The beans</strong></span><span style="font-weight:normal;"><strong> will be created only when requested.</strong></span><span style="font-weight:normal;"><strong> </strong></span></p>
<p><span style="font-weight:normal;"><strong>Conside when there is a bean which is initiated at the </strong></span><span style="font-weight:normal;"><strong>startup</strong></span><span style="font-weight:normal;"><strong>. But, it has </strong></span><span style="font-weight:normal;"><strong>depends-on</strong></span><span style="font-weight:normal;"><strong> attribute pointing to the bean which is set as </strong></span><span style="font-weight:normal;"><strong>lazy-init=&#8221;true&#8221;</strong></span><span style="font-weight:normal;"><strong>. This case the can will be initiated without considering </strong></span><span style="font-weight:normal;"><strong>lazy-init</strong></span><span style="font-weight:normal;"><strong> value.</strong></span></p>
<p><span style="font-weight:normal;"><strong>Reference</strong></span></p>
<p><span style="font-weight:normal;"><strong><a class="aligncenter" title="Lazy Loading of beans" href="http://www.javabeat.net/tips/97-how-to-lazy-initialize-spring-beans.html" target="_blank">http://www.javabeat.net/tips/97-how-to-lazy-initialize-spring-beans.html</a></strong></span></p>
<p><span style="font-weight:normal;"><strong><br />
</strong></span></p>
<p><strong> </strong></p>
</div>
<div style="padding:10px;"><strong>Q: What is the difference between load() and get() methods in Hibernate ?</strong></div>
<div style="padding:10px;"><strong>Q: What is lazy loading in Hibernate ? Suppose i have a one-to-many relation ship between emp and dept table in hibernate with lazy loading is set true. Then when the employee instance will beloaded: </strong></div>
<div style="padding:10px;"><strong>i: when i called the getEmployee() method,</strong></div>
<div style="padding:10px;"><strong>ii: When i called getEmployee().getName().</strong></div>
<div style="padding:10px;"><strong>Q:  How pageContext implicit variable variable is useful.</strong></div>
<div style="padding:10px;"><strong>=========</strong></div>
<div style="padding:10px;">
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Q:How to synchronize arraylist?</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">A:by using the method Collections.synchronizedList(); ,</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">ArrayList al=new ArrayList();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">al.add(&#8220;lolo&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">al.add(&#8220;polo&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">al.add(&#8220;hai&#8221;);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Collections.synchronizedList(al);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Q:In How Many Ways can you create an object for a class in java?</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">A:There are four ways in which we can create an object for a class in java</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Using New Operator: like Test t=new Test();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Using newInstance(): like Test t=(Test)Class.forName(&#8220;&#8221;).newInstance();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Using Clone: like</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Test x=new Test();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Test t=x.clone();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Using Object Deserialization : like ObjectInputStream istream=new ObjectInputStream(some inputStream);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Q:<span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Can we create constructor for an abstract class?</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">A:<span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Yes , we can create Constructor for abstaract class. The constructor will be invoked while instantiating its subclass object. The constructor can be explicitly by using super keyword.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Q:<span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">Is it possible to override static method?</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:13466px;width:1px;height:1px;">
<p>A:No it is not possible to override a static method. This because there is only 1 instance of a static method.</p>
</div>
</div>
<p><strong>Q: How to synchronize arraylist? </strong></p>
<p>A:by using the method Collections.synchronizedList(); ,</p>
<p>ArrayList al=new ArrayList();</p>
<p>al.add(&#8220;lolo&#8221;);</p>
<p>al.add(&#8220;polo&#8221;);</p>
<p>al.add(&#8220;hai&#8221;);</p>
<p>Collections.synchronizedList(al);</p>
<p><strong>Q:In How Many Ways can you create an object for a class in java?</strong></p>
<p>A:There are four ways in which we can create an object for a class in java</p>
<p>Using New Operator: like Test t=new Test();</p>
<p>Using newInstance(): like Test t=(Test)Class.forName(&#8220;&#8221;).newInstance();</p>
<p>Using Clone: like</p>
<p>Test x=new Test();</p>
<p>Test t=x.clone();</p>
<p>Using Object Deserialization : like ObjectInputStream istream=new ObjectInputStream(some inputStream);</p>
<p><strong>Q:</strong><span style="white-space:pre;"><strong> </strong></span><strong>Can we create constructor for an abstract class?</strong></p>
<p>A:<span style="white-space:pre;"> </span>Yes , we can create Constructor for abstaract class. The constructor will be invoked while instantiating its subclass object. The constructor can be explicitly by using super keyword.</p>
<p><strong>Q:</strong><span style="white-space:pre;"><strong> </strong></span><strong>Is it possible to override static method?</strong></p>
<p>A: No it is not possible to override a static method. This because there is only 1 instance of a static method.</p>
<p><strong>Q: How can container knows that JSP has been changed ? ex: I created one.jsp and the result has been displayed. Next i modified one.jsp and got the new result. but how can container know that one.jsp has got changed?</strong></p>
<p>A: By checking the &#8220;time stamp&#8221; of the jsp file</p>
<p><strong>Q: What&#8217;s the difference between the methods sleep() and wait()</strong></p>
<p>A: The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.</p>
<p><strong>Q: State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.</strong></p>
<p>A: public : Public class is visible in other packages, field is visible everywhere (class must be public too)</p>
<p>private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.</p>
<p>protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.</p>
<p>default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package.</p>
<p><strong>Q: What is static in java?</strong></p>
<p>A: Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can&#8217;t override a static method with a nonstatic method. In other words, you can&#8217;t change a static method into an instance method in a subclass.</p>
<p><strong>Q: Difference between HashMap and HashTable?</strong></p>
<p>A: The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.</p>
<p><strong>Q: What if the main method is declared as private?</strong></p>
<p><strong><span style="font-weight:normal;">A: The program compiles properly but at runtime it will give &#8220;Main method not public.&#8221; message.</span></strong></p>
<p><strong><span style="font-weight:normal;"><strong>Q: If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?</strong></span></strong></p>
<p><strong>A: It is empty. But not null.</strong></p>
<p><strong><strong>Q: How can one prove that the array is not null but empty using one line of code?</strong></strong></p>
<p><strong>A: Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.</strong></p>
<p><strong><strong>Q: What are Checked and UnChecked Exception?</strong></strong></p>
<p><strong>A:A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.</strong></p>
<p><strong>Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream&#8217;s read() method·</strong></p>
<p><strong>Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn&#8217;t force client programmers either to catch the</strong></p>
<p><strong>exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String&#8217;s charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.</strong></p>
<p><strong><strong>Q: What are different types of inner classes?</strong></strong></p>
<p><strong>A:Nested top-level classes, Member classes, Local classes, Anonymous classes</strong></p>
<p><strong><strong>Nested top-level classes</strong>- <span style="font-weight:normal;">If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class.</span></strong></p>
<p><span style="font-weight:normal;"><strong>Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested top-level variety.</strong></span></p>
<p><strong><strong>Member classes</strong> &#8211; <span style="font-weight:normal;">M</span><span style="font-weight:normal;">ember inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.</span></strong></p>
<p><strong><strong>Local classes</strong> -<span style="font-weight:normal;"> Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a</span></strong></p>
<p><span style="font-weight:normal;"><strong>more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.</strong></span></p>
<p><strong><strong>Anonymous classes </strong>- <span style="font-weight:normal;">Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.</span></strong></p>
<p><strong>Q: What is the difference between declaring a variable and defining a variable?</strong></p>
<p><span style="font-weight:normal;">A: In declaration we just mention the type of the variable and it&#8217;s name. We do not initialize it. But defining means declaration + initialization.</span></p>
<p><span style="font-weight:normal;">e.g String s; is just a declaration while String s = new String (&#8220;abcd&#8221;); Or String s = &#8220;abcd&#8221;; are both definitions.</span></p>
<p><span style="font-weight:normal;"><strong><strong>Q: Give a simplest way to find out the time a method takes for execution without using any profiling tool?</strong></strong></span></p>
<p><strong>A:  Read the system time just before the method is invoked and immediately after method returns. Take the time difference, which will give you the time taken by a method for execution.</strong></p>
<p>To put it in code&#8230;</p>
<p>long start = System.currentTimeMillis ();</p>
<p>method ();</p>
<p>long end = System.currentTimeMillis ();</p>
<p>System.out.println (&#8220;Time taken for execution is &#8221; + (end &#8211; start));</p>
<p>Remember that if the time taken for execution is too small, it might show that it is taking zero milliseconds for execution. Try it on a method which is big enough, in the sense the one which is doing considerable amout of processing.</p>
<p><strong>Q:  How to call a procedure having more than one out parameter ?</strong></p>
<p>package proceduretest;</p>
<p>import java.sql.CallableStatement;<br />
import java.sql.Connection;<br />
import java.sql.DriverManager;<br />
import java.sql.ResultSet;<br />
import java.sql.Statement;<br />
import java.sql.Types;</p>
<p>import oracle.jdbc.driver.OracleTypes;</p>
<p>public class CallingProcedure {<br />
public static void main(String[] args) throws Exception {<br />
Connection con = null;<br />
try {<br />
Class.forName(&#8220;oracle.jdbc.driver.OracleDriver&#8221;);<br />
con = DriverManager.getConnection(<br />
&#8220;jdbc:oracle:thin:@localhost:1521:XE&#8221;, &#8220;jyoti&#8221;, &#8220;mishra&#8221;);</p>
<p>/**<br />
*<br />
*<br />
* Procedure For Below ResultSets<br />
* ===================================<br />
* create or replace PROCEDURE<br />
* getName(emp__CURSOR1 OUT SYS_REFCURSOR,emp__CURSOR2 OUT<br />
* SYS_REFCURSOR, salary out NUMBER, empnumber in number)<br />
* AS<br />
* BEGIN<br />
* OPEN emp__CURSOR1 FOR SELECT ename FROM EMP where<br />
* empno=empnumber;<br />
*<br />
* OPEN emp__CURSOR2 FOR SELECT * FROM EMP ;<br />
*<br />
* SELECT SAL INTO salary FROM EMP WHERE EMPNO=empnumber;<br />
*<br />
* END;<br />
*<br />
*<br />
*<br />
*<br />
*/<br />
CallableStatement cstmt = con<br />
.prepareCall(&#8220;{call GETNAME(?,?,?,?)}&#8221;);<br />
cstmt.registerOutParameter(1, OracleTypes.CURSOR);<br />
cstmt.registerOutParameter(2, OracleTypes.CURSOR);<br />
cstmt.registerOutParameter(3, Types.FLOAT);<br />
cstmt.setInt(4, 7369);<br />
boolean resultsAvailable = cstmt.execute();<br />
System.out.println(&#8220;Resultset available &#8221; + resultsAvailable);<br />
ResultSet rs1 = (ResultSet) cstmt.getObject(1);<br />
System.out.println(&#8220;Empname  &#8221; + &#8220;Name  &#8221; + &#8221; JOB&#8221;);<br />
while (rs1.next()) {<br />
System.out.println(&#8220;Employee Nmae having ID 7369 : &#8220;<br />
+ rs1.getString(1) + &#8221; &#8220;);<br />
}<br />
System.out.println(&#8220;=====================\n\n&#8221;);<br />
/*rs1 = (ResultSet) cstmt.getObject(2);<br />
while (rs1.next()) {<br />
System.out.print(&#8221; &#8221; + rs1.getInt(1) + &#8221; &#8220;);<br />
System.out.print(rs1.getString(2) + &#8221; &#8220;);<br />
System.out.print(rs1.getString(3) + &#8221; &#8220;);<br />
System.out.print(rs1.getInt(4) + &#8221; &#8220;);<br />
System.out.print(rs1.getDate(5) + &#8221; &#8220;);<br />
System.out.print(rs1.getInt(6) + &#8221; &#8220;);<br />
System.out.print(rs1.getInt(7) + &#8221; &#8220;);<br />
System.out.println(rs1.getInt(8) + &#8221; &#8220;);<br />
}*/<br />
Float sal = cstmt.getFloat(3);<br />
System.out.println(&#8220;Employee Salary having ID 7369 : &#8221; + sal);<br />
} catch (ClassNotFoundException cnf) {<br />
System.out.println(cnf.getMessage());<br />
}</p>
<p>}<br />
}</p>
<p><strong> </strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jyotimishra.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jyotimishra.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jyotimishra.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jyotimishra.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jyotimishra.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jyotimishra.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jyotimishra.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jyotimishra.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jyotimishra.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jyotimishra.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jyotimishra.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jyotimishra.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jyotimishra.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jyotimishra.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=14&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jyotimishra.wordpress.com/2009/07/23/interview-questions-and-answers/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d1732956322c2ff2dd8b6900eff22e5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jyotimishra</media:title>
		</media:content>

		<media:content url="http://wiki.metawerx.net/images/out.png" medium="image" />

		<media:content url="http://jyotimishra.files.wordpress.com/2009/07/image0011.png?w=300" medium="image">
			<media:title type="html">image001</media:title>
		</media:content>

		<media:content url="http://tech.inhelsinki.nl/2007-08-29/graph-java-xml-performance.png" medium="image">
			<media:title type="html">Sax vs Dom</media:title>
		</media:content>
	</item>
		<item>
		<title>Constructor In Hibernate Query Language</title>
		<link>http://jyotimishra.wordpress.com/2009/07/18/constructor-in-hibernate-query-language/</link>
		<comments>http://jyotimishra.wordpress.com/2009/07/18/constructor-in-hibernate-query-language/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 19:03:11 +0000</pubDate>
		<dc:creator>jyotimishra</dc:creator>
				<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://jyotimishra.wordpress.com/2009/07/18/constructor-in-hibernate-query-language/</guid>
		<description><![CDATA[Need of Constructor in HQL Well when we use hql statement that will select all the attributes from the POJO class, no problem to type cast the retuen type to corresponding POJO Class reference. As below example shows: List list = session.createQuery(&#8220;from Contact c &#8220;).list(); for (Iterator iterator = list.iterator(); iterator.hasNext();) { Contact contact = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=12&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong></strong><strong>Need of Constructor in HQL</strong></p>
<p><strong></strong><br />
Well when we use hql statement that will select all the attributes from the POJO class, no problem to type cast the retuen type to corresponding POJO Class reference. As below example shows:<br />
List list = session.createQuery(&#8220;from Contact c &#8220;).list();<br />
for (Iterator iterator = list.iterator(); iterator.hasNext();) {<br />
Contact contact = (Contact) iterator.next();<br />
System.out.print(&#8220;First Name ==&gt;&gt; &#8221; + contact.getFirstName());<br />
System.out.println(&#8220;Last Name ==&gt;&gt; &#8221; + contact.getLastName());<br />
}</p>
<p>This time the &#8220;list&#8221; contain object of type Contact. So no problem in type casting it to Contact class (pojo) reference. But what will happened if we select specified attributes like below:</p>
<p>List list = session.createQuery(&#8220;select c.firstName, c.lastName from Contact c &#8220;).list();<br />
for (Iterator iterator = list.iterator(); iterator.hasNext();) {<br />
Contact contact = (Contact) iterator.next();<br />
System.out.print(&#8220;First Name ==&gt;&gt; &#8221; + contact.getFirstName());<br />
System.out.println(&#8221; Last Name ==&gt;&gt; &#8221; + contact.getLastName());<br />
}</p>
<p>This time it will through a java.lang.ClassCastException. Beacuse this time the list contains type Object. So it is not possible to type cast to POJO class reference.<br />
But in some cases we required pojo class object. At that time constructor will be usefull in HQL statements. Create a constructor using those attributes which you required in select statements. Like below:<br />
<strong>Contact.java</strong><br />
package jyoti.ssis.hibernate;<br />
/** * @author Jyoti Ranjna * *<br />
* Java Class to map to the datbase Contact Table<br />
*/<br />
public class Contact {<br />
private String firstName;<br />
private String lastName;<br />
private String email;<br />
private long id;<br />
/* Default Constructor<br />
* */<br />
public Contact() {<br />
}<br />
/** required parametrized constructor<br />
* @param firstName<br />
* @param lastName<br />
*/<br />
public Contact(String firstName, String lastName) {<br />
this.firstName = firstName;<br />
this.lastName = lastName;<br />
}<br />
/** * @return Email<br />
*/<br />
public String getEmail() {<br />
return email;<br />
}<br />
/** * @return First Name<br />
*/<br />
public String getFirstName() {<br />
return firstName;<br />
}<br />
/** * @return Last name<br />
*/<br />
public String getLastName() {<br />
return lastName;<br />
}<br />
/** * @param string Sets the Email<br />
*/<br />
public void setEmail(String string) {<br />
email = string;<br />
}<br />
/** * @param string Sets the First Name<br />
*/<br />
public void setFirstName(String string) {<br />
firstName = string;<br />
}<br />
/** * @param string sets the Last Name<br />
*/<br />
public void setLastName(String string) {<br />
lastName = string;<br />
}<br />
/** * @return ID Returns ID<br />
*/<br />
public long getId() {<br />
return id;<br />
}<br />
/** * @param l Sets the ID<br />
*/<br />
public void setId(long l) {<br />
id = l;<br />
}<br />
}</p>
<p>Corresponding Mapping file<br />
<strong>contact.hbm.xml</strong></p>
<p>&lt;?xml version=&#8221;1.0&#8243;?&gt;<br />
&lt;!DOCTYPE hibernate-mapping PUBLIC<br />
&#8220;-//Hibernate/Hibernate Mapping DTD 3.0//EN&#8221;<br />
<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>&gt;</p>
<p>&lt;hibernate-mapping&gt;<br />
&lt;class name=&#8221;jyoti.ssis.hibernate.Contact&#8221; table=&#8221;CONTACT&#8221;&gt;<br />
&lt;id name=&#8221;id&#8221; column=&#8221;ID&#8221;&gt;&lt;generator&gt;&lt;/id&gt;<br />
&lt;property name=&#8221;firstName&#8221;&gt;&lt;column name=&#8221;FIRSTNAME&#8221;&gt;&lt;/property&gt;<br />
&lt;property name=&#8221;lastName&#8221;&gt;&lt;column name=&#8221;LASTNAME&#8221;&gt;&lt;/property&gt;<br />
&lt;property name=&#8221;email&#8221;&gt;&lt;column name=&#8221;EMAIL&#8221;&gt;&lt;/property&gt;<br />
&lt;/class&gt;<br />
&lt;/hibernate-mapping&gt;</p>
<p>Finally the main class where we will use the constructor for getting the pojo class object</p>
<p><strong>SelectHQLExampleUsingConstructor.java<br />
</strong>package jyoti.ssis.hibernate;<br />
import java.util.Iterator;<br />
import java.util.List;<br />
import org.hibernate.Session;<br />
import org.hibernate.SessionFactory;<br />
import org.hibernate.cfg.Configuration;<br />
/** * @author Jyoti Ranjan * *<br />
Select HQL Example Using Constructor<br />
*/</p>
<p>public class SelectHQLExampleUsingConstructor {<br />
static SessionFactory sessionFactory =null;<br />
public static void main(String[] args) {<br />
Session session = null;<br />
try {<br />
//Get Session From Session Factory<br />
session = getSession();<br />
String s = &#8220;Jyoti&#8221;;<br />
List list = session.createQuery( &#8220;select new Contact(c.firstName, c.lastName)from Contact c where c.firstName like &#8216;&#8221;+s+&#8221;&#8216;&#8221;).list();<br />
for (Iterator iterator = list.iterator(); iterator.hasNext();) {<br />
Contact contact = (Contact) iterator.next();<br />
System.out.print(&#8220;First Name ==&gt;&gt; &#8221; + contact.getFirstName());<br />
System.out.println(&#8221; Last Name ==&gt;&gt; &#8221; + contact.getLastName());<br />
}<br />
} catch (Exception e) {<br />
System.out.println(e.getMessage());<br />
} finally {<br />
if (session != null) session.close();<br />
}<br />
}<br />
public static Session getSession(){<br />
//Create HibernateSessionFactory<br />
if(sessionFactory==null){<br />
sessionFactory = new Configuration().configure().buildSessionFactory();<br />
}<br />
return sessionFactory.openSession();<br />
}<br />
}</p>
<p>Finally the hibernate configuration file<br />
<strong>hibernate.cfg.xml<br />
</strong><br />
&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;utf-8&#8242;?&gt;<br />
&lt;!DOCTYPE hibernate-configuration PUBLIC<br />
&#8220;-//Hibernate/Hibernate Configuration DTD//EN&#8221;<br />
<a href="http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd</a>&gt;</p>
<p>&lt;hibernate-configuration&gt;<br />
&lt;session-factory&gt;<br />
&lt;property name=&#8221;hibernate.connection.pool_size&#8221;&gt;10&lt;/property&gt;<br />
&lt;property name=&#8221;show_sql&#8221;&gt;true&lt;/property&gt;<br />
&lt;property name=&#8221;dialect&#8221;&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;<br />
&lt;property name=&#8221;hibernate.hbm2ddl.auto&#8221;&gt;update&lt;/property&gt;<br />
&lt;property name=&#8221;myeclipse.connection.profile&#8221;&gt;mysql&lt;/property&gt;<br />
&lt;property name=&#8221;connection.url&#8221;&gt;jdbc:mysql://localhost:3306/hibernate&lt;/property&gt;<br />
&lt;property name=&#8221;connection.username&#8221;&gt;root&lt;/property&gt;<br />
&lt;property name=&#8221;connection.password&#8221;&gt;root&lt;/property&gt;<br />
&lt;property name=&#8221;connection.driver_class&#8221;&gt;com.mysql.jdbc.Driver&lt;/property&gt;<br />
&lt;mapping resource=&#8221;jyoti/ssis/hibernate/contact.hbm.xml&#8221;&gt;&lt;/session-factory&gt;<br />
&lt;/hibernate-configuration&gt;</p>
<p>Run application by setting hibernate required jar files in class path. The out put of the application should come like this on eclipse console:<br />
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly.<br />
Hibernate: select contact0_.FIRSTNAME as col_0_0_, contact0_.LASTNAME as col_1_0_ from CONTACT contact0_ where (contact0_.FIRSTNAME like &#8216;Jyoti&#8217;)<br />
First Name ==&gt;&gt; Jyoti Last Name ==&gt;&gt; Ranjan</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jyotimishra.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jyotimishra.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jyotimishra.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jyotimishra.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jyotimishra.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jyotimishra.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jyotimishra.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jyotimishra.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jyotimishra.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jyotimishra.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jyotimishra.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jyotimishra.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jyotimishra.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jyotimishra.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=12&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jyotimishra.wordpress.com/2009/07/18/constructor-in-hibernate-query-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d1732956322c2ff2dd8b6900eff22e5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jyotimishra</media:title>
		</media:content>
	</item>
		<item>
		<title>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure</title>
		<link>http://jyotimishra.wordpress.com/2009/07/15/communications-link-failure/</link>
		<comments>http://jyotimishra.wordpress.com/2009/07/15/communications-link-failure/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 07:09:32 +0000</pubDate>
		<dc:creator>jyotimishra</dc:creator>
				<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Communications link failure problem in Hibernate and Solution I am using c3po connection pool and the settings in the hibernate.cfg.xml file for c3po is as follows &#60;property name=&#8221;c3p0.min_size&#8221;&#62;5&#60;/property&#62; &#60;property name=&#8221;c3p0.max_size&#8221;&#62;20&#60;/property&#62; &#60;property name=&#8221;c3p0.timeout&#8221;&#62;1800&#60;/property&#62; &#60;property name=&#8221;c3p0.max_statements&#8221;&#62;50&#60;/property&#62; &#60;property name=&#8221;connection.provider_class&#8221;&#62;org.hibernate.connection.C3P0ConnectionProvider&#60;/property&#62; But what happened after a certain amount of connection idle time, i am getting the following error. I solve [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=1&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;"><strong>Communications link failure  problem in Hibernate and Solution</strong></p>
<p style="text-align:left;">I am using c3po connection pool and the settings in the hibernate.cfg.xml file for c3po is as follows</p>
<p style="text-align:left;">
<p style="text-align:left;">&lt;property name=&#8221;c3p0.min_size&#8221;&gt;5&lt;/property&gt;<br />
&lt;property name=&#8221;c3p0.max_size&#8221;&gt;20&lt;/property&gt;<br />
&lt;property name=&#8221;c3p0.timeout&#8221;&gt;1800&lt;/property&gt;<br />
&lt;property name=&#8221;c3p0.max_statements&#8221;&gt;50&lt;/property&gt;<br />
&lt;property name=&#8221;connection.provider_class&#8221;&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/property&gt;</p>
<p style="text-align:left;">
<p style="text-align:left;">But what happened after a certain amount of connection idle time, i am getting the following error. I solve the error as mentioned following:</p>
<p style="text-align:left;">
<p><strong>Error Message From Log File</strong></p>
<p>WARN TP-Processor2 org.hibernate.util.JDBCExceptionReporter &#8211; SQL Error: 0, SQLState: 08003<br />
ERROR TP-Processor2 org.hibernate.util.JDBCExceptionReporter &#8211; No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:</p>
<p>** BEGIN NESTED EXCEPTION **</p>
<p>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException<br />
MESSAGE: The last packet successfully received from the server was34330 seconds ago.The last packet sent successfully to the server was 34330 seconds ago, which  is longer than the server configured value of &#8216;wait_timeout&#8217;. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property &#8216;autoReconnect=true&#8217; to avoid this problem.</p>
<p>STACKTRACE:</p>
<p>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was34330 seconds ago.The last packet sent successfully to the server was 34330 seconds ago, which  is longer than the server configured value of &#8216;wait_timeout&#8217;. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property &#8216;autoReconnect=true&#8217; to avoid this problem.<br />
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)<br />
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)<br />
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)<br />
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)<br />
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)<br />
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)<br />
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3246)<br />
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917)<br />
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)<br />
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)<br />
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)<br />
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)<br />
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)<br />
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)<br />
at org.hibernate.loader.Loader.doQuery(Loader.java:662)<br />
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)<br />
at org.hibernate.loader.Loader.doList(Loader.java:2145)<br />
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)<br />
at org.hibernate.loader.Loader.list(Loader.java:2024)<br />
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)<br />
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)<br />
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)<br />
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)<br />
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)<br />
at com.softidsolutions.mypaydayadvancenow.admin.dao.AdminloginDAO.validateAdmin(AdminloginDAO.java:172)<br />
at com.softidsolutions.mypaydayadvancenow.admin.services.AdminServices.validateAdmin(AdminServices.java:17)<br />
at com.softidsolutions.mypaydayadvancenow.admin.action.AdminLoginAction.execute(AdminLoginAction.java:34)<br />
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)<br />
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)<br />
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)<br />
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)<br />
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)<br />
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)<br />
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)<br />
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)<br />
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)<br />
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)<br />
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)<br />
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)<br />
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)<br />
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)<br />
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:200)<br />
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)<br />
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:773)<br />
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)<br />
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:895)<br />
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)<br />
at java.lang.Thread.run(Thread.java:619)<br />
Caused by: java.net.SocketException: Software caused connection abort: socket write error<br />
at java.net.SocketOutputStream.socketWrite0(Native Method)<br />
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)<br />
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)<br />
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)<br />
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)<br />
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3227)<br />
&#8230; 41 more</p>
<p>** END NESTED EXCEPTION **</p>
<p>ERROR TP-Processor2 com.softidsolutions.mypaydayadvancenow.admin.dao.AdminloginDAO &#8211; Validating Login Failed , Error is  could not execute query<br />
INFO TP-Processor2 com.softidsolutions.mypaydayadvancenow.admin.dao.AdminloginDAO &#8211; Time is: 05-29-2009 11:18:35 AM CDT<br />
INFO TP-Processor2 com.softidsolutions.mypaydayadvancenow.admin.dao.AdminloginDAO &#8211; Closing Session<br />
INFO TP-Processor2 com.softidsolutions.mypaydayadvancenow.admin.dao.AdminloginDAO &#8211; Time is: 05-29-2009 11:18:35 AM CDT<br />
INFO TP-Processor2 com.softidsolutions.mypaydayadvancenow.admin.dao.AdminloginDAO &#8211; Validating AdminLogin<br />
INFO TP-Processor2 com.softidsolutions.mypaydayadvancenow.admin.dao.AdminloginDAO &#8211; Time is: 05-29-2009 11:18:53 AM CDT<br />
WARN TP-Processor2 org.hibernate.util.JDBCExceptionReporter &#8211; SQL Error: 0, SQLState: 08003<br />
ERROR TP-Processor2 org.hibernate.util.JDBCExceptionReporter &#8211; No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:</p>
<p>** BEGIN NESTED EXCEPTION **</p>
<p>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException<br />
MESSAGE: The last packet successfully received from the server was34330 seconds ago.The last packet sent successfully to the server was 34330 seconds ago, which  is longer than the server configured value of &#8216;wait_timeout&#8217;. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property &#8216;autoReconnect=true&#8217; to avoid this problem.</p>
<p>STACKTRACE:</p>
<p>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was34330 seconds ago.The last packet sent successfully to the server was 34330 seconds ago, which  is longer than the server configured value of &#8216;wait_timeout&#8217;. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property &#8216;autoReconnect=true&#8217; to avoid this problem.<br />
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)<br />
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)<br />
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)<br />
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)<br />
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)<br />
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)<br />
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3246)<br />
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917)<br />
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)<br />
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)<br />
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)<br />
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)<br />
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)<br />
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)<br />
at org.hibernate.loader.Loader.doQuery(Loader.java:662)<br />
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)<br />
at org.hibernate.loader.Loader.doList(Loader.java:2145)<br />
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)<br />
at org.hibernate.loader.Loader.list(Loader.java:2024)<br />
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)<br />
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)<br />
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)<br />
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)<br />
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)<br />
at com.softidsolutions.mypaydayadvancenow.admin.dao.AdminloginDAO.validateAdmin(AdminloginDAO.java:172)<br />
at com.softidsolutions.mypaydayadvancenow.admin.services.AdminServices.validateAdmin(AdminServices.java:17)<br />
at com.softidsolutions.mypaydayadvancenow.admin.action.AdminLoginAction.execute(AdminLoginAction.java:34)<br />
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)<br />
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)<br />
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)<br />
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)<br />
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)<br />
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)<br />
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)<br />
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)<br />
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)<br />
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)<br />
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)<br />
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)<br />
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)<br />
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)<br />
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:200)<br />
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)<br />
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:773)<br />
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)<br />
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:895)<br />
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)<br />
at java.lang.Thread.run(Thread.java:619)<br />
Caused by: java.net.SocketException: Software caused connection abort: socket write error<br />
at java.net.SocketOutputStream.socketWrite0(Native Method)<br />
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)<br />
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)<br />
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)<br />
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)<br />
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3227)<br />
&#8230; 41 more</p>
<p>** END NESTED EXCEPTION **</p>
<p><strong>SOLUTION</strong></p>
<p>You need to create a properties file like c3p0.properties and place the file in the class path of your project.</p>
<p>Place the following code in that file</p>
<p><strong>c3p0.testConnectionOnCheckout=true</strong></p>
<p>What the following code will do is:</p>
<p>it will check whether the connection is disconnected. If the connection is disconnected it will reconnect automatically.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jyotimishra.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jyotimishra.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jyotimishra.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jyotimishra.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jyotimishra.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jyotimishra.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jyotimishra.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jyotimishra.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jyotimishra.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jyotimishra.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jyotimishra.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jyotimishra.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jyotimishra.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jyotimishra.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jyotimishra.wordpress.com&amp;blog=8580900&amp;post=1&amp;subd=jyotimishra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jyotimishra.wordpress.com/2009/07/15/communications-link-failure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d1732956322c2ff2dd8b6900eff22e5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jyotimishra</media:title>
		</media:content>
	</item>
	</channel>
</rss>
