<?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>TechieDrill &#187; Java</title>
	<atom:link href="http://techiedrill.com/category/programming/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://techiedrill.com</link>
	<description>Your World Of Technical Tutorials</description>
	<lastBuildDate>Tue, 05 Jan 2010 16:50:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Reading image files from Java</title>
		<link>http://techiedrill.com/2010/01/reading-image-files-from-java/</link>
		<comments>http://techiedrill.com/2010/01/reading-image-files-from-java/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 16:45:46 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=540</guid>
		<description><![CDATA[Here is the code to read a image file from java. Image file can be read even if it is located inside a compressed JAR file or even inside a folder.  imageIO class from javax is the main element of this functionality.
Here is the code

import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ReadingImage
{
public void getImage()
{
try
{
BufferedImage image =  [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the code to read a image file from java. Image file can be read even if it is located inside a compressed JAR file or even inside a folder.  imageIO class from javax is the main element of this functionality.</p>
<p>Here is the code</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.awt.image.BufferedImage;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.io.IOException;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.imageio.ImageIO;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class ReadingImage</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public void getImage()</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">try</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">BufferedImage image = <span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ImageIO.read(getClass().getResource(&#8221;Sunset.jpg&#8221;));</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">// Do something with the image.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">} catch (IOException e)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">e.printStackTrace();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public static void main(String[] args)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{<span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ReadingImage ri = new ReadingImage();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ri.getImage();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<blockquote><p>import javax.imageio.ImageIO;</p>
<p>import java.awt.image.*;</p></blockquote>
<blockquote><p>import java.io.IOException;</p></blockquote>
<blockquote><p>import java.awt.image.BufferedImage;</p></blockquote>
<blockquote><p>public class ReadImageDemo</p></blockquote>
<blockquote><p>{</p></blockquote>
<blockquote><p>public void displayImage()</p></blockquote>
<blockquote><p>{</p></blockquote>
<blockquote><p>try</p></blockquote>
<blockquote><p>{</p></blockquote>
<blockquote><p>BufferedImage imageSrc = <span style="white-space: pre;"> </span></p></blockquote>
<blockquote><p>ImageIO.read(getClass().getResource(&#8221;Corsa.jpg&#8221;));</p></blockquote>
<blockquote><p>// Do whatever you wanna do with this image.</p></blockquote>
<blockquote><p>} catch (IOException exception)</p></blockquote>
<blockquote><p>{</p></blockquote>
<blockquote><p>exception.printStackTrace();</p></blockquote>
<blockquote><p>}</p></blockquote>
<blockquote><p>}</p></blockquote>
<blockquote><p>public static void main(String argum[])</p></blockquote>
<blockquote><p>{<span style="white-space: pre;"> </span></p></blockquote>
<blockquote><p>ReadImageDemo readImageDemo  = new ReadImageDemo();</p></blockquote>
<blockquote><p>readImageDemo. displayImage();</p></blockquote>
<blockquote><p>}</p></blockquote>
<blockquote><p>}</p></blockquote>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/reading-image-files-from-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Decompress/unzip java objects</title>
		<link>http://techiedrill.com/2010/01/decompressunzip-java-objects/</link>
		<comments>http://techiedrill.com/2010/01/decompressunzip-java-objects/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 17:43:16 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=538</guid>
		<description><![CDATA[The java.util.zip.ZipEntry extends the Zip file entry.  java.util.zip.ZipEntry implements java.util.zip.ZipConstants interface.
In this sample code we pass the zip file name as an argument/parameter in the command line argument .
To unzip, create object byte stream and give the size of an array perceiving the length of the text in the file

import java.io.*;
import java.util.zip.*;
public class UnZipObjectSample {
 public [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>java.util.zip.ZipEntry extends the Zip file entry. </strong> <strong>java.util.zip.ZipEntry </strong>implements <strong>java.util.zip.ZipConstants </strong>interface<strong>.</strong></p>
<p>In this sample code we pass the zip file name as an argument/parameter in the command line argument .</p>
<p>To unzip, create object byte stream and give the size of an array perceiving the length of the text in the file</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.io.*;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.zip.*;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class UnZipObjectSample {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>public static void main(String arguments[]) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>try {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>BufferedOutputStream bufferedOutputStream = null;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>new FileInputStream(arguments[0])));</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>ZipEntry zipEntry;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>while ((zipEntry = zipInputStream.getNextEntry()) != null) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>int counter;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>int initial = 0;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>byte text[] = new byte[900];</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(&#8221;sampleOUT.txt&#8221;),</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>900);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>while ((counter = zipInputStream.read(text, initial, 900)) != -1) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>bufferedOutputStream.write(text, initial, counter);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//flushing and closing bufferedOutputStream</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>bufferedOutputStream.flush();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>bufferedOutputStream.close();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>} catch (Exception exception) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//handle generic exceptions</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>exception.printStackTrace();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 70px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<blockquote><p>import java.io.*;</p></blockquote>
<blockquote><p>import java.util.zip.*;</p></blockquote>
<blockquote></blockquote>
<blockquote><p>public class UnZipObjectSample {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>public static void main(String arguments[]) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>try {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>BufferedOutputStream bufferedOutputStream = null;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>new FileInputStream(arguments[0])));</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>ZipEntry zipEntry;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>while ((zipEntry = zipInputStream.getNextEntry()) != null) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>int counter;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>int initial = 0;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>byte text[] = new byte[900];</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(&#8221;sampleOUT.txt&#8221;),</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>900);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>while ((counter = zipInputStream.read(text, initial, 900)) != -1) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>bufferedOutputStream.write(text, initial, counter);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>//flushing and closing bufferedOutputStream</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>bufferedOutputStream.flush();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>bufferedOutputStream.close();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>} catch (Exception exception) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>//handle generic exceptions</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>exception.printStackTrace();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p>}</p></blockquote>
<div></div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/decompressunzip-java-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a zip file using java ZipOutputStream</title>
		<link>http://techiedrill.com/2010/01/creating-a-zip-file-using-java-zipoutputstream/</link>
		<comments>http://techiedrill.com/2010/01/creating-a-zip-file-using-java-zipoutputstream/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 17:32:37 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=536</guid>
		<description><![CDATA[Following example explains how to read a file using file input stream and zip that file using zip output stream.  ZipOutputStream comes in package import java.util.zip.ZipOutputStream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class FilesZippingSampleCode {
 public static void main(String argum[]) {
 try {
 String sourceFile = &#8220;sampleFile.txt&#8221;;
 String targetZip = &#8220;zipME.zip&#8221;;
 ZipOutputStream zipOutputStream = new ZipOutputStream(new [...]]]></description>
			<content:encoded><![CDATA[<p>Following example explains how to read a file using file input stream and zip that file using zip output stream.  ZipOutputStream comes in package import java.util.zip.ZipOutputStream;</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.io.FileInputStream;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.io.FileOutputStream;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.io.IOException;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.zip.ZipEntry;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.zip.ZipOutputStream;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class FilesZippingSampleCode {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>public static void main(String argum[]) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>try {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>String sourceFile = &#8220;sampleFile.txt&#8221;;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>String targetZip = &#8220;zipME.zip&#8221;;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>targetZip));</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>FileInputStream fileInputStream = new FileInputStream(sourceFile);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>// This is to put an entry in the Zip output stream</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>zipOutputStream.putNextEntry(new ZipEntry(sourceFile));</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>int size = 0;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>byte[] bufferByte = new byte[1024];</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>// This allows to read a file from beginning till end of file and</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>// write it in a zip output stream</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>while ((size = fileInputStream.read(bufferByte, 0, bufferByte.length)) &gt; 0) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>zipOutputStream.write(bufferByte, 0, size);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>zipOutputStream.closeEntry();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//Close the fileInputStream</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>fileInputStream.close();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>// Close zipOutputStream</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>zipOutputStream.close();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>} catch (IOException iOException) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>iOException.printStackTrace();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<blockquote><p>import java.io.FileInputStream;</p></blockquote>
<blockquote><p>import java.io.FileOutputStream;</p></blockquote>
<blockquote><p>import java.io.IOException;</p></blockquote>
<blockquote><p>import java.util.zip.ZipEntry;</p></blockquote>
<blockquote><p>import java.util.zip.ZipOutputStream;</p></blockquote>
<blockquote></blockquote>
<blockquote><p>public class FilesZippingSampleCode {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>public static void main(String argum[]) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>try {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>String sourceFile = &#8220;sampleFile.txt&#8221;;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>String targetZip = &#8220;zipME.zip&#8221;;</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>targetZip));</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>FileInputStream fileInputStream = new FileInputStream(sourceFile);</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>// This is to put an entry in the Zip output stream</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>zipOutputStream.putNextEntry(new ZipEntry(sourceFile));</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>int size = 0;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>byte[] bufferByte = new byte[1024];</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>// This allows to read a file from beginning till end of file and</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>// write it in a zip output stream</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>while ((size = fileInputStream.read(bufferByte, 0, bufferByte.length)) &gt; 0) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>zipOutputStream.write(bufferByte, 0, size);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>zipOutputStream.closeEntry();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>//Close the fileInputStream</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>fileInputStream.close();</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>// Close zipOutputStream</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>zipOutputStream.close();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>} catch (IOException iOException) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>iOException.printStackTrace();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p>}</p></blockquote>
<div></div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/creating-a-zip-file-using-java-zipoutputstream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieve Media Access Control Address (MAC) using java</title>
		<link>http://techiedrill.com/2010/01/retrieve-media-access-control-address-mac-using-java/</link>
		<comments>http://techiedrill.com/2010/01/retrieve-media-access-control-address-mac-using-java/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 17:24:26 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=533</guid>
		<description><![CDATA[Try this code and get the MAC address of your machine..
Specify the ip address of the machine instead of localhost to get the MAC address of the specified ip address machine
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
public class MACAddressExample {
 public static void main(String arguments[]) {
 try {
 // To obtain internet address
 InetAddress inetaddress = InetAddress.getLocalHost();
 [...]]]></description>
			<content:encoded><![CDATA[<p>Try this code and get the MAC address of your machine..</p>
<p>Specify the ip address of the machine instead of localhost to get the MAC address of the specified ip address machine</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.net.InetAddress;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.net.NetworkInterface;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.net.SocketException;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.net.UnknownHostException;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class MACAddressExample {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>public static void main(String arguments[]) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>try {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>// To obtain internet address</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>InetAddress inetaddress = InetAddress.getLocalHost();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>// InetAddress inetaddress = InetAddress.getByName(&#8221;10.11.583.26&#8243;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>/*</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> * Retrieve the current host&#8217;s network interfacea and start reading</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> * the hardware device address</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> */</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>NetworkInterface networkInterface = NetworkInterface</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>.getByInetAddress(inetaddress);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>if (networkInterface != null) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>byte[] MACAddress = networkInterface.getHardwareAddress();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>if (MACAddress != null) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>/*</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> * obtain the array of Media access control address and</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> * convert it into hexadecimal value as 00-19-D1-17-78-9E</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> */</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>for (int loop = 0; loop &lt; MACAddress.length; loop++) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>System.out.format(&#8221;%02X%s&#8221;, MACAddress[loop],</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>(loop &lt; MACAddress.length &#8211; 1) ? &#8220;-&#8221; : &#8220;&#8221;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>} else {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>System.out.println(&#8221;Following address nor exists/found&#8221;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>} else {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>System.out.println(&#8221;Network interface for &#8220;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>+ &#8220;nor exists/found for &#8221; + inetaddress);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>} catch (UnknownHostException unknownHostException) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>unknownHostException.printStackTrace();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>} catch (SocketException socketException) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>socketException.printStackTrace();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<p>import java.net.InetAddress;</p>
<p>import java.net.NetworkInterface;</p>
<p>import java.net.SocketException;</p>
<p>import java.net.UnknownHostException;</p>
<p>public class MACAddressExample {</p>
<p><span style="white-space: pre;"> </span>public static void main(String arguments[]) {</p>
<p><span style="white-space: pre;"> </span>try {</p>
<p><span style="white-space: pre;"> </span>// To obtain internet address</p>
<p><span style="white-space: pre;"> </span>InetAddress inetaddress = InetAddress.getLocalHost();</p>
<p><span style="white-space: pre;"> </span>// InetAddress inetaddress = InetAddress.getByName(&#8221;10.11.583.26&#8243;);</p>
<p><span style="white-space: pre;"> </span>/*</p>
<p><span style="white-space: pre;"> </span> * Retrieve the current host&#8217;s network interfacea and start reading</p>
<p><span style="white-space: pre;"> </span> * the hardware device address</p>
<p><span style="white-space: pre;"> </span> */</p>
<p><span style="white-space: pre;"> </span>NetworkInterface networkInterface = NetworkInterface</p>
<p><span style="white-space: pre;"> </span>.getByInetAddress(inetaddress);</p>
<p><span style="white-space: pre;"> </span>if (networkInterface != null) {</p>
<p><span style="white-space: pre;"> </span>byte[] MACAddress = networkInterface.getHardwareAddress();</p>
<p><span style="white-space: pre;"> </span>if (MACAddress != null) {</p>
<p><span style="white-space: pre;"> </span>/*</p>
<p><span style="white-space: pre;"> </span> * obtain the array of Media access control address and</p>
<p><span style="white-space: pre;"> </span> * convert it into hexadecimal value as 00-19-D1-17-78-9E</p>
<p><span style="white-space: pre;"> </span> */</p>
<p><span style="white-space: pre;"> </span>for (int loop = 0; loop &lt; MACAddress.length; loop++) {</p>
<p><span style="white-space: pre;"> </span>System.out.format(&#8221;%02X%s&#8221;, MACAddress[loop],</p>
<p><span style="white-space: pre;"> </span>(loop &lt; MACAddress.length &#8211; 1) ? &#8220;-&#8221; : &#8220;&#8221;);</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span>} else {</p>
<p><span style="white-space: pre;"> </span>System.out.println(&#8221;Following address nor exists/found&#8221;);</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span>} else {</p>
<p><span style="white-space: pre;"> </span>System.out.println(&#8221;Network interface for &#8221;</p>
<p><span style="white-space: pre;"> </span>+ &#8220;nor exists/found for &#8221; + inetaddress);</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span>} catch (UnknownHostException unknownHostException) {</p>
<p><span style="white-space: pre;"> </span>unknownHostException.printStackTrace();</p>
<p><span style="white-space: pre;"> </span>} catch (SocketException socketException) {</p>
<p><span style="white-space: pre;"> </span>socketException.printStackTrace();</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span>}</p>
<p>}</p>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/retrieve-media-access-control-address-mac-using-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String to Date conversion using SimpleDateFormat</title>
		<link>http://techiedrill.com/2010/01/string-to-date-conversion-using-simpledateformat/</link>
		<comments>http://techiedrill.com/2010/01/string-to-date-conversion-using-simpledateformat/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 17:14:24 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=530</guid>
		<description><![CDATA[Below code explains how to convert a string representing a date into an date object java.util.Date object.
To accomplish this we use SimpleDateFormat which can be imported as  java.text.SimpleDateFormat which by default extends java.text.DateFormat abstract class..


import java.util.Date;
import java.text.ParseException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class StringToDateConversion {
 public static void main(String argu[]) {
 DateFormat dateFormat = new SimpleDateFormat(&#8221;MM/dd/yy&#8221;);
 try {
 Date [...]]]></description>
			<content:encoded><![CDATA[<p style="font-size: 1em; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">Below code explains how to convert a string representing a date into an date object <span>java.util.Date</span> object.</p>
<p style="font-size: 1em; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">To accomplish this we use SimpleDateFormat which can be imported as  <span>java.text.SimpleDateFormat</span> which by default extends <span>java.text.DateFormat</span> abstract class..</p>
<blockquote>
<p style="font-size: 1em; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.Date;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.text.ParseException;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.text.DateFormat;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.text.SimpleDateFormat;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class StringToDateConversion {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>public static void main(String argu[]) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>DateFormat dateFormat = new SimpleDateFormat(&#8221;MM/dd/yy&#8221;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>try {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Date todaysDate = dateFormat.parse(&#8221;01/01/2010&#8243;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>System.out.println(&#8221;Date Today : &#8221; + dateFormat.format(todaysDate));</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>} catch (ParseException parseException) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>parseException.printStackTrace();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 30px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<blockquote></blockquote>
<blockquote><p>import java.util.Date;</p></blockquote>
<blockquote><p>import java.text.ParseException;</p></blockquote>
<blockquote><p>import java.text.DateFormat;</p></blockquote>
<blockquote><p>import java.text.SimpleDateFormat;</p></blockquote>
<blockquote></blockquote>
<blockquote><p>public class StringToDateConversion {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>public static void main(String argu[]) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>DateFormat dateFormat = new SimpleDateFormat(&#8221;MM/dd/yy&#8221;);</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>try {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>Date todaysDate = dateFormat.parse(&#8221;01/01/2010&#8243;);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>System.out.println(&#8221;Date Today : &#8221; + dateFormat.format(todaysDate));</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>} catch (ParseException parseException) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>parseException.printStackTrace();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p>}</p></blockquote>
<div></div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/string-to-date-conversion-using-simpledateformat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an empty collection object</title>
		<link>http://techiedrill.com/2010/01/creating-an-empty-collection-object/</link>
		<comments>http://techiedrill.com/2010/01/creating-an-empty-collection-object/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 17:06:06 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=526</guid>
		<description><![CDATA[Java methods at times need to acquire an empty object, this can be accomplished by using java.util.Collections class. Collections class namely have 3 static instance for the creation of static empty list, map and tree. This will also be helpful in creating type-safe collection objects
See the below code for better understanding

import java.util.Collections;
import java.util.*;
public class EmptyCollections [...]]]></description>
			<content:encoded><![CDATA[<p>Java methods at times need to acquire an empty object, this can be accomplished by using java.util.Collections class. Collections class namely have 3 static instance for the creation of static empty list, map and tree. This will also be helpful in creating type-safe collection objects</p>
<p>See the below code for better understanding</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.Collections;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.*;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class EmptyCollections {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>public static void main(String args[]) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//Empty collection object</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>List list = Collections.EMPTY_LIST;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Set set = Collections.EMPTY_SET;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Map map = Collections.EMPTY_MAP;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>// Below are for the type-safe, use this for type-safe</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>List s = Collections.emptyList();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Set l = Collections.emptySet();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>Map d = Collections.emptyMap();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 50px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<blockquote><p>import java.util.Collections;</p></blockquote>
<blockquote><p>import java.util.*;</p></blockquote>
<blockquote><p>public class EmptyCollections {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>public static void main(String args[]) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>//Empty collection object</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>List emptyList = Collections.EMPTY_LIST;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>Set emptySet = Collections.EMPTY_SET;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>Map emptyMap = Collections.EMPTY_MAP;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>// Below are for the type-safe, use this for type-safe</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>List list1 = Collections.emptyList();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>Set set1 = Collections.emptySet();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>Map map1 = Collections.emptyMap();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p>}</p></blockquote>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/creating-an-empty-collection-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ternary Operator in java</title>
		<link>http://techiedrill.com/2010/01/ternary-operator-in-java/</link>
		<comments>http://techiedrill.com/2010/01/ternary-operator-in-java/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 16:54:30 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=523</guid>
		<description><![CDATA[Java ternary operator serves number of purpose. Ternary operator are basically a conditional operators. Ternary operator is compact version of if-then-else statement. Performance wise Ternary operator are good conditional operators.
Ternary operator functions as if condition evaluation returns true, first value is returned else second value after the colon is returned
Try this code below&#8230;.

 public class TernaryOperatorExample [...]]]></description>
			<content:encoded><![CDATA[<p>Java ternary operator serves number of purpose. Ternary operator are basically a conditional operators. Ternary operator is compact version of if-then-else statement. Performance wise Ternary operator are good conditional operators.</p>
<p>Ternary operator functions as if condition evaluation returns true, first value is returned else second value after the colon is returned</p>
<p>Try this code below&#8230;.</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>public class TernaryOperatorExample {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> public static void main(String arge[]) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> int firstValue = 500;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> int secondValue = 700;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> int minimum = firstValue &lt; secondValue ? firstValue : secondValue;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> int minimumValue;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> if (firstValue &lt; secondValue) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> minimumValue = firstValue;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> } else {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> minimumValue = secondValue;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> }</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> int maximumValue = firstValue &gt; secondValue ? firstValue : secondValue;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> int absoluteValue = firstValue &lt; 0 ? -firstValue : firstValue;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> System.out.println(&#8221;Miimum     = &#8221; + minimum);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> System.out.println(&#8221;Minimum Value = &#8221; + minimumValue);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> System.out.println(&#8221;Maximum Value      = &#8221; + maximumValue);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> System.out.println(&#8221;Absolute Value     = &#8221; + absoluteValue);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> }</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 69px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<blockquote></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>public class TernaryOperatorExample {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> public static void main(String arge[]) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> int firstValue = 500;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> int secondValue = 700;</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> int minimum = firstValue &lt; secondValue ? firstValue : secondValue;</p></blockquote>
<blockquote></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> int minimumValue;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> if (firstValue &lt; secondValue) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> minimumValue = firstValue;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> } else {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> minimumValue = secondValue;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> }</p></blockquote>
<blockquote></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> int maximumValue = firstValue &gt; secondValue ? firstValue : secondValue;</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> int absoluteValue = firstValue &lt; 0 ? -firstValue : firstValue;</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> System.out.println(&#8221;Miimum     = &#8221; + minimum);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> System.out.println(&#8221;Minimum Value = &#8221; + minimumValue);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> System.out.println(&#8221;Maximum Value      = &#8221; + maximumValue);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> System.out.println(&#8221;Absolute Value     = &#8221; + absoluteValue);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> }</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<div></div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/ternary-operator-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tricky Static</title>
		<link>http://techiedrill.com/2010/01/tricky-static/</link>
		<comments>http://techiedrill.com/2010/01/tricky-static/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 16:45:30 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=521</guid>
		<description><![CDATA[Static is bit tricky in java programming. Using static imports we need not create an instance of the class to call the objects of the class.
Have a look at the below code.. try it out, quite interesting
Here we used static field min() and max() methods of Math class without creating an instance for the class, [...]]]></description>
			<content:encoded><![CDATA[<p>Static is bit tricky in java programming. Using static imports we need not create an instance of the class to call the objects of the class.</p>
<p>Have a look at the below code.. try it out, quite interesting</p>
<p>Here we used static field min() and max() methods of Math class without creating an instance for the class, since the class &#8220;<span style="white-space: pre;"> </span>import static java.lang.Math.min; import static java.lang.Math.max; is imported</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>import static java.lang.Math.min;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>import static java.lang.Math.max;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>import static java.lang.System.out;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>import java.util.Date;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>public class ImportStaticExample {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> public static void main(String[] args) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> int minimumValue = min(10,20);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> int maximumValue = max(10,20);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> out.println(&#8221;minimumValue: &#8220;+minimumValue);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> out.println(&#8221;maximumValue: &#8220;+maximumValue);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> out.println(&#8221;Date today: &#8221; + new Date());</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> }</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 63px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<blockquote></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>import static java.lang.Math.min;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>import static java.lang.Math.max;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>import static java.lang.System.out;</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>import java.util.Date;</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>public class ImportStaticExample {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> public static void main(String[] args) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span></p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> int minimumValue = min(10,20);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> int maximumValue = max(10,20);</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> out.println(&#8221;minimumValue: &#8220;+minimumValue);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> out.println(&#8221;maximumValue: &#8220;+maximumValue);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> out.println(&#8221;Date today: &#8221; + new Date());</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span> }</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<div></div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/tricky-static/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Foreach Example</title>
		<link>http://techiedrill.com/2010/01/java-foreach-example/</link>
		<comments>http://techiedrill.com/2010/01/java-foreach-example/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 09:43:35 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=519</guid>
		<description><![CDATA[Java For:each example
Java for each loop will execute faster through the collection iterator. It executes faster for objects within the iterator than the generic for loop
Sample code Illustrated below

import java.util.*;
public class ForEachExample {
 public static void main(String args[]) {
 List colors = new ArrayList();
 colors.add(&#8221;RED&#8221;);
 colors.add(&#8221;BLUE&#8221;);
 colors.add(&#8221;GREEN&#8221;);
 colors.add(&#8221;YELLO&#8221;);
 colors.add(&#8221;VOILET&#8221;);
 for (Iterator iterator = colors.iterator(); iterator.hasNext();) [...]]]></description>
			<content:encoded><![CDATA[<p>Java For:each example</p>
<p>Java for each loop will execute faster through the collection iterator. It executes faster for objects within the iterator than the generic for loop</p>
<p>Sample code Illustrated below</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import java.util.*;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class ForEachExample {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>public static void main(String args[]) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>List colors = new ArrayList();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>colors.add(&#8221;RED&#8221;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>colors.add(&#8221;BLUE&#8221;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>colors.add(&#8221;GREEN&#8221;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>colors.add(&#8221;YELLO&#8221;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>colors.add(&#8221;VOILET&#8221;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>for (Iterator iterator = colors.iterator(); iterator.hasNext();) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>String name = (String) iterator.next();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//returns the first character of the string in the collection object</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>System.out.println(&#8221;Character&#8221;+name.charAt(0));</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//returns the string in the iterator object</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>System.out.println(&#8221;Color:&#8221;+name);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<blockquote><p>import java.util.*;</p></blockquote>
<blockquote></blockquote>
<blockquote><p>public class ForEachExample {</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>public static void main(String args[]) {</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>List colors = new ArrayList();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>colors.add(&#8221;RED&#8221;);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>colors.add(&#8221;BLUE&#8221;);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>colors.add(&#8221;GREEN&#8221;);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>colors.add(&#8221;YELLO&#8221;);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>colors.add(&#8221;VOILET&#8221;);</p></blockquote>
<blockquote></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>for (Iterator iterator = colors.iterator(); iterator.hasNext();) {</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>String name = (String) iterator.next();</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>//returns the first character of the string in the collection object</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>System.out.println(&#8221;Character&#8221;+name.charAt(0));</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>//returns the string in the iterator object</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>System.out.println(&#8221;Color:&#8221;+name);</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>}</p></blockquote>
<blockquote><p>}</p></blockquote>
<div></div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/java-foreach-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ordinal Enumeration example</title>
		<link>http://techiedrill.com/2010/01/ordinal-enumeration-example/</link>
		<comments>http://techiedrill.com/2010/01/ordinal-enumeration-example/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 09:29:23 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=516</guid>
		<description><![CDATA[Ordinal Enumeration generally returns the position value of the constants. Enumeration ordinal numbering starts from the initial constant value of the enumeration as &#8216;0&#8242; and to the n-1 constants values
Here is the best illustrated example

enum Days {
SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY
}
public class EnumOrdinalExample {
public static void main(String[] args) {
//Give you the ordinal value of the enumeration constant.
 //Ordinal numbering [...]]]></description>
			<content:encoded><![CDATA[<p>Ordinal Enumeration generally returns the position value of the constants. Enumeration ordinal numbering starts from the initial constant value of the enumeration as &#8216;0&#8242; and to the n-1 constants values</p>
<p>Here is the best illustrated example</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">enum Days {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class EnumOrdinalExample {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public static void main(String[] args) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">//Give you the ordinal value of the enumeration constant.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//Ordinal numbering starts from 0 to the n-1 values.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">System.out.println(&#8221;SUNDAY : &#8221; + Days.SUNDAY.ordinal());</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">System.out.println(&#8221;TUESDAY: &#8221; + Days.TUESDAY.ordinal());</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">System.out.println(&#8221;THURSDAY : &#8221; + Days.THURSDAY.ordinal());</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 31px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<blockquote></blockquote>
<blockquote><p>enum Days {</p></blockquote>
<blockquote><p>SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY</p></blockquote>
<blockquote><p>}</p></blockquote>
<blockquote></blockquote>
<blockquote><p>public class EnumOrdinalExample {</p></blockquote>
<blockquote><p>public static void main(String[] args) {</p></blockquote>
<blockquote><p>//Give you the ordinal value of the enumeration constant.</p></blockquote>
<blockquote><p><span style="white-space: pre;"> </span>//Ordinal numbering starts from 0 to the n-1 values.</p></blockquote>
<blockquote><p>System.out.println(&#8221;SUNDAY : &#8221; + Days.SUNDAY.ordinal());</p></blockquote>
<blockquote><p>System.out.println(&#8221;TUESDAY: &#8221; + Days.TUESDAY.ordinal());</p></blockquote>
<blockquote><p>System.out.println(&#8221;THURSDAY : &#8221; + Days.THURSDAY.ordinal());</p></blockquote>
<blockquote><p>}</p></blockquote>
<blockquote><p>}</p></blockquote>
<div><strong><span style="text-decoration: underline;">OUPTUT</span></strong></div>
<div></div>
<div><strong><span></p>
<div><span style="font-weight: normal;"><em>SUNDAY : 0</em></span></div>
<div><span style="font-weight: normal;"><em>TUESDAY: 2</em></span></div>
<div><span style="font-weight: normal;"><em>THURSDAY : 4</em></span></div>
<p></span></strong></div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2010/01/ordinal-enumeration-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
