<?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; Java Interview Questions</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/java-interview-questions/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, 03 Feb 2012 10:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Define Hashtable,HashMap and HashSet</title>
		<link>http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/</link>
		<comments>http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 11:25:49 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Java Interview Questions]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[HashSet]]></category>
		<category><![CDATA[HashTable]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[set]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=627</guid>
		<description><![CDATA[Hashtable Hashtable is basically a datastructure to retain values of key-value pair. It didn&#8217;t allow null for both key and value. You will get NullPointerException if you add null value. It is synchronized. So it come with its cost. Only one thread can access in one time Hashtable&#60;Interger,String&#62;; cityTable=new Hashtable&#60;Interger,String&#62;(); cityTable.put(1,&#8221;Lahore&#8221;); cityTable.put(2,&#8221;Karachi&#8221;); cityTable.put(3,null); // NullPointerException [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Hashtable</strong></p>
<p>Hashtable is basically a datastructure to retain values of key-value pair.</p>
<ul>
<li>It didn&#8217;t allow null for both key and value. You will get NullPointerException if you add null value.</li>
<li>It is synchronized. So it come with its cost. Only one thread can access in one time</li>
</ul>
<ol>
<li><em>Hashtable&lt;Interger,String&gt;; cityTable=new Hashtable&lt;Interger,String&gt;();</em></li>
<li><em>cityTable.put(1,&#8221;Lahore&#8221;);</em></li>
<li><em>cityTable.put(2,&#8221;Karachi&#8221;);</em></li>
<li><em>cityTable.put(3,null); // NullPointerException at runtime</em></li>
<li><em>System.out.println(cityTable.get(1));</em></li>
<li><em>System.out.println(cityTable.get(2));</em></li>
<li><em>System.out.println(cityTable.get(3));</em></li>
</ol>
<p><strong>HashMap</strong></p>
<p>Like Hashtable it also accepts key value pair.</p>
<ul>
<li>It allows null for both key and value</li>
<li>It is un-synchronized. So come up with better performance</li>
</ul>
<ol>
<li><em>HashMap&lt;Interger,String&gt;; prodcutTable=new HashMap&lt;Interger,String&gt;();</em></li>
<li><em>prodcutTable</em><em>.put(1,&#8221;Keys&#8221;);</em></li>
<li><em>prodcutTable</em><em>.put(2,null);</em></li>
</ol>
<p><strong>HashSet</strong></p>
<p>HashSet does not allow duplicate values. It provides add method rather put method. You also use its contain method to check whether the object is already available in HashSet. HashSet can be used  where you want to maintain a unique list.</p>
<ol>
<li><em>HashSet&lt;String&gt;; stateSet=new HashSet&lt;String&gt;();</em></li>
<li><em>stateSet</em><em>.add(&#8220;CA&#8221;);</em></li>
<li><em>stateSet</em><em>.</em><em>add</em><em>(&#8220;WI&#8221;);</em></li>
<li><em>stateSet</em><em>.</em><em>add</em><em>(&#8220;NY&#8221;);</em></li>
<li></li>
<li>if(stateSet.contains(&#8220;PB&#8221;)) /* if CA,it will not add but shows following message */</li>
<li><em>System.out.println(Already found);</em></li>
<li><em>else<br />
</em></li>
<li><em>stateSet.add(&#8220;PB&#8221;);</em></li>
</ol>
<p>Use hashSet if you just want to have a set of object, HashMap if you want some mappings(key-value pair), Use Hashtable in multi threaded enviroment as its synchronized (alternatively you can use a synchronizedMap as well)</p>
<p>For More Information on Collections Visit <a href="http://www.bestjavainterviewquestions.com/java-util-package-2/">UTIL PACKAGE</a></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-util-package-2/" title="JAVA UTIL PACKAGE">JAVA UTIL PACKAGE</a> (0)</li><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions">Core Java Interview Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/define-hashtablehashmap-and-hashset/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exception Handling and their uses</title>
		<link>http://www.bestjavainterviewquestions.com/exception-handling-and-their-uses/</link>
		<comments>http://www.bestjavainterviewquestions.com/exception-handling-and-their-uses/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 16:31:51 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Java Interview Questions]]></category>
		<category><![CDATA[catch]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[exception handling]]></category>
		<category><![CDATA[finally]]></category>
		<category><![CDATA[throw]]></category>
		<category><![CDATA[throws]]></category>
		<category><![CDATA[try]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=587</guid>
		<description><![CDATA[Q)  What is the difference between ‘throw’ and ‘throws’ ?And it’s application? Rep) Exceptions that are thrown by java runtime systems can be handled by Try and catch blocks. With throw exception we can handle the exceptions thrown by the program itself. If a method is capable of causing an exception that it does not [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q)  What is the difference between ‘throw’ and ‘throws’ ?And it’s application?<br />
</strong></p>
<p><strong>Rep) </strong> Exceptions that are thrown by java runtime systems can be handled by Try and catch blocks. With throw exception we can handle the exceptions thrown by the program itself. If a method is capable of causing an exception that it does not<br />
handle, it must specify this behavior so the callers of the method can guard<br />
against that exception.</p>
<p><strong>Q)   What is the difference between ‘Exception’ and ‘error’ in java?</strong></p>
<p><strong>Rep) </strong> Exception and Error are the subclasses of the Throwable class. Exception class is used for exceptional conditions that user program should catch. With exception class we can subclass to create our own custom exception.<br />
Error defines exceptions that are not excepted to be caught by you program. Example is Stack Overflow.</p>
<p><strong>Q)  What is ‘Resource leak’?<br />
</strong></p>
<p><strong>Rep) </strong> Freeing up other resources that might have been allocated at the beginning of a method.</p>
<p><strong>Q)  What is the ‘finally’ block?</strong></p>
<p><strong>Rep) </strong> Finally block will execute whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally clause is also execute.</p>
<p><strong>Q)  Can we have catch block with out try block? If so when?<br />
</strong></p>
<p><strong>Rep) </strong> No. Try/Catch or Try/finally form a unit.</p>
<p><strong>Q)  What will happen to the Exception object after exception handling?<br />
</strong></p>
<p><strong>Rep) </strong> It will go for Garbage Collector. And frees the memory.</p>
<p><strong>Q)  How many Exceptions we can define in ‘throws’ clause?<br />
</strong></p>
<p><strong>Rep) </strong> We can define multiple exceptions in throws clause.<br />
Signature is.. : type method-name (parameter-list) throws exception-list</p>
<p><strong>Q)  The finally block is executed when an exception is thrown, even if no catch matches it.<br />
True/False<br />
</strong></p>
<p><strong>Rep) </strong> True</p>
<p><strong>Q)   The subclass exception should precede the base class exception when used within the catch clause.<br />
True/False<br />
</strong></p>
<p><strong>Rep) </strong>True</p>
<p><strong>Q)   Exceptions can be caught or rethrown to a calling method.<br />
True/False</strong></p>
<p><strong>Rep) </strong>True</p>
<p><strong>Q)  The statements following the throw keyword in a program are not executed.<br />
True/False</strong></p>
<p><strong>Rep) </strong> True</p>
<p><strong>Q)  The toString ( ) method in the user-defined exception class is overridden.<br />
True/False</strong></p>
<p><strong>Rep) </strong>True</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-util-package-2/" title="JAVA UTIL PACKAGE">JAVA UTIL PACKAGE</a> (0)</li><li>June 30, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-exception-handling-questions/" title="Java Exception Handling Questions">Java Exception Handling Questions</a> (0)</li><li>October 27, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-connection-pooling/" title="Define Connection Pooling">Define Connection Pooling</a> (0)</li><li>July 21, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-swings-interview-questions/" title="Java Swings Interview Questions">Java Swings Interview Questions</a> (0)</li><li>September 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/using-mysql-database-in-hibernate/" title="Using MySql DataBase in Hibernate">Using MySql DataBase in Hibernate</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/exception-handling-and-their-uses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to get a Leap Year</title>
		<link>http://www.bestjavainterviewquestions.com/how-to-get-a-leap-year/</link>
		<comments>http://www.bestjavainterviewquestions.com/how-to-get-a-leap-year/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 14:31:38 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Java Interview Questions]]></category>
		<category><![CDATA[code for leap year]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java examples]]></category>
		<category><![CDATA[java leapyear code]]></category>
		<category><![CDATA[javacode]]></category>
		<category><![CDATA[leap year java]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=544</guid>
		<description><![CDATA[import java.util.Calendar.*; import java.lang.*;  //its&#8217; a default package which will import class LeapYear { public static void main(String args[])throws Exception { Calendar cal=Calendar.getInstance(); int year=cal.get(Calendar.YEAR); if(year % 4 == 0 &#38;&#38; (year % 100 != 0 &#124;&#124; year % 400 == 0)) {   System.out.println(&#8220;Leap Year&#8221;);          }else  { System.out.println(&#8220;Not a Leap Year);      } } }  // [...]]]></description>
			<content:encoded><![CDATA[<p>import java.util.Calendar.*;</p>
<p>import java.lang.*;  //its&#8217; a default package which will import</p>
<p>class <strong>LeapYear </strong>{</p>
<p>public static void main(String args[])throws Exception {</p>
<p>Calendar cal=Calendar.getInstance();</p>
<p>int year=cal.get(Calendar.YEAR);</p>
<p>if(year % 4 == 0 &amp;&amp; (year % 100 != 0 || year % 400 == 0))</p>
<p>{   System.out.println(&#8220;Leap Year&#8221;);          }else  {</p>
<p>System.out.println(&#8220;Not a Leap Year);      }</p>
<p>}</p>
<p>}  // The Meaning of above is every 4 year&#8217;s the LeapYear comes and when The Centuries comes into pictures it will divided by the 400 so that the remainder should be zera is the Leap year</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>July 30, 2010 -- <a href="http://www.bestjavainterviewquestions.com/stored-procedures-for-beginners/" title="Stored Procedures for Beginners">Stored Procedures for Beginners</a> (0)</li><li>April 7, 2009 -- <a href="http://www.bestjavainterviewquestions.com/overview-of-servlets/" title="OVERVIEW OF SERVLETS">OVERVIEW OF SERVLETS</a> (0)</li><li>March 29, 2009 -- <a href="http://www.bestjavainterviewquestions.com/j2ee-interview-questions/" title="J2EE Interview Questions">J2EE Interview Questions</a> (0)</li><li>March 25, 2009 -- <a href="http://www.bestjavainterviewquestions.com/creating-a-stateful-session-bean/" title="Creating a Stateful session Bean">Creating a Stateful session Bean</a> (1)</li><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/how-to-get-a-leap-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Define Jar,War,Ear file</title>
		<link>http://www.bestjavainterviewquestions.com/define-jarwarear-file/</link>
		<comments>http://www.bestjavainterviewquestions.com/define-jarwarear-file/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 19:04:02 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Define creating and extracting of jar]]></category>
		<category><![CDATA[ear]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[war]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=578</guid>
		<description><![CDATA[Q) What is EAR file Rep) Enterprise Archive file. A JAR archive that contains a J2EE application. Q) What is JAR file Rep) Java Archive file it contains a J2EE application. You can create a JAR file using the command jar cf XYZ.jar *.class *.gif if will compress all the .class files and the related [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) What is EAR file</strong></p>
<p><strong>Rep) </strong>Enterprise Archive file. A JAR archive that contains a<br />
J2EE application.</p>
<p><strong>Q) What is JAR file</strong></p>
<p><strong>Rep)</strong> Java Archive file it contains a J2EE application.</p>
<p>You can create a JAR file using the command</p>
<p><em>jar cf XYZ.jar *.class *.gif</em></p>
<p>if will compress all the .class files and the related gif files to the one file called jar</p>
<p>You can extract the JAR file using the command</p>
<p><em>jar xf XYZ.jar</em></p>
<p>Updating the existing JAR file</p>
<p><em>jar -uf XYZ.jar file1.class</em></p>
<p><strong>Q) What is WAR file</strong></p>
<p><strong>Rep)</strong> Enterprise Archive file. A JAR archive that contains a<br />
J2EE application.</p>
<p>You can create a <strong>WAR </strong>file using the command</p>
<p><em>jar -cfv XYZ.war</em></p>
<p>You can extract a <strong>WAR </strong>file using the command</p>
<p><em>jar -xfv XYZ.war</em></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-earjar-and-war/" title="Define Ear,jar and war">Define Ear,jar and war</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/define-jarwarear-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploading Excel File  Using Jsp</title>
		<link>http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/</link>
		<comments>http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 16:27:39 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Upload Excel sheet using jsp/java]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[file upload using java]]></category>
		<category><![CDATA[file upload using jsp]]></category>
		<category><![CDATA[file upload using jsp example]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[jsp example]]></category>
		<category><![CDATA[jsp excep file upload example]]></category>
		<category><![CDATA[jsp upload example]]></category>
		<category><![CDATA[uploading the excelfile]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=541</guid>
		<description><![CDATA[There are two choice for reading and writing the Excel file in your application. 1.By Using the JExcelapi 2.By Jakarta&#8217;s Poi.jar which uses the HSSFSheet read and write. &#8211;&#62; Using the JExcelapi which  is  not suitable for the important data. It fails to read several files and  in most occasions it also fails to create [...]]]></description>
			<content:encoded><![CDATA[<p>There are two choice for reading and writing the Excel file in your application.</p>
<p>1.By Using the JExcelapi</p>
<p>2.By Jakarta&#8217;s Poi.jar which uses the HSSFSheet read and write.</p>
<p>&#8211;&gt; Using the JExcelapi which  is  not suitable for the important data. It fails to read several files and  in most occasions it also fails to create cells. In short JExcelAPI isn&#8217;t suitable for enterprise use.</p>
<p>&#8211;&gt;Where as the POI.jar is a Jakarta  Project&#8217;s which was developed  by pure Java implementation of the Excel file format. It is a mature product and was able to correctly and effortlessly read excel data generated from various sources, including non-MS Excel products like Open Office, and for various versions of Excel. so for this reasons it is Highly recommended.</p>
<p>Before Using this Code you have to download the <strong><em>poi.jar</em></strong> file  and place it in the <em>lib</em> folder of your application (or) place in the jar folder and give the path in the <em>environment variables in the My Computers</em>, and then import the <em>HSSF</em> files and then follow the code</p>
<p><em>&lt;%@ page import = &#8220;java.io.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.sql.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;javax.servlet.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;javax.servlet.http.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.util.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.awt.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.io.File&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.io.IOException&#8221; %&gt;<br />
&lt;%@ page import = &#8220;javax.swing.filechooser.FileSystemView&#8221; %&gt;</em></p>
<p>&lt;%@ page import=&#8221;org.apache.poi.hssf.usermodel.HSSFSheet&#8221;%&gt;<br />
&lt;%@ page import=&#8221;org.apache.poi.hssf.usermodel.HSSFWorkbook&#8221;%&gt;<br />
&lt;%@ page import=&#8221;org.apache.poi.hssf.usermodel.HSSFRow&#8221;%&gt;<br />
&lt;%@ page import=&#8221;org.apache.poi.hssf.usermodel.HSSFCell&#8221;%&gt;</p>
<p>&lt;%<br />
//Here Datedas is the value of the length which is retrived from the database in my application</p>
<p><em><br />
String fname1=&#8221;File&#8221;-&#8221;+Datedas+&#8221;.xls&#8221;; </em></p>
<p><em>//Giving name to the file<br />
</em></p>
<p><em> //creating a file object</em></p>
<p><em> File fname=new File(fname1);</em></p>
<p><em>//Creating an object to the HSSF Class<br />
</em></p>
<p><em> HSSFWorkbook hwb = new HSSFWorkbook();<br />
</em></p>
<p>//Giving the name to the Excel file which will be created by this HSSFsheet</p>
<p><em>HSSFSheet sheet = hwb.createSheet(&#8220;stock sheet&#8221;);<br />
</em></p>
<p><em>//Creating the row for your data</em></p>
<p><em>HSSFRow pw = sheet.createRow((short)2);<br />
</em></p>
<p><em>//Mention the Heading of your Excel sheet<br />
</em></p>
<p><em> pw.createCell((short) 0).setCellValue(&#8220;S.No&#8221;);<br />
pw.createCell((short) 1).setCellValue(&#8220;Heading1&#8243;);<br />
pw.createCell((short) 2).setCellValue(&#8220;</em><em>Heading2</em><em>&#8220;);<br />
pw.createCell((short) 3).setCellValue(&#8220;</em><em>Heading3</em><em>&#8220;);<br />
pw.createCell((short) 4).setCellValue(&#8220;</em><em>Heading4</em><em>&#8220;);<br />
pw.createCell((short) 5).setCellValue(&#8220;</em><em>Heading5</em><em>&#8220;);<br />
pw.createCell((short) 6).setCellValue(&#8220;</em><em>Heading6</em><em>&#8220;);<br />
pw.createCell((short) 7).setCellValue(&#8220;</em><em>Heading7</em><em>&#8220;);<br />
pw.createCell((short) 8).setCellValue(&#8220;</em><em>Heading8</em><em>&#8220;);<br />
pw.createCell((short) 9).setCellValue(&#8220;</em><em>Heading9</em><em>&#8220;);<br />
pw.createCell((short) 10).setCellValue(&#8220;</em><em>Heading10</em><em>&#8220;);<br />
pw.createCell((short) 11).setCellValue(&#8220;</em><em>Heading1</em><em>1&#8243;);</em></p>
<p>//String stored1=&#8221;",stored2=&#8221;",stored3=&#8221;",stored4=&#8221;",stored5=&#8221;",stored6=&#8221;",stored7=&#8221;",stored9=&#8221;";<br />
//float stored8=0.0f,stored10=0.0f,stored12=0.0f;<br />
int comprk=1;</p>
<p>int index=3;<br />
//int compno=0;<br />
int sno=0;<br />
while(rs.next())<br />
{</p>
<p>compno=1;<br />
sno++;</p>
<p>System.out.println(&#8220;Testing in the loop  &#8220;+compno);</p>
<p><em>//Creating the Excel Sheet Rows </em></p>
<p><em>HSSFRow row = sheet.createRow((short)index);</em></p>
<p><em> row.createCell((short) 0).setCellValue(sno);</em></p>
<p><em>row.createCell((short)                                                    .setCellValue(Integer.parseInt(rs.getString(1)));<br />
row.createCell((short) 2).setCellValue(rs.getString(2));<br />
row.createCell((short) 3).setCellValue(rs.getString(3));<br />
row.createCell((short) 4).setCellValue(rs.getString(4));<br />
row.createCell((short) 5).setCellValue(rs.getString(5));<br />
row.createCell((short) 6).setCellValue(rs.getString(6));<br />
row.createCell((short) 7).setCellValue(rs.getString(7));<br />
row.createCell((short) 8).setCellValue(rs.getFloat(8));<br />
row.createCell((short) 9).setCellValue(rs.getString(9));<br />
row.createCell((short) 10).setCellValue(rs.getFloat(10));<br />
row.createCell((short) 11).setCellValue(rs.getFloat(13));<br />
index++;<br />
}</em></p>
<p>FileOutputStream fileOut = new FileOutputStream(fname);</p>
<p>hwb.write(fileOut);<br />
fileOut.flush();<br />
fileOut.close();<br />
out.println(&#8220;&lt;b&gt;Your excel file has been Successfully generated&lt;/b&gt;&#8221;);</p>
<p>%&gt;</p>
<p>&nbsp;</p>
<h3><span style="color: #ff0000;">Find More file upload examples click here</span> <a title="uploading image into DB" href="http://www.bestjavainterviewquestions.com/uploading-file-name-of-image-to-database/" target="_blank">1</a> , <a title="File Upload using servlet" href="http://www.bestjavainterviewquestions.com/file-uploading-using-servlet/" target="_blank">2</a> and <a title="File Upload using JSP" href="http://www.bestjavainterviewquestions.com/jsp-example-file-uploading/" target="_blank">3</a></h3>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>January 26, 2009 -- <a href="http://www.bestjavainterviewquestions.com/jsp-example-file-uploading/" title="Jsp Example: File Uploading">Jsp Example: File Uploading</a> (0)</li><li>April 7, 2009 -- <a href="http://www.bestjavainterviewquestions.com/j2ee-interview-questions-3/" title="J2EE Interview Questions">J2EE Interview Questions</a> (0)</li><li>January 26, 2009 -- <a href="http://www.bestjavainterviewquestions.com/file-uploading-using-servlet/" title="File Uploading Using Servlet">File Uploading Using Servlet</a> (0)</li><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/core-java-interview-questions/" title="Core Java Interview Questions">Core Java Interview Questions</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploading file name or image to DataBase</title>
		<link>http://www.bestjavainterviewquestions.com/uploading-file-name-of-image-to-database/</link>
		<comments>http://www.bestjavainterviewquestions.com/uploading-file-name-of-image-to-database/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 17:05:53 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[FileUpload to DataBase]]></category>
		<category><![CDATA[file upload to DB using servlet]]></category>
		<category><![CDATA[file upload to DB using servlet example]]></category>
		<category><![CDATA[file upload using servlet]]></category>
		<category><![CDATA[FileUpload]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[servlet file upload]]></category>
		<category><![CDATA[servlet file upload example]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=535</guid>
		<description><![CDATA[This is an example of the file Uploading in Java using Servlets . This file uploading concept Works with the Java as follows Here is the Code of the file Uploading using Servlets in JAVA and saving the image and filename of image in the database Name the HTML page as file.html &#60;!DOCTYPE HTML PUBLIC [...]]]></description>
			<content:encoded><![CDATA[<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>Here is the Code of the file Uploading using Servlets in JAVA and saving the image and filename of image in the database</p>
<p><strong>Name the HTML page as file.html</strong></p>
<p><em>&lt;!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”&gt;<br />
&lt;html&gt;<br />
&lt;form method=”post” action=”servlet/UploadFile” enctype=”multipart/form-data”&gt;<br />
Name<br />
&lt;input type=”text” name=”uname”/&gt;<br />
File<br />
&lt;input type=”file” name=”upfile”/&gt;<br />
&lt;input type=”submit”/&gt;<br />
&lt;/form&gt;<br />
&lt;/html&gt;</em></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.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>Class.forName(&#8220;com.mysql.jdbc.Driver&#8221;);<br />
Connection conn = DriverManager.getConnection(&#8220;jdbc:mysql://localhost/test?user=root&amp;password=test&#8221;);<br />
PrintWriter out=res.getWriter();</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<br />
String contentType = req.getContentType();<br />
int flag=0;<br />
FileInputStream fis=null;<br />
FileOutputStream fileOut=null;<br />
//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<br />
if ((contentType != null) &amp;&amp; (contentType.indexOf(&#8220;multipart/form-data&#8221;) &gt;= 0))<br />
{<br />
DataInputStream in = new DataInputStream(req.getInputStream());<br />
//we are taking the length of Content type data<br />
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<br />
while (totalBytesRead &lt; formDataLength) {<br />
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);<br />
totalBytesRead += byteRead;<br />
}</em></p>
<p><em>String file = new String(dataBytes);<br />
//for saving the file name<br />
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;");<br />
String extension_saveName=saveFile.substring(extension_save);</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<br />
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>int file_No=22;<br />
String pathname_dir=&#8221;D:\\rk\\&#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 />
out.println(&#8220;&lt;h1&gt; your files are saved&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;&#8221;);<br />
out.close();</em></p>
<p><em>File database_filename=new File(pathname_dir);<br />
fis=new FileInputStream(database_filename);<br />
PreparedStatement ps = conn.prepareStatement(&#8220;insert into test (fname) values (?)&#8221;);<br />
ps.setString(1,database_filename.getName());<br />
ps.executeUpdate();<br />
ps.close();<br />
flag=1;</em></p>
<p><em>}</em></p>
<p><em>if(flag==1)<br />
{<br />
fileOut.close();<br />
fis.close();<br />
}<br />
}catch(Exception e)<br />
{<br />
System.out.println(&#8220;Exception Due to&#8221;+e);<br />
e.printStackTrace();<br />
}<br />
}<br />
}</em></p>
<p>The above code is used to save the path in the DataBase where(in Which directory/folder) the file is saved .</p>
<p>If you want to save the image into data base the just modify the part of the above code like the below specified.</p>
<p>Here note that the image column data type should be take as blob</p>
<p><em> File database_filename=new File(pathname_dir);<br />
fis=new FileInputStream(database_filename);<br />
PreparedStatement ps = conn.prepareStatement(&#8220;insert into test (fname,image) values (?,?)&#8221;);<br />
ps.setString(1,database_filename.getName());<br />
ps.setBinaryStream(2,fis,database_filename.length())</em></p>
<p><em>//ps.setBinaryStream(int parameterIndex,InputStream x,int length)</em></p>
<p><em>to know more about BinaryStream and the methods of sql package <a class="wp-caption" title="methods of sql Interface" href="http://computerpreferedcourses.blogspot.com/2009/01/javasql-interface-preparedstatement.html" target="_blank">clickhere</a><br />
ps.executeUpdate();<br />
ps.close();</em></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>&nbsp;</p>
<h3><span style="color: #ff0000;">Find More file upload examples click here</span> <a title="Upload Excel file using jsp" href="http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/" target="_blank">1</a> , <a title="File Upload using servlet" href="http://www.bestjavainterviewquestions.com/file-uploading-using-servlet/" target="_blank">2</a> and <a title="File Upload using JSP" href="http://www.bestjavainterviewquestions.com/jsp-example-file-uploading/">3</a></h3>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>January 26, 2009 -- <a href="http://www.bestjavainterviewquestions.com/file-uploading-using-servlet/" title="File Uploading Using Servlet">File Uploading Using Servlet</a> (0)</li><li>April 7, 2009 -- <a href="http://www.bestjavainterviewquestions.com/j2ee-interview-questions-3/" title="J2EE Interview Questions">J2EE Interview Questions</a> (0)</li><li>April 7, 2009 -- <a href="http://www.bestjavainterviewquestions.com/overview-of-servlets/" title="OVERVIEW OF SERVLETS">OVERVIEW OF SERVLETS</a> (0)</li><li>April 4, 2009 -- <a href="http://www.bestjavainterviewquestions.com/java-interview-questions/" title="Java Interview Questions">Java Interview Questions</a> (0)</li><li>April 4, 2009 -- <a href="http://www.bestjavainterviewquestions.com/j2ee-interview-questions-2/" title="J2EE Interview Questions">J2EE Interview Questions</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/uploading-file-name-of-image-to-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Text file using Java</title>
		<link>http://www.bestjavainterviewquestions.com/522/</link>
		<comments>http://www.bestjavainterviewquestions.com/522/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 17:06:22 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Java Saving a File]]></category>
		<category><![CDATA[saving a file using java]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=522</guid>
		<description><![CDATA[//Write a java program for creating a text file import java.io.*; import java.io.OutputStream; class FileAccess { public static void main(String args[])throws IOException { //Attach keyboard to DataInputStream DataInputStream dis=new DataInputStream(System.in); //Attach myfile to fileoutputstream FileOutputStream fos=new FileOutputStream(&#8220;xxxx.txt&#8221;); //read data from datainputstream and write it into fileoutputstream ObjectOutputStream p=new ObjectOutputStream(fos); char ch; System.out.println(&#8220;Enter date(@ to end [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>//Write a java program for creating a text file </em></strong></p>
<p><em>import java.io.*;<br />
import java.io.OutputStream;</em></p>
<p><em>class FileAccess<br />
{<br />
public static void main(String args[])throws IOException<br />
{</em></p>
<p><em>//Attach keyboard to DataInputStream</em></p>
<p><em>DataInputStream dis=new DataInputStream(System.in);</em></p>
<p><em>//Attach myfile to fileoutputstream</em></p>
<p><em>FileOutputStream fos=new FileOutputStream(&#8220;xxxx.txt&#8221;);</em></p>
<p><em>//read data from datainputstream and write it into fileoutputstream</em></p>
<p><em>ObjectOutputStream p=new ObjectOutputStream(fos);<br />
char ch;<br />
System.out.println(&#8220;Enter date(@ to end the program);&#8221;);<br />
while((ch=(char)dis.read())!=&#8217;@')<br />
fos.write(ch);<br />
p.writeInt(12345);<br />
p.writeObject(&#8220;Today&#8221;);<br />
p.putFields();</em></p>
<p><em>//p.writeStreamHeader();</em></p>
<p><em>p.writeFields();</em></p>
<p><em>p.flush();</em></p>
<p><em>//closefikle</em></p>
<p><em>fos.close();<br />
}<br />
}</em></p>
<p><strong>Procedure:</strong></p>
<p>First compile the program and run the program then given the inputs as a string then exit that and u can fine the file in the destination u had specified</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>January 26, 2009 -- <a href="http://www.bestjavainterviewquestions.com/uploading-file-name-of-image-to-database/" title="Uploading file name or image to DataBase">Uploading file name or image to DataBase</a> (0)</li><li>July 21, 2010 -- <a href="http://www.bestjavainterviewquestions.com/how-to-make-a-class-serializable/" title="How to Make a Class Serializable">How to Make a Class Serializable</a> (1)</li><li>July 30, 2010 -- <a href="http://www.bestjavainterviewquestions.com/stored-procedures-for-beginners/" title="Stored Procedures for Beginners">Stored Procedures for Beginners</a> (0)</li><li>February 15, 2009 -- <a href="http://www.bestjavainterviewquestions.com/services-provided-by-ejb-container/" title="Services Provided by EJB Container">Services Provided by EJB Container</a> (0)</li><li>October 27, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-is-finalizer-methods/" title="What is Finalizer Methods">What is Finalizer Methods</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/522/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Explain Stream Tokenizer</title>
		<link>http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/</link>
		<comments>http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 08:27:33 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[StreamTokenizer]]></category>
		<category><![CDATA[core java]]></category>
		<category><![CDATA[define StreamTokenizer]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[string tokenizer java]]></category>
		<category><![CDATA[strings in java]]></category>
		<category><![CDATA[tokenizer]]></category>
		<category><![CDATA[tokenizer in java]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=499</guid>
		<description><![CDATA[Stream Tokenizer : StreamTokenizer is a direct subclass of Object class. StreamTokenizer is included in java.io. Package. The StreamTokenizer class takes an input stream and parses it into &#8220;tokens&#8221; , allowing the tokens to be read one at a time. The parsing process is controlled by a table and a number of flags ( like [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Stream Tokenizer :</strong></p>
<p>StreamTokenizer is a direct subclass of Object class. <em>StreamTokenizer is included in</em> <strong>java.io. Package</strong>.<em> The StreamTokenizer class takes an input stream and parses it into &#8220;tokens&#8221; , allowing the tokens to be read one at a time. The parsing process is controlled by a table and a number of flags ( like TT_WORD, TT-EOF,TT-EOL etc., all representing some integer value) that can be set to various states. The StreamTokenizer can recongnize identifiers, numbers, quoted strings and various comment styles. Tokenizing is a feature of compilers, interpreters and parsers.</em></p>
<p>A stream can contain three types of tokens.</p>
<ul>
<li><em>Words ( that is, multiple character tokens )</em></li>
<li><em>Single-character tokens</em></li>
<li><em>Whitespace( including C/C++/Java-style comments )</em></li>
</ul>
<p>Some constants, defined in StreamTokenizer, used as flags to identity the tokens :</p>
<p><em>int TT-EOL : A constant indicating that the end of the line has been read.<br />
</em></p>
<p><em>Int TT-EOF : A constant indicating that the end of the stream has been read.<br />
</em></p>
<p><em>int TT-WORD : A constant indicating that a word token has been read.</em></p>
<p><em>Int ttype : After a call to the nextToken method, this field contains the type of the token just read</em></p>
<p><strong>Aim : </strong>To count the number of words in a file using StreamTokenizer and whitespace as delimiter File name is passes as command-line argument.</p>
<p><em><strong>Sample program of StreamTokenizer as follows</strong></em> :</p>
<p><em>import java.io.*<br />
public class StreamTokenizerDemo {<br />
static int words = 0;<br />
public static void wordCount(Reader r)throws IOException<br />
{<br />
StreamTokenizer st = new StreamTokenizer(r);<br />
st.wordChars(33,255);</em></p>
<p><em>// if token in not EOF<br />
while(st.nextToken()!=st.TT_EOF)<br />
{<br />
//if token is word<br />
if(st.ttype == st.TT_WORD)<br />
words++;<br />
}</em></p>
<p><em>}<br />
public static void main(String args[])throws IOException<br />
{<br />
// pass file name as command-line<br />
FileReader fr = new FileReader(args[0]);<br />
wordCount(fr);<br />
System.out.pritnln(&#8221; Total words in file :&#8221;+words);<br />
}<br />
}</em></p>
<p><em><strong>Method signature of wordChars();</strong></em></p>
<p><em>public void wordChars(int low, int high);</em></p>
<p>Specifies that all characters between thew range low and high are word constituents. A word token consists of a word constituent followed by zero or more word constituents or number constituents</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/when-the-port-number-is-changed/" title="When the port number is changed">When the port number is changed</a> (0)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-is-port-number/" title="What is Port Number">What is Port Number</a> (0)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-is-abstract-classexplan/" title="What is Abstract Class?Explan">What is Abstract Class?Explan</a> (0)</li><li>December 12, 2008 -- <a href="http://www.bestjavainterviewquestions.com/url-connection-class/" title="URL Connection Class">URL Connection Class</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Define Static Keyword</title>
		<link>http://www.bestjavainterviewquestions.com/define-static-keyword/</link>
		<comments>http://www.bestjavainterviewquestions.com/define-static-keyword/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 07:32:24 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Define static keyword]]></category>
		<category><![CDATA[corejava]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[static in java]]></category>
		<category><![CDATA[static keyword in java]]></category>
		<category><![CDATA[static member in java]]></category>
		<category><![CDATA[static members]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=495</guid>
		<description><![CDATA[static is a keyword and means &#8216; can be accessed without the help of an object &#8216;. static is used an access modifier with members ( variables and methods ) of class. A static member belongs to the whole class. That is, all the objects of the class share ( or access ) the same [...]]]></description>
			<content:encoded><![CDATA[<p><strong>static is a keyword </strong>and means <strong>&#8216; can be accessed without the help of an object &#8216;.</strong></p>
<p><strong>static </strong>is used an access modifier with members ( variables and methods ) of class. A static member belongs to the whole class. That is, all the objects of the class share ( or access ) the same static variable. Or to say, a static variable is common to all the objects of the class. static variables do not have &#8220;this&#8221; reference. <strong>&#8216; this &#8216; </strong>is a keyword used to refer to a particular current object. This is quite contrast with instance variables where each variable keeps a separate copy of data when called with an object. The static variables like instance variables are given default values ( like zero for int ), if not assiganed any values.</p>
<p><strong>Declaring static members : </strong></p>
<p><strong>static </strong>int count ;</p>
<p><strong>static </strong>int min( int a, int b)</p>
<p><em>{</em></p>
<p><em>//body</em></p>
<p><em>}</em></p>
<p><strong>Example :</strong></p>
<p><em>public class StaticDemo {<br />
static int salary = 5000;<br />
public static void display()<br />
{<br />
System.out.println(&#8220;Hello&#8221;);<br />
}<br />
public static void main(String args[])<br />
{<br />
System.out.println(salary);</em></p>
<p><em>//called directly without object<br />
StaticDemo sd= new StaticDemo();</em></p>
<p><em>//called with object<br />
System.out.println(sd.salary);</em></p>
<p><em>//called with class name<br />
System.out.println(StaticDemo.salary);</em></p>
<p><em>//all the below display calls prints Hello</em></p>
<p><em>display();<br />
sd.display();<br />
StaticDemo.display();<br />
}<br />
}</em></p>
<p><strong>Output :</strong></p>
<p><em>double d =10.5 ;<br />
int x=d;<br />
int y=(int)d ;<br />
System.out.println(y);</em></p>
<p>In the above, casting is done explicitly by us as we are assigning d of datatype double ( 8 bytes ) to x of datatype int ( 4 bytes ).</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>December 16, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-interfacedefine/" title="Explain Interface?Define ">Explain Interface?Define </a> (0)</li><li>July 30, 2010 -- <a href="http://www.bestjavainterviewquestions.com/stored-procedures-for-beginners/" title="Stored Procedures for Beginners">Stored Procedures for Beginners</a> (0)</li><li>April 7, 2009 -- <a href="http://www.bestjavainterviewquestions.com/overview-of-servlets/" title="OVERVIEW OF SERVLETS">OVERVIEW OF SERVLETS</a> (0)</li><li>April 5, 2009 -- <a href="http://www.bestjavainterviewquestions.com/how-to-get-a-leap-year/" title="How to get a Leap Year">How to get a Leap Year</a> (0)</li><li>March 29, 2009 -- <a href="http://www.bestjavainterviewquestions.com/j2ee-interview-questions/" title="J2EE Interview Questions">J2EE Interview Questions</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/define-static-keyword/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is Abstract Class?Explan</title>
		<link>http://www.bestjavainterviewquestions.com/what-is-abstract-classexplan/</link>
		<comments>http://www.bestjavainterviewquestions.com/what-is-abstract-classexplan/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 07:01:30 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Explain Abstract Class]]></category>
		<category><![CDATA[abstrack class in java]]></category>
		<category><![CDATA[abstract java]]></category>
		<category><![CDATA[abstract keyword in java]]></category>
		<category><![CDATA[core java]]></category>
		<category><![CDATA[define abstract class]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=492</guid>
		<description><![CDATA[Abstract Class  : In some situations we want to define a superclass that declares the structure of a given abstract without providing a complete implementation of every method. That means we only provide general code and it is developers responsibility to customize that class. To make sure this, we can make the abstract, that means [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Abstract Class  :</strong></p>
<p>In some situations we want to define a superclass that declares the structure of a given abstract without providing a complete implementation of every method. That means we only provide general code and it is developers responsibility to customize that class. To make sure this, we can make the abstract, that means the developer will have to override your method .</p>
<p>The abstract keyword is used to make a method abstract if we have an abstract in a class, we also have to make the class an abstract.</p>
<p><strong>Note :</strong></p>
<p><strong>&#8211;&gt; </strong>An abstract class is a class that contain one or more abstract methods</p>
<p><strong>&#8211;&gt; </strong>An abstract class can have instance variables, concrete methods in addition to abstract methods</p>
<p><strong>&#8211;&gt; </strong>We cannot create object to abstract class</p>
<p><strong>&#8211;&gt; </strong>We can create reference variables to abstract class</p>
<p><strong>&#8211;&gt; </strong>All the abstract methods of abstract class should be implemented in its subclass.</p>
<p><strong>&#8211;&gt; </strong>A class cannot be both <em>abstract</em> and <em>final</em>.</p>
<p><strong>&#8211;&gt; </strong>Abstract class reference cannot refer to individual methods of the subclasses</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li>March 24, 2009 -- <a href="http://www.bestjavainterviewquestions.com/define-hashset-class/" title="Define HashSet Class">Define HashSet Class</a> (0)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/when-the-port-number-is-changed/" title="When the port number is changed">When the port number is changed</a> (0)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-is-port-number/" title="What is Port Number">What is Port Number</a> (0)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/" title="Explain Stream Tokenizer">Explain Stream Tokenizer</a> (0)</li><li>December 12, 2008 -- <a href="http://www.bestjavainterviewquestions.com/url-connection-class/" title="URL Connection Class">URL Connection Class</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/what-is-abstract-classexplan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

