<?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/"
	>

<channel>
	<title>Java Interview Questions &#187; Uncategorized</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 30 Jul 2010 06:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>File Uploading Using Servlet</title>
		<link>http://www.bestjavainterviewquestions.com/file-uploading-using-servlet/</link>
		<comments>http://www.bestjavainterviewquestions.com/file-uploading-using-servlet/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 15:30:33 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[File Uploading using Servlet]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=531</guid>
		<description><![CDATA[FileUploading Using Servlet(JAVA) This is an example of the file Uploading in Java using Servlets . This file uploading concept Works with the Java as follows The Servlet api consists of the method called getContentType which takes the file request as the input and generates the file to the specified path Here is the Code [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>FileUploading Using Servlet(JAVA)</strong></span></p>
<p>This is an example of the file Uploading in Java using Servlets . This file uploading concept Works with the Java as follows</p>
<p>The Servlet api consists of the method called getContentType which takes the file request as the input and generates the file to the specified path</p>
<p>Here is the Code of the file Uploading using Servlets in JAVA</p>
<p><strong>Name the HTML page as file.html</strong></p>
<p><em>&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;&gt;<br />
&lt;html&gt;<br />
&lt;form method=&#8221;post&#8221; action=&#8221;servlet/UploadFile&#8221; enctype=&#8221;multipart/form-data&#8221;&gt;<br />
Name<br />
&lt;input type=&#8221;text&#8221; name=&#8221;uname&#8221;/&gt;<br />
File<br />
&lt;input type=&#8221;file&#8221; name=&#8221;upfile&#8221;/&gt;<br />
&lt;input type=&#8221;submit&#8221;/&gt;<br />
&lt;/form&gt;<br />
&lt;/html&gt;</em></p>
<p>Specify the action path to which servlet to must follow and the type of the data to send to the servlet is specified by the <em>enctype=&#8221;multipart/form-data&#8221; </em></p>
<p>Once the request goes to the servlet the request is collected through getContentType() method (to learn more  about <a class="wp-caption" title="Javax.Servlet Interface" href="http://computerpreferedcourses.blogspot.com/2009/01/javaxservlet-interface-servletrequest.html" target="_blank">getContentType</a>)</p>
<p>Write the servlet code and specify the name of the servlet as <strong><em>UploadFile.java</em></strong></p>
<p><em>package com.myapp.struts;</em></p>
<p><em>import java.io.*;<br />
import java.sql.*;<br />
import javax.servlet.http.HttpServlet;<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;<br />
import javax.servlet.ServletInputStream.*;<br />
import java.io.PrintWriter;</em></p>
<p><em>public class UploadFile extends HttpServlet {</em></p>
<p><em>public void doPost(HttpServletRequest req,HttpServletResponse res)<br />
{</em></p>
<p><em>try{</em></p>
<p><em>//out.println(&#8220;&lt;br&gt;Content type is :: &#8221; +contentType);<br />
//to get the content type information from JSP Request Header</em></p>
<p><em>String contentType = req.getContentType();<br />
int flag=0;<br />
FileInputStream fis=null;<br />
FileOutputStream fileOut=null;</em></p>
<p><em>//here we are checking the content type is not equal to Null and as well as the passed data from mulitpart/form-data is greater than or equal to 0</em></p>
<p><em>if ((contentType != null) &amp;&amp; (contentType.indexOf(&#8220;multipart/form-data&#8221;) &gt;= 0))<br />
{<br />
DataInputStream in = new DataInputStream(req.getInputStream());</em></p>
<p><em>//we are taking the length of Content type data</em></p>
<p><em>int formDataLength = req.getContentLength();<br />
byte dataBytes[] = new byte[formDataLength];<br />
int byteRead = 0;<br />
int totalBytesRead = 0;</em></p>
<p><em>//this loop converting the uploaded file into byte code</em></p>
<p><em>while (totalBytesRead &lt; formDataLength) {<br />
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);<br />
totalBytesRead += byteRead;<br />
}</em></p>
<p><em>String file = new String(dataBytes);</em></p>
<p><em>//for saving the file name</em></p>
<p><em>String saveFile = file.substring(file.indexOf(&#8220;filename=\&#8221;") + 10);<br />
saveFile = saveFile.substring(0, saveFile.indexOf(&#8220;\n&#8221;));<br />
out.println(&#8220;savefiledddd    &#8220;+saveFile);<br />
int extension_save=saveFile.lastIndexOf(&#8220;\&#8221;");</em></p>
<p><em>//Here we are invoking the absolute path out of the encrypted data</em></p>
<p><em>saveFile = saveFile.substring(saveFile.lastIndexOf(&#8220;\\&#8221;)+ 1,saveFile.indexOf(&#8220;\&#8221;"));<br />
int lastIndex = contentType.lastIndexOf(&#8220;=&#8221;);<br />
String boundary = contentType.substring(lastIndex + 1,contentType.length());<br />
int pos;</em></p>
<p><em>//extracting the index of file</em></p>
<p><em>pos = file.indexOf(&#8220;filename=\&#8221;");<br />
pos = file.indexOf(&#8220;\n&#8221;, pos) + 1;<br />
pos = file.indexOf(&#8220;\n&#8221;, pos) + 1;<br />
pos = file.indexOf(&#8220;\n&#8221;, pos) + 1;<br />
int boundaryLocation = file.indexOf(boundary, pos) &#8211; 4;<br />
int startPos = ((file.substring(0, pos)).getBytes()).length;<br />
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;</em></p>
<p><em>out.println(&#8220;savefile&#8221;+saveFile);</em></p>
<p><em>String pathname_dir=&#8221;D:\\test\\&#8221;+saveFile;<br />
File filepath=new File(pathname_dir);<br />
out.println(&#8220;filepath_  &#8220;+filepath);<br />
fileOut = new FileOutputStream(filepath);<br />
fileOut.write(dataBytes, startPos, (endPos &#8211; startPos));<br />
fileOut.flush();<br />
fileOut.close();<br />
fis.close();</em></p>
<p><em>}</em></p>
<p><em>}catch(Exception e)<br />
{<br />
System.out.println(&#8220;Exception Due to&#8221;+e);<br />
e.printStackTrace();<br />
}<br />
}<br />
}</em></p>
<p>Here you are specifying the path that the file is to save in your local disk i.e</p>
<p>your file will be saving in the <strong>test foldar </strong>with the name of the file as orginal name of the file you are invoking.</p>
<p>Here is Deployment discriptor to pass the request from the html to Servlet program. save these with the name <strong>web.xml </strong>in the <strong>WEB-INF</strong> directory</p>
<p><em> &lt;servlet&gt;<br />
&lt;servlet-name&gt;UploadFile&lt;/servlet-name&gt;<br />
&lt;servlet-class&gt;com.myapp.struts.UploadFile&lt;/servlet-class&gt;<br />
&lt;/servlet&gt;</em></p>
<p><em> &lt;servlet-mapping&gt;<br />
&lt;servlet-name&gt;UploadFile&lt;/servlet-name&gt;<br />
&lt;url-pattern&gt;/servlet/UploadFile&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;</em></p>
<p><em>Note: If  You want the code in the jsp follow the link <a class="wp-caption" title="Jsp File Uploading" href="http://www.bestjavainterviewquestions.com/jsp-example-file-uploading/" target="_blank">JSP File Uploading</a></em><strong><em><br />
</em></strong></p>
<p><em><br />
</em></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/explain-java-takes-care-of-registering-the-driver/" title="Explain Java takes care of registering the driver"><img src="Array" alt="Explain Java takes care of registering the driver" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/adding-a-database-driver-in-hibernate/" title="Adding a DataBase Driver in Hibernate"><img src="Array" alt="Adding a DataBase Driver in Hibernate" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/define-session-migration/" title="Define Session Migration"><img src="Array" alt="Define Session Migration" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/define-local-interfaces/" title="Define Local Interfaces"><img src="Array" alt="Define Local Interfaces" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/overview-of-servlets/" title="OVERVIEW OF SERVLETS"><img src="Array" alt="OVERVIEW OF SERVLETS" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/file-uploading-using-servlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Explain Interface?Define</title>
		<link>http://www.bestjavainterviewquestions.com/explain-interfacedefine/</link>
		<comments>http://www.bestjavainterviewquestions.com/explain-interfacedefine/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 18:03:18 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Explain Interface]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=488</guid>
		<description><![CDATA[Interface: In Java language, an interface is like a stripped-down class; it specifies a set of methods that an instance must handle, but it omits inheritance relations and method implementations. Object-oriented programming is sometimes modeled as communication between objects like one object talks to, or sends a message to, another object ( by invoking a [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: medium;"><strong>Interface:<br />
</strong></span><br />
In Java language, an interface is like a stripped-down class; it specifies a set of methods that an instance must handle, but it omits inheritance relations and method implementations.</p>
<p>Object-oriented programming is sometimes modeled as communication between objects like one object talks to, or sends a message to, another object ( by invoking a method on it ). An object needs to know the order to talk with another object ; a set of abstract methods i.e., method minus implementation information. Put the another way, an interface specifies how we can talk to an object,but says nothing about what kind of object will handle our messages. It is job of one or more class instances to provide the substance behind an interface&#8217;s promise.</p>
<p>The general form of an interface definition is :</p>
<p><em><strong>interface</strong> name</em></p>
<p><em>{<br />
</em></p>
<p><em>variable declarations;</em></p>
<p><em>method declarations;</em></p>
<p><em>}</em></p>
<p>Here, <strong>interface</strong> is the keyword and <strong>name</strong> is any valid Java variable ( just like class names ).</p>
<p>Variables are declared as follows:</p>
<p><em><strong>public static final</strong> type variableName = value;</em></p>
<p>Methods declaration will contain only a list of methods without any body statements.</p>
<p><strong>Example:</strong></p>
<p>return-type methodName(parameter_list);</p>
<p>The following is an example of an interface definition that contains two variables and one method :</p>
<p><em><strong>interface</strong> Item</em></p>
<p><em> {</em></p>
<p><em>public static final int prodCode = 1001;</em></p>
<p><em>public static final String prodName = &#8220;Fan&#8221;;</em></p>
<p><em>public abstract void display();</em></p>
<p><em>}</em></p>
<p>Here the code for the method is not included in the interface and the method declaration simply ends with a semicolon. The class that implements this interface must define the code for the method.</p>
<p><strong>NOTE:</strong></p>
<p><strong>&#8211;&gt; </strong>All the Interface methods are Abstract only by Default.</p>
<p><strong>&#8211;&gt; </strong>we can&#8217;t create an object to the <em><strong>interface. </strong></em>But we can create a reference variable to <em>interface.</em></p>
<p><strong>&#8211;&gt; </strong>Once the interface is provided we can create &#8216;n&#8217; number of implementation classes</p>
<p><strong>&#8211;&gt; </strong>we can create object to implementation class by using this we can allow all features of the super class.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/configuring-the-log4j-for-hibernate/" title="Configuring the Log4J for Hibernate"><img src="Array" alt="Configuring the Log4J for Hibernate" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/the-url-class/" title="The URL Class"><img src="Array" alt="The URL Class" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/define-servletinputstream/" title="Define ServletInputStream"><img src="Array" alt="Define ServletInputStream" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/servlets-and-jsps/" title="Servlets and Jsp&#8217;s"><img src="Array" alt="Servlets and Jsp&#8217;s" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/define-session-migration/" title="Define Session Migration"><img src="Array" alt="Define Session Migration" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/explain-interfacedefine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL Connection Class</title>
		<link>http://www.bestjavainterviewquestions.com/url-connection-class/</link>
		<comments>http://www.bestjavainterviewquestions.com/url-connection-class/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 17:58:37 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[URL Connection classes]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=476</guid>
		<description><![CDATA[URL Connection Class The URLConnection class provides a more granular interface to a URL than the getContent method in the URL class. This class provides method for examining HTTP headers, getting information about the URL&#8217;s content, and getting input and output stream to the URL. Some of the methods used in these URL Connection Class [...]]]></description>
			<content:encoded><![CDATA[<p><strong>URL Connection Class</strong></p>
<p>The URLConnection class provides a more granular interface to a URL than the getContent method in the URL class. This class provides method for examining HTTP headers, getting information about the URL&#8217;s content, and getting input and output stream to the URL.</p>
<p><strong><em>Some of the methods used in these URL Connection Class are as follows</em></strong></p>
<p><em>public abstract class java.net.URLConnection extends java.lang.Object {<br />
protected java.net.URL url;<br />
protected boolean doInput;<br />
protected boolean doOutput;<br />
protected boolean allowUserInteraction;<br />
protected boolean useCaches;<br />
protected long ifModifiedSinces;<br />
protected boolean connected;<br />
static java.net.ContentHandlerFactory factory;<br />
public static synchronized java.net.FileNameMap getFileNameMap();<br />
public static void setFileNameMap(java.net.FileNameMap);<br />
public abstract void connect() throws java.io.IOException;<br />
protected java.net.URLConnection(java.net.URL);<br />
public java.net.URL getURL();<br />
public int getContentLength();<br />
public java.lang.String getContentType();<br />
public java.lang.String getContentEncoding();<br />
public long getExpiration();<br />
public long getDate();<br />
public long getLastModified();<br />
public java.lang.String getHeaderField(java.lang.String);<br />
public java.util.Map getHeaderFields();<br />
public int getHeaderFiledInt(java.lang.String,int);<br />
public long getHeaderFieldDate(java.lang.String,long);<br />
public java.lang.String getHeaaderFieldKey(int);</em></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/what-is-thread-how-to-use-threads/" title="What is Thread, How to Use Threads?"><img src="Array" alt="What is Thread, How to Use Threads?" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/services-provided-by-ejb-container/" title="Services Provided by EJB Container"><img src="Array" alt="Services Provided by EJB Container" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions"><img src="Array" alt="Core Java Interview Questions" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/goto-statement-in-java/" title="GoTo statement in Java"><img src="Array" alt="GoTo statement in Java" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/applet-interview-questions/" title="Applet Interview Questions"><img src="Array" alt="Applet Interview Questions" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/url-connection-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Collection FrameWork</title>
		<link>http://www.bestjavainterviewquestions.com/collection-framework/</link>
		<comments>http://www.bestjavainterviewquestions.com/collection-framework/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 01:40:24 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Collection FrameWork]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[define collection framework]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=429</guid>
		<description><![CDATA[Q) What is Collection FrameWork? Res) A Collection FrameWork represents a class library to handle groups of objects &#8211;&#62; Collection framework is implemented in Java.Util.Package. &#8211;&#62; Collection does&#8217;t store copy of all the object, but it stores references of all objects. &#8211;&#62; Collection classes will act upon only referenced datatypes they do not act upon [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) What is Collection FrameWork?</strong></p>
<p><strong>Res)</strong> A Collection FrameWork represents a class library to handle groups of objects</p>
<p><strong>&#8211;&gt; </strong>Collection framework is implemented in <strong>Java.Util.Package</strong>.</p>
<p><strong>&#8211;&gt; </strong>Collection does&#8217;t store copy of all the object, but it stores references of all objects.</p>
<p><strong>&#8211;&gt; </strong>Collection classes will act upon only referenced datatypes they do not act upon primitive datatypes.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/difference-between-string-and-stringbuffer/" title="Difference between String and StringBuffer"><img src="Array" alt="Difference between String and StringBuffer" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/using-serialization/" title="Using Serialization "><img src="Array" alt="Using Serialization " /></a></li><li><a href="http://www.bestjavainterviewquestions.com/what-is-default-package-in-java/" title="What is Default Package in Java"><img src="Array" alt="What is Default Package in Java" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/servlet-session-examples/" title="Servlets Session Examples"><img src="Array" alt="Servlets Session Examples" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/explain-session-destroy-in-servlets/" title="Explain session destroy in Servlets"><img src="Array" alt="Explain session destroy in Servlets" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/collection-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Difference between session.save() and session.saveOrUpdate()</title>
		<link>http://www.bestjavainterviewquestions.com/difference-between-sessionsave-and-sessionsaveorupdate/</link>
		<comments>http://www.bestjavainterviewquestions.com/difference-between-sessionsave-and-sessionsaveorupdate/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 17:34:30 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/difference-between-sessionsave-and-sessionsaveorupdate/</guid>
		<description><![CDATA[Q) Difference between session.save() and session.saveOrUpdate()? A) session.save() &#8211; Insert data into the table session.saveOrUpdate()- Insert data if primary key not exist otherwise update Random Posts]]></description>
			<content:encoded><![CDATA[<p><strong>Q) Difference between session.save() and session.saveOrUpdate()?<br />
A)</strong><br />
session.save() &#8211; Insert data into the table<br />
session.saveOrUpdate()- Insert data if primary key not exist otherwise update</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/collection-framework/" title="Collection FrameWork"><img src="Array" alt="Collection FrameWork" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/java-jdbc-questions/" title="Java-Jdbc Questions"><img src="Array" alt="Java-Jdbc Questions" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/servlet-session-examples/" title="Servlets Session Examples"><img src="Array" alt="Servlets Session Examples" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/the-url-class/" title="The URL Class"><img src="Array" alt="The URL Class" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/hibernate-interview-questions-2/" title="Hibernate Interview Questions"><img src="Array" alt="Hibernate Interview Questions" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/difference-between-sessionsave-and-sessionsaveorupdate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
